Submission #751869

#TimeUsernameProblemLanguageResultExecution timeMemory
751869SebBoxes with souvenirs (IOI15_boxes)C++17
0 / 100
1 ms212 KiB
#include "boxes.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

long long delivery(int N, int K, int L, int p[]) {
    ll ans=0;
    int l=0,r=N-1,aux,in;
    bool flag = false;
    sort(p,p+N);
    for (;l<N;l+=K) {
        flag = false;
        aux = min(l+K-1,N-1);
        if (p[aux]>L/2 || p[l]>L/2) break;
        ans += min({L,2*p[aux],2*(L-p[l])});
        flag = true;
    }
    if (flag==false) l -= K;
    for (;r>=0;r-=K) {
        flag = false;
        aux = max(r-K+1,0);
        if (p[aux]<=L/2 || p[r]<=L/2) break;
        ans += min({L,2*p[r],2*(L-p[aux])});
        flag = true;
    }
    if (flag==false) r += K;
    for (in=l;in<=r;in++) if (p[in]>L/2) break;
    in--;
    ans += min(2*L,2*p[in] + 2*(L-p[in+1]));
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...