# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1268784 | bgnbvnbv | Stove (JOI18_stove) | C++20 | 14 ms | 2248 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define st first
#define nd second
#define pb push_back
#define endl '\n'
#define task "revenue"
using pii = pair<int,int>;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const int MAXN =5e3 + 5;
const int MAXK = 110;
const int LOG = 20;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(task".inp","r")) {
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
int n,k; cin >> n >> k;
vector <int> t(n);
for(int i=0;i<n;++i){
cin >> t[i];
}
int total = t[n-1] - t[0] + 1;
vector <int> gap;
for(int i=0;i < n - 1;++i){
int g = t[i+1] - (t[i] + 1);
gap.pb(g);
}
sort(gap.rbegin(),gap.rend());
for(int i=0;i < k -1 and i < (int)gap.size();++i){
total -= gap[i];
}
cout << total << endl;
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... |