forked from DionysiosB/CodeForces
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1684D-Traps.cpp
More file actions
32 lines (25 loc) · 742 Bytes
/
1684D-Traps.cpp
File metadata and controls
32 lines (25 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <cstdio>
#include <vector>
#include <algorithm>
int main(){
long t; scanf("%ld", &t);
while(t--){
long n, k; scanf("%ld %ld", &n, &k);
std::vector<long> a(n);
std::vector<std::pair<long, long> > v(n);
for(long p = 0; p < n; p++){
scanf("%ld", &a[p]);
v[p].first = a[p] - (n - p);
v[p].second = p;
}
sort(v.rbegin(), v.rend());
std::vector<bool> jump(n, false);
for(long p = 0; p < k; p++){jump[v[p].second] = true;}
long long damage(0);
for(long p = 0, cnt = 0; p < n; p++){
if(jump[p]){++cnt;}
else{damage += (a[p] + cnt);}
}
printf("%lld\n", damage);
}
}