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;
int main() {
long long n, wiel, wart, l = 0, p = 0, overall = 0;
cin >> n;
map<long long, long long> m;
vector<vector<long long>> v;
for (int i = 0; i < n; i++) {
cin >> wiel >> wart;
m[wiel] += wart;
overall += wart;
}
for (auto [wie, war] : m) {
v.push_back({wie, war});
}
long long wyn = 0, suma = v[0][1], osw = v[v.size() - 1][0];
for(int i = 0; i < v.size(); i++) {
if (overall - osw + v[i][0] > wyn) {
wyn = overall - osw + v[i][0];
}
overall -= v[i][1];
}
while (l < v.size()) {
if (p < v.size() && suma - v[p][0] + v[l][0] > 0) {
if (suma - v[p][0] + v[l][0] > wyn) {
wyn = suma - v[p][0] + v[l][0];
}
p += 1;
if (p < v.size() - 1) {
suma += v[p][1];
}
}
else {
suma -= v[l][1];
l += 1;
}
}
cout << wyn;
}
Compilation message (stderr)
art.cpp: In function 'int main()':
art.cpp:17:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for(int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
art.cpp:23:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | while (l < v.size()) {
| ~~^~~~~~~~~~
art.cpp:24:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | if (p < v.size() && suma - v[p][0] + v[l][0] > 0) {
| ~~^~~~~~~~~~
art.cpp:29:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | if (p < v.size() - 1) {
| ~~^~~~~~~~~~~~~~
# | 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... |