Submission #1316123

#TimeUsernameProblemLanguageResultExecution timeMemory
1316123khanhphucscratchBoxes with souvenirs (IOI15_boxes)C++20
10 / 100
0 ms332 KiB
#include "boxes.h"
#include<bits/stdc++.h>
#define int long long
using namespace std;
int delivery(int32_t n, int32_t k, int32_t len, int32_t p[]) {
    int l = 0, r = n-1;
    int ans = 0;
    while(l < n && p[l] == 0) l++;
    while(l <= r){
        if(r-l+1 <= k){
            ans += 2*min(len-p[l], p[r]);
            break;
        }
        else{
            if(len-p[r-k+1] < p[l+k-1]){
                ans += 2*(len-p[r-k+1]); r -= k;
            }
            else{
                ans += 2*p[l+k-1]; l += k;
            }
        }
    }
    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...