Submission #992429

#TimeUsernameProblemLanguageResultExecution timeMemory
992429phoenixBoxes with souvenirs (IOI15_boxes)C++17
10 / 100
1 ms348 KiB
#include "boxes.h"
#include <bits/stdc++.h>

using namespace std;

long long delivery(int n, int k, int ll, int p[]) {
    long long L = ll;
    long long res = 0;
    int l = -1, r = n;
    while (l + 1 < n && p[l + 1] * 2 < L) 
        l++;
    while (r - 1 >= 0 && (L - p[r - 1]) * 2 < L) 
        r--;
    int cnt = r - l - 1;
    res += cnt / k * L; 
    cnt %= k;
    if (cnt) {
        res += L; 
        for (int i = 0; i < k - cnt; i++) {
            int a1 = (l >= 0 ? p[l] : -1), a2 = (r < n ? L - p[r] : -1);
            if (max(a1, a2) == -1) 
                break;
            if (a1 >= a2) {
                l--;
            } else {
                r++;
            }
        }
    }
    while (l >= 0) {
        res += 2 * p[l];
        l -= k;
    }
    while (r < n) {
        res += 2 * (L - p[r]);
        r += k;
    }
    return res;
}

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:20:56: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   20 |             int a1 = (l >= 0 ? p[l] : -1), a2 = (r < n ? L - p[r] : -1);
      |                                                 ~~~~~~~^~~~~~~~~~~~~~~~
#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...