#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define fir first
#define sec second
using namespace std;
int main() {
int n,k;
cin>>n>>k;
int t[n+1];
for(int i=1;i<=n;i++)
cin>>t[i];
set <pii> s;
int T[n+1]={};
for(int i=2;i<=n;i++)
s.insert({t[i]-t[i-1]-1,i});
int cnt=0;
for(auto it=s.begin();it!=s.end() and cnt<n-k;it++){
pii cur=*it;
cnt++;
T[cur.sec]=1;
}
T[1]=1;
for(int i=2;i<=n;i++){
if(T[i]==1) T[i]=T[i-1]+t[i]-t[i-1];
if(T[i]==0) T[i]=T[i-1]+1;
}
cout<<T[n];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
300 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
300 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
444 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
448 KB |
Output is correct |
13 |
Correct |
2 ms |
444 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
300 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
444 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
448 KB |
Output is correct |
13 |
Correct |
2 ms |
444 KB |
Output is correct |
14 |
Correct |
2 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
84 ms |
6716 KB |
Output is correct |
17 |
Correct |
79 ms |
6660 KB |
Output is correct |
18 |
Correct |
70 ms |
6712 KB |
Output is correct |
19 |
Correct |
70 ms |
6672 KB |
Output is correct |
20 |
Correct |
78 ms |
6792 KB |
Output is correct |
21 |
Correct |
79 ms |
6812 KB |
Output is correct |
22 |
Correct |
68 ms |
6612 KB |
Output is correct |
23 |
Correct |
71 ms |
6732 KB |
Output is correct |
24 |
Correct |
74 ms |
6672 KB |
Output is correct |