Skip to content

Commit 13eb753

Browse files
authored
Create 2019-roundA-Training.cpp
1 parent d22cf33 commit 13eb753

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

Diff for: kick-start/2019-roundA-Training.cpp

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include<bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
#define INF 0x3f3f3f3f
6+
7+
8+
typedef long long LL;
9+
10+
const int MAXN = 1e5 +10;
11+
12+
LL s[MAXN];
13+
LL sum[MAXN];
14+
15+
int main(){
16+
17+
ios :: sync_with_stdio(0);
18+
cin.tie(0);
19+
std::cout.precision(8);
20+
std::cout.setf( std::ios::fixed, std:: ios::floatfield );
21+
22+
int T;
23+
cin >> T;
24+
25+
for(int t =1 ; t <= T; ++t){
26+
27+
int n,p;
28+
cin >> n>> p;
29+
for(int i=1 ; i<=n ; ++i)cin >> s[i];
30+
31+
sort(s+1,s+n+1);
32+
33+
sum[0] =0;
34+
for(int i=1 ; i<=n ; ++i)sum[i] = sum[i-1] + s[i];
35+
LL ans = INT64_MAX >> 1;
36+
for(int i=p ; i <=n ;++i){
37+
LL sc = sum[i] - sum[i-p];
38+
LL need = s[i] * p - sc;
39+
40+
if(ans > need) ans = need;
41+
}
42+
cout << "Case #"<<t<<": "<<ans << "\n";
43+
}
44+
45+
46+
return 0;
47+
}

0 commit comments

Comments
 (0)