This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int mxN = 2e5+1, M = 1e9+7;
int main(){
#ifdef _DEBUG
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);
int n, k;
cin >> n >> k, --k;
vector<int> a(n), flag;
int ans = n;
for(int i = 0; i<n; ++i){
cin >> a[i];
}
for(int i = 1; i<n; ++i){
flag.push_back(a[i]-a[i-1]-1);
}
sort(flag.rbegin(), flag.rend());
for(int i = k; i<flag.size(); ++i){
ans += flag[i];
}
cout << ans << "\n";
}
Compilation message (stderr)
stove.cpp: In function 'int main()':
stove.cpp:27:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for(int i = k; i<flag.size(); ++i){
| ~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |