This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define num long long
#define ndata vector<num>
struct VBO {
map<num, num> sv_by_s;
num _get_e(num size) {
auto u = sv_by_s.find(size);
if (u == sv_by_s.end()) return 0;
num res = (*u).second;
sv_by_s.erase(size);
return res;
}
void insert (num size, num value) {
num old = _get_e(size);
sv_by_s.insert({ size, old + value });
}
};
int main () {
int nbArt;
cin >> nbArt;
VBO data;
for (int iA = 0; iA < nbArt; iA ++) {
num a, b;
cin >> a >> b;
data.insert(a, b);
}
ndata size;
ndata value;
for (auto d : data.sv_by_s) {
size .push_back(d.first);
value.push_back(d.second);
}
nbArt = size.size();
num max_v = 0;
num sum_v = 0;
num max_a = 0;
for (int iA = 0; iA < nbArt; iA ++) {
max_v = max(max_v, size[iA] - sum_v);
num answer = sum_v + value[iA] - size[iA] + max_v;
max_a = max(max_a, answer);
sum_v += value[iA];
}
cout << max_a;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |