# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
923669 | Aiperiii | Boxes with souvenirs (IOI15_boxes) | C++14 | 1036 ms | 349832 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>
#include "boxes.h"
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
long long delivery(int N, int K, int L, int p[]) {
vector <ll> a,b,dpa,dpb;
for(int i=0;i<N;i++){
if(p[i]<=L-p[i])a.pb(p[i]);
else b.pb(L-p[i]);
}
a.pb(0);b.pb(0);
dpa.pb(0);dpb.pb(0);
sort(all(a));sort(all(b));
for(int i=1;i<a.size();i++){
if(i>=K)dpa.pb(dpa[i-K]+2*a[i]);
else dpa.pb(2*a[i]);
}
for(int i=1;i<b.size();i++){
if(i>=K)dpb.pb(dpb[i-K]+2*b[i]);
else dpb.pb(2*b[i]);
}
ll ans=dpa.back()+dpb.back();
for(int i=0;i<a.size();i++){
if((int)a.size()-i-1<=K){
int x=K-((int)a.size()-i-1);
int pos=(int)b.size()-1-x;
if(pos<0)pos=0;
ans=min(ans,dpa[i]+dpb[pos]+L);
}
}
return ans;
}
/*
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n,k,l;
cin>>n>>k>>l;
int pos[n];
for(int i=0;i<n;i++)cin>>pos[i];
cout<<delivery(n,k,l,pos);
}
*/
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |