"Codeforces Round 339 (Div 2) D" "Brute force greedy dichotomy" Skills highest skill number multiplied by cm+ minimum skill multiply CF weight value max

Source: Internet
Author: User
D. Skills time limit per test 2 seconds memory limit per test megabytes input standard input output standard output

Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism is introduced. Now, each player character have exactly n skills. Each skill are represented by a non-negative an integer ai-the current skill level. All skills has the same maximum level A.

Along with the skills, global ranking of all players is added. Players is ranked according to the so-called force. The force of a player was the sum of the following values:the number of skills that a character have perfected (i.e., such That ai = A), multiplied by coefficient cf. the minimum skill level among all skills (min ai), multiplied by coefficient c M.

Now Lesha have m Hacknetian currency units, which he is willing to spend. Each currency unit can increase the current level of any skill by 1 (if it's not equal to A yet). Help him spend the achieve, the maximum possible value of the force. Input

The first line of the input contains five space-separated integers n, A, CF, CM and M (1≤n≤100 000, 1≤a≤109, 0≤c F, cm≤1000,0≤m≤1015).

The second line contains exactly n integers ai (0≤ai≤a), separated by spaces,-the current levels of skills. Output

On the first line print the maximum value of the-the-character can achieve using no more than M currency units.

On the second line print n integers a ' I (Ai≤a ' i≤a), skill levels which one must achieve in order to reach the Specifie D value of the force, and using no more than M currency units. Numbers should is separated by spaces. Examples input

3 5 1 5
1 3 1
Output
2 5 2 
Input
3 5 1 339
1 3 1
Output
5 5 5 
Note

In the first test the optimal strategy are to increase the second skill to its maximum, and increase the both others by 1.

The second Test one should increase all skills to maximum.


#include <stdio.h> #include <iostream> #include <string.h> #include <string> #include < ctype.h> #include <math.h> #include <set> #include <map> #include <vector> #include <queue
> #include <bitset> #include <algorithm> #include <time.h> using namespace std; void Fre () {freopen ("c://test//input.in", "R", stdin); Freopen ("C://test//output.out", "w", stdout);} #define MS (x, y) Me  Mset (x,y,sizeof (x)) #define MC (x, y) memcpy (x,y,sizeof (×)) #define MP (y) make_pair (x, y) #define LS o<<1 #define RS
o<<1|1 typedef long Long LL;
typedef unsigned long long UL;
typedef unsigned int UI; Template <class T1, class t2>inline void Gmax (T1 &a, T2 b) {if (b > a) a = b;} template <class T1, class t2>inline void Gmin (T1 &a, T2 b) {if (b < a) A = b;} const int N = 1e5 + ten, M = 0, Z = 1e9 + 7, Ms63 = 0x3f3f3
f3f; int n;
LL m; int A;
LL CF, CM;
LL Sum[n]; struct Skill {int V, o;}
A[n]; BOOL Cmp1 (Skill A, Skill b) {return A.V < B.V;} bool Cmp2 (Skill A, Skill b) {return A.O < B.O;} int solve (int R, LL now) {if (
	R = = 0) return A;
	int L = 1;
	int r = r;
		while (L < r) {int mid = (L + R + 1) >> 1;
		LL need = (LL) a[mid].v * mid-sum[mid];//also takes so much to reach the level of the mid-personal if (Need > Now) r = mid-1;
	else L = mid;
	} ll need = (ll) a[l].v*l-sum[l];
	LL more = (now-need)/L;
return min (LL) A, A[L].V + more); } int main () {while (~scanf ("%d%d%lld%lld%lld", &n, &a, &AMP;CF, &cm, &m)) {//First step: sort so that the skill level is strictly ascending because the output
		Format required, we also have to correspond to each skill number for (int i = 1; I <= n; ++i) {scanf ("%d", &a[i].v); a[i].o = i;} Sort (A + 1, a + n + 1, CMP1);

		A[n + 1].v = A;

		Second part: The prefix of the sum of the skill level is maintained and is used for subsequent rapid calculation of the ascending level for (int i = 1; I <= n; ++i) sum[i] = sum[i-1] + a[i].v;
		In the third step, we enumerate how many people's skills fill LL ans =-1;
		LL cost = 0;
		int V, p;
			enumeration [I+1,n] skills have been raised to the top level, [1,i] We maintain a minimum skill level as large as possible for (int i = n; i >= 0; i.) {cost + = A-a[i + 1].v; if (Cost > m)Break
			int MINV = Solve (i, m-cost);
			LL tmp = minv*cm + (n-i) *cf;
				if (tmp > ans) {ans = tmp;
				p = i;
			v = MINV;
		}} printf ("%lld\n", ans);
		for (int i = n; i > P; i.) A[I].V = A;
		for (int i = 1; I <= p; ++i) Gmax (A[I].V, v);
		Sort (A + 1, a + n + 1, CMP2); for (int i = 1; I <= n; ++i) printf ("%d", A[I].V);
	Puts ("");
} return 0;
}/* "trick&&" 1, the game must be focused on, be sure to pay attention to the details of the program and the code of the hierarchy.
This water problem I unexpectedly late 16sAC >_< stupid fried.
2, do the problem before you must pay attention to the format of the output, or it may be finished in order to output adjustment program.
3, some very easy to explode the problem of int, simply use ll bar >_< "test Instructions" everyone has n (1e5) skills, skill levels are in [0,1E9] range each skill has a current level, all skills of the highest level of a person's power is recorded as the following two items and
1, the number of top skills *CF 2, the lowest level of skill *cm we want to spend as little money as possible to make the power as high as possible "type" of violent dichotomy "analysis" according to the ability calculation, obviously, we care about the number of top-level skills and the number of low-level skills.

We enumerate the number of top-level skills and divide the number of base skills we can raise. Need to record--1, to reach I top skills need to spend 2 of the money, making low-level skills X "Time Complexity && Optimization" 3 5 10 1 0 1 3 1 * *


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.