# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1008616 | khanhtb | Stove (JOI18_stove) | C++14 | 20 ms | 3100 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>
#define ll long long
#define ull unsigned long long
#define ld double
#define pb push_back
#define pf push_front
#define vi vector<ll>
#define vii vector<vi>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;
const ll mod = 1e9+7;
const ll inf = 1e18;
const ll base = 31;
const ll blocksz = 320;
const ll N = 5e5+8;
ll n,a[N],k;
void solve(){
cin >> n >> k;
ll ans = k;
priority_queue<ll,vi,greater<ll>> pq;
for(ll i = 1; i <= n; i++){
cin >> a[i];
if(i > 1) pq.push(a[i]-a[i-1]);
}
while(n > k){
ans += pq.top();
pq.pop();
n--;
}
cout << ans;
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
if(fopen("test.inp","r")){
freopen("test.inp","r",stdin);
freopen("test.out","w",stdout);
}
ll T = 1;
// cin >> T;
while(T--){
solve();
// cout << '\n';
}
}
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... |