Submission #420093

#TimeUsernameProblemLanguageResultExecution timeMemory
420093dxz05Boxes with souvenirs (IOI15_boxes)C++14
0 / 100
1 ms204 KiB
#include "boxes.h"
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

long long delivery(int N, int K, int L, int p[]) {
    vector<int> v;
    for (int i = 0; i < N; i++){
        if (p[i]) v.push_back(p[i]);
    }
    N = v.size();

    ll ans = 0;
    while (!v.empty()){
        int sz = v.size();
        if (sz <= K){
            int fr = L - v[0], ls = v[sz - 1];

            ans += min({L, fr * 2, ls * 2});

            v.clear();
            break;
        }

        int cost1 = min(L, v[K - 1] * 2);
        int cost2 = min(L, v[sz - K] * 2);

        if (cost1 <= cost2){
            ans += cost1;
            v.erase(v.begin(), v.begin() + K);
        } else {
            ans += cost2;
            v.erase(v.end() - K, v.end());
        }

    }

    return ans;
}

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:13:15: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   13 |     N = v.size();
      |         ~~~~~~^~
boxes.cpp:17:24: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   17 |         int sz = v.size();
      |                  ~~~~~~^~
#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...