# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
960992 | aminjon__ | Stove (JOI18_stove) | C++17 | 18 ms | 2188 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 all(x) (x).begin() , (x).end()
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
void solve(){
int n , k;
cin >> n >> k;
vector <int> t(n);
vector <int> gaps(n);
for(int i = 0;i < n;i++){
cin >> t[i];
if(i > 0){
gaps[i] = t[i]-t[i-1]-1;
}
}
int ans = t[n-1]-t[0]+1;
sort(gaps.begin()+1 , gaps.end() ,greater<ll>());
for(int j = 0;j < gaps.size();j++){
if(k > 0){
k--;
ans -= gaps[j];
}
}
cout<<ans<<endl;
}
int main(){
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
ll t=1;
//cin>>t;
while(t--){
solve();
}
return 0;
}
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... |