#include <bits/stdc++.h>
using namespace std;
int main()
{
long long N;
cin >> N;
vector<pair<long long, long long>> Tab(N);
for (long long i = 0; i < N; i++)
{
long long a, b;
cin >> a >> b;
Tab[i] = {a, b};
}
sort(Tab.begin(), Tab.end());
vector<long long> cum(N + 1), size(N + 1);
for (long long i = 1; i <= N; i++)
{
size[i] = Tab[i - 1].first;
cum[i] = cum[i - 1] + Tab[i - 1].second;
}
long long best = 0;
long long last = 1;
for (long long i = 1; i <= N; i++)
{
long long temp = cum[i] - cum[last - 1];
temp -= size[i] - size[last];
if (temp < 0)
{
temp = cum[i] - cum[i - 1];
last = i;
}
best = max(best, temp);
}
cout << best;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |