# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
850989 |
2023-09-18T06:29:25 Z |
askow |
Stove (JOI18_stove) |
C++14 |
|
0 ms |
348 KB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n,k;
cin>>n>>k;
int a[n];
for(int i=0;i<n;i++)cin>>a[i];
/*
if(n<=20){
int ans=1e18;
for(int i=0;i<(1LL<<n);i++){
if(__builtin_popcount(i)>k)continue;
if(__builtin_popcount(i)<k)continue;
int R=0;
int pret=0;
for(int j=0;j<n;j++){
if(i&(1LL<<j)){
// ovde gasim
R+=(a[j]+1)-(a[pret]);
pret=j+1;
}
}
//return 0;
if(i&(1LL<<(n-1))){
//cout<<i<<" "<<R;
//cout<<endl;
ans=min(ans,R);
//cout<<i<<" "<<R;
//cout<<endl;
}
}
cout<<ans;
return 0;
}*/
priority_queue<pair<int,pair<int,int>>>pq;
pq.push({(a[n-1]+1)-a[0],{0,n-1}});
int pozicija[n];
for(int i=0;i<n;i++)pozicija[i]=0;
pozicija[n-1]=1;
k--;
while(k--){
int vrednost=pq.top().first;
int l=pq.top().second.first;
int r=pq.top().second.second;
//cout<<vrednost<<" "<<l<<" "<<r;
//cout<<":::";
pq.pop();
int pret=-1;
for(int i=l;i>=0;i--){
if(pozicija[i]){
pret=i;
break;
}
}
if(pret==-1)pret=0;
int R=1e18;
for(int i=l;i<r;i++){
int V=(a[i]+1)-a[pret];
int V1=(a[r]+1)-a[i+1];
R=min(R,V+V1);
}
int ind=-1;
for(int i=l;i<r;i++){
int V=(a[i]+1)-a[pret];
int V1=(a[r]+1)-a[i+1];
if(R==V+V1){
ind=i;
}
}
pozicija[ind]=1;
pq.push({(a[ind]+1)-a[pret],{l,ind}});
pq.push({(a[r]+1)-a[ind+1],{ind+1,r}});
}
int ans=0;
int pret=0;
for(int i=0;i<n;i++){
if(pozicija[i]){
ans+=(a[i]+1)-a[pret];
pret=i+1;
}
}
cout<<ans;
}
Compilation message
stove.cpp: In function 'int main()':
stove.cpp:45:13: warning: unused variable 'vrednost' [-Wunused-variable]
45 | int vrednost=pq.top().first;
| ^~~~~~~~
# |
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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |