#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
#include <math.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ifstream in("input.txt");
ofstream out("output.txt");
typedef long long ll;
int n,k;
ll v[100001];
ll tot=0;
ll diff[100001];
bool cmp(int a, int b){
return a>b;
}
int main(){
cin>>n>>k;
v[0]=-1e9-1;
cin>>v[0];
for(int i=1;i<=n-1;i++){
cin>>v[i];
tot+=v[i]-v[i-1];
diff[i]=v[i]-v[i-1];
}
sort(diff+1,diff+n,cmp);
for(int i=1;i<=k-1;i++){
tot-=diff[i]-1;
}
//if(k>=2&&v[1]-v[0]<diff[k-1])tot+=1;
tot+=1;
cout<<tot;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
248 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
248 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
4 ms |
504 KB |
Output is correct |
11 |
Correct |
5 ms |
504 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
4 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
508 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
248 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
4 ms |
504 KB |
Output is correct |
11 |
Correct |
5 ms |
504 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
4 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
508 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
91 ms |
2936 KB |
Output is correct |
17 |
Correct |
88 ms |
2936 KB |
Output is correct |
18 |
Correct |
86 ms |
2936 KB |
Output is correct |
19 |
Correct |
88 ms |
2800 KB |
Output is correct |
20 |
Correct |
89 ms |
2936 KB |
Output is correct |
21 |
Correct |
89 ms |
3064 KB |
Output is correct |
22 |
Correct |
91 ms |
2852 KB |
Output is correct |
23 |
Correct |
87 ms |
2896 KB |
Output is correct |
24 |
Correct |
86 ms |
2808 KB |
Output is correct |