# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
650040 | Kenpar | Stove (JOI18_stove) | C++17 | 28 ms | 2776 KiB |
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 endl '\n'
const ll MOD = 998244353;
const ll INF = 1e16;
const int INT_INF = 1e9;
const ll MAX = 1e6+1;
void solve(){
int n;
cin>>n;
int k;
cin>>k;
vector<bool> merged(n, false);
vector<int> arr(n);
vector<pair<int,int>> dif;
for(int i = 0; i < n; i++){
cin>>arr[i];
if(i != 0){
dif.push_back({arr[i] - arr[i-1], i-1});
}
}
sort(dif.begin(), dif.end() );
ll ans = 0;
for(pair<int,int> ch : dif){
//cout<<ch.first<<" "<<ch.second<<endl;
}
for(int i = 0; i < n-k; i++){
ans+=dif[i].first;
merged[dif[i].second] = true;
}
for(int i = 0; i < n; i++){
ans+=!merged[i];
}
cout<<ans;
}
int main()
{
cin.tie(NULL);
ios::sync_with_stdio(NULL);
int t = 1;
//cin >> t;
while(t--){
solve();
cout<<endl;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |