# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1017487 |
2024-07-09T08:21:22 Z |
vjudge1 |
Stove (JOI18_stove) |
C++17 |
|
0 ms |
348 KB |
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
using namespace std;
#define int long long
int mod = 1e18 + 7;
signed main(){
int n , k , mx = 0;
cin >> n >> k;
int a[n];
vector <int> v;
for(int i = 0; i < n; i++){
cin >> a[i];
if(i != 0){
v.push_back(abs(a[i] - a[i - 1]));
}
mx = max(mx , a[i]);
}
if(k == n){
cout << n;
return 0;
}
if(k == 1){
cout << mx ;
return 0;
}
sort(v.begin() ,v.end() );
reverse(v.begin() , v.end() );
// mx++;
int s = v.size();
for(int i = 0; i < min(s , k - 1LL); i++){
mx -= v[i] - 1;
}
cout << mx;
return 0;
}
//AZIM_BEST
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |