Submission #617910

# Submission time Handle Problem Language Result Execution time Memory
617910 2022-08-01T17:02:39 Z sokratisi Distributing Candies (IOI21_candies) C++17
Compilation error
0 ms 0 KB
#include "candies.h"
#include <set>
#include <vector>

using namespace std;

vector<int> distribute_candies(vector<int> c, vector<int> l,
                                    vector<int> r, vector<int> v) {
    int n = c.size();
    vector<int> s(n, 0);
    int q = l.size();
    vector<pair<pair<int, int>, int>> edges;
    for (int i = 0; i < q; i++) {
        edges.push_back({{l[i], 1}, v[i]});
        edges.push_back({{r[i] + 1, 0}, v[i]});
    }
    sort(edges.begin(), edges.end());
    int pos = 0;
    int add = 0;
    for (int i = 0; i < n; i++) {
        while (edges[pos].first.first == i) {
            if (edges[pos].first.second) {
                add += edges[pos].second;
            }
            else {
                add -= edges[pos].second;
            }
            pos++;
        }
        s[i] = min(c[i], add);
    }

    return s;
}

Compilation message

candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:17:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   17 |     sort(edges.begin(), edges.end());
      |     ^~~~
      |     short