# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
556120 |
2022-05-02T11:26:57 Z |
HeatDroppa |
Stove (JOI18_stove) |
C++14 |
|
19 ms |
2772 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int lim=1e5+4;
const ll inf=1e18;
//ll dp_new[lim];
//ll dp_old[lim];
int t[lim];
int n,k;
/*void solve(int l,int r,int optl,int optr)
{
if(l>r) return ;
int med=(l+r)>>1;
pair<ll,int> bst={inf,-1};
for(int i=optl;i<=min(med,optr);++i)
bst=min(bst,{dp_old[i-1]+t[med]-t[i]+1,i});
dp_new[med]=bst.first;
solve(l,med-1,optl,bst.second);
solve(med+1,r,bst.second,optr);
}*/
void solution()
{
ll ans=t[n]-t[1]+1;
vector<ll> raz;
for(int i=2;i<=n;++i)
raz.push_back(t[i]-t[i-1]-1);
sort(raz.begin(),raz.end(),greater<ll>());
for(int i=0;i<k-1;++i)
ans-=raz[i];
cout<<ans<<'\n';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>n>>k;
for(int i=1;i<=n;++i)
cin>>t[i];//,
//dp_old[i]=t[i]-t[1]+1;
/*for(int i=2;i<=k;++i)
solve(i,n,i,n),
swap(dp_old,dp_new);
cout<<dp_old[n]<<'\n';*/
solution();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
19 ms |
1836 KB |
Output is correct |
17 |
Correct |
19 ms |
1804 KB |
Output is correct |
18 |
Correct |
18 ms |
1876 KB |
Output is correct |
19 |
Correct |
18 ms |
2772 KB |
Output is correct |
20 |
Correct |
18 ms |
2716 KB |
Output is correct |
21 |
Correct |
17 ms |
2772 KB |
Output is correct |
22 |
Correct |
17 ms |
2768 KB |
Output is correct |
23 |
Correct |
17 ms |
2764 KB |
Output is correct |
24 |
Correct |
18 ms |
2772 KB |
Output is correct |