#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
using namespace std;
const int N = 1e5 + 4;
const int inf = 1e18;
struct edge {
int a,b,c,d;
};
vector<int>v;
vector<pair<int,int> >v1;
vector<int>v2;
signed main(){
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
boost;
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++){
int x;
cin>>x;
v.push_back(x);
}
for(int i=0;i<n-1;i++){
v1.push_back({v[i+1]-v[i]-1,i});
}
sort(v1.rbegin(),v1.rend());
for(int i=0;i<k-1;i++){
v2.push_back(v1[i].second);
}
sort(v2.begin(),v2.end());
int j=0;
int st=0;
int ans=0;
if(v2.size()==0){
cout<<v[n-1]-v[0]+1;
return 0;
}
for(int i=0;i<v.size();i++){
if(j<v2.size()&&i==v2[j]){
j++;
ans+=v[i]+1-v[st];
st=i+1;
}
}
ans+=v[n-1]-v[st]+1;
cout<<ans;
}
Compilation message
stove.cpp: In function 'int main()':
stove.cpp:40:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(int i=0;i<v.size();i++){
| ~^~~~~~~~~
stove.cpp:41:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | if(j<v2.size()&&i==v2[j]){
| ~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
448 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
448 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
1 ms |
592 KB |
Output is correct |
12 |
Correct |
2 ms |
592 KB |
Output is correct |
13 |
Correct |
2 ms |
592 KB |
Output is correct |
14 |
Correct |
2 ms |
644 KB |
Output is correct |
15 |
Correct |
1 ms |
592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
448 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
1 ms |
592 KB |
Output is correct |
12 |
Correct |
2 ms |
592 KB |
Output is correct |
13 |
Correct |
2 ms |
592 KB |
Output is correct |
14 |
Correct |
2 ms |
644 KB |
Output is correct |
15 |
Correct |
1 ms |
592 KB |
Output is correct |
16 |
Correct |
19 ms |
5200 KB |
Output is correct |
17 |
Correct |
19 ms |
5220 KB |
Output is correct |
18 |
Correct |
19 ms |
5200 KB |
Output is correct |
19 |
Correct |
19 ms |
5212 KB |
Output is correct |
20 |
Correct |
22 ms |
5232 KB |
Output is correct |
21 |
Correct |
30 ms |
5956 KB |
Output is correct |
22 |
Correct |
25 ms |
6000 KB |
Output is correct |
23 |
Correct |
26 ms |
5964 KB |
Output is correct |
24 |
Correct |
26 ms |
6068 KB |
Output is correct |