#include <algorithm>
#include <fstream>
#include <vector>
#include <queue>
#include <stack>
#include <iostream>
#include <cmath>
#include <queue>
#include <set>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <unordered_set>
#define F first
#define S second
#define PB push_back
using namespace std;
const long long MOD=1e9+7, INF=1e18;
const int INFI=1e9;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<pair<int, ii>> viii;
typedef vector<vii> vvii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
bool cmp(const ii& x, const ii& y) { return x.F>y.F; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k; cin>>n>>k;
ll ans=0;
vi ar(n+1, 0);
vii dif(n-1, {0, 0});
bool mark[n+1];
memset(mark, false, n+1);
for(int i=1;i<=n;i++) cin>>ar[i];
for(int i=2;i<=n;i++) dif[i-2]={ar[i]-ar[i-1], i};
sort(dif.begin(), dif.end(), cmp);
for(int i=0;i<k-1;i++) mark[dif[i].S]=true;
int inicio=ar[1];
for(int i=1;i<=n;i++){
if(mark[i]){
ans+=ar[i-1]+1-inicio;
inicio=ar[i];
}
}
ans+=ar[n]+1-inicio;
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
756 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
756 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
756 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
19 ms |
2612 KB |
Output is correct |
17 |
Correct |
18 ms |
2648 KB |
Output is correct |
18 |
Correct |
17 ms |
2704 KB |
Output is correct |
19 |
Correct |
19 ms |
2696 KB |
Output is correct |
20 |
Correct |
17 ms |
2648 KB |
Output is correct |
21 |
Correct |
17 ms |
2656 KB |
Output is correct |
22 |
Correct |
17 ms |
2652 KB |
Output is correct |
23 |
Correct |
17 ms |
2704 KB |
Output is correct |
24 |
Correct |
17 ms |
2660 KB |
Output is correct |