# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1049816 |
2024-08-09T05:28:42 Z |
vjudge1 |
Stove (JOI18_stove) |
C++17 |
|
0 ms |
348 KB |
#include <bits/stdc++.h>
using namespace std;
//typedef long long ll;
///typedef unsigned long long ull;
typedef pair<int,int> pi;
//typedef pair<long long,long long> pl;
#define all(s) s.begin(),s.end()
#define F first
#define S second
#define sz(a) a.size()
#define int long long
//const ll mod = 998244353;
//const ll mod1 = 1e9+7;
//const ll INF = 1e18;
const int N = 100200;
const int inf = 1e9+200;
int n,k;
int a[N];
vector<int> p;
int ans=0;
void solve() {
cin>>n>>k;
for(int i=1;i<=n;++i) {
cin>>a[i];
}
a[n+1]=inf;
for(int i=1,j=1;i<=n;++i) {
if(a[i]+1!=a[i+1]) {
p.push_back(a[i+1]-a[i]-1);
ans+=(a[i]-a[j]+1);
j=i+1;
}
}
sort(all(p));
int cnt=sz(p)-k;
for(auto u:p) {
if(cnt>0) {
ans+=u;
--cnt;
}
else {
break;
}
}
cout<<ans<<'\n';
}
signed main() {
ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
int T=1;
//cin>>T;
while(T--) {
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |