A. chorestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output
Luba have to do n chores today. i-th chore takes aI units of time to complete. It is guaranteed this for every the conditionai ≥ ai -1 is met, The sequence is sorted.
Also Luba can work really hard on some chores. She can choose not more than k any chores and does each of the them in x units of time instead of a i ().
Luba was very responsible, so she had to do all n chores, and now she wants to know the minimum time she needs To do everything. Luba cannot do chores simultaneously.
Input
The first line contains three integers n, k, x (1≤ k ≤ n ≤ 100, 1≤ x ≤99)-the number of chores Luba have to do, the number of chores she can does in x units of time, and T He number x itself.
The second line contains n integer numbers ai (2≤ a i ≤100)-the time Luba have to spend to do i-th chore.
It is guaranteed this, and for each ai ≥ ai -1.
Output
Print One Number-minimum time Luba needs to does all n chores.
Examplesinput
4 2 2
3 6 7 10
Output
13
Input
5 2 1
100 100 100) 100 100
Output
60W
Note
The first example the best option would is to does the third and the fourth chore, spending x = 2 time on EA Ch instead of a3 and a4, respectively. Then the answer is 3 + 6 + 2 + 2 =.
In the second example Luba can choose any and chores to spend x time on them instead of a i. The answer is 100 3 + 2 1 = 302.
"Analysis": silly greedy. Control before n-k the number of groups to seek the standard and, the other to K sum.
"Code":
#include <bits/stdc++.h>using namespacestd;intMain () {intn,k,x; inta[ the]; while(~SCANF ("%d%d%d",&n,&k,&x)) { for(intI=0; i<n;i++) {scanf ("%d",&A[i]); } intsum=0; for(intI=0; i<n-k;i++) {sum+=A[i]; } for(inti=n-k+1; i<=n;i++) {sum+=x; } printf ("%d\n", sum); } return 0;}
View Code
#pragmaGCC optimize (3)#include<bits/stdc++.h>using namespaceStd;typedefLong LongLl;inlinevoidReadInt (int&x) {x=0;intf=1;CharCh=GetChar (); while(!isdigit (CH)) {if(ch=='-') f=-1; ch=GetChar ();} while(IsDigit (CH)) x=x*Ten+ch-'0', ch=GetChar (); X*=F;} InlinevoidReadlong (LL &x) {x=0;intf=1;CharCh=GetChar (); while(!isdigit (CH)) {if(ch=='-') f=-1; ch=GetChar ();} while(IsDigit (CH)) x=x*Ten+ch-'0', ch=GetChar (); X*=F;}/*================header template==============*/intn,a,ans=0, k,x;intMain () {readInt (n); ReadInt (k); ReadInt (x); for(intI=1; i<=n;i++) {readInt (a); if(i<=n-k) Ans+=A; Elseans+=x; } printf ("%d\n", ans); return 0;}
Friend's
Educational codeforces Round a[water problem/array sort]