Submission #674831

#TimeUsernameProblemLanguageResultExecution timeMemory
674831benjaminkleynBoxes with souvenirs (IOI15_boxes)C++17
0 / 100
1 ms212 KiB
#include <bits/stdc++.h>
#include "boxes.h"
using namespace std;
typedef long long ll;

ll delivery(int n, int k, int l, int p[]) 
{
    vector<ll> L, R;
    for (int i = 0; i < n; i++)
        if (p[i] == 0)
            continue;
        else if (l - p[i] < p[i])
            L.push_back(l - p[i]);
        else
            R.push_back(p[i]);

    sort(L.rbegin(), L.rend());
    sort(R.rbegin(), R.rend());

    ll ans = 0;

    while (L.size() >= k)
    {
        for (int i = 0; i < k - 1; i++)
            L.pop_back();
        ans += 2 * L.back();
        L.pop_back();
    }
    while (R.size() >= k)
    {
        for (int i = 0; i < k - 1; i++)
            R.pop_back();
        ans += 2 * R.back();
        R.pop_back();
    }
    if (L.size() == 0)
        ans += 2 * R.back();
    else if (R.size() == 0)
        ans += 2 * L.back();
    else
    {
        ans += l;
        if (L.size() + R.size() > k)
            ans += min(R[k - L.size()], L[k - R.size()]);
    }

    return ans;
}

Compilation message (stderr)

boxes.cpp: In function 'll delivery(int, int, int, int*)':
boxes.cpp:22:21: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   22 |     while (L.size() >= k)
      |            ~~~~~~~~~^~~~
boxes.cpp:29:21: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |     while (R.size() >= k)
      |            ~~~~~~~~~^~~~
boxes.cpp:43:33: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   43 |         if (L.size() + R.size() > k)
      |             ~~~~~~~~~~~~~~~~~~~~^~~
#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...