#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
#define ll long long
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
int const nmax = 500000;
ll const inf = 1000000000000000;
struct number{
ll cost;
ll sz;
bool operator < (number const &a) const{
return sz < a.sz;
}
};
number v[1 + nmax];
ll sum[1 + nmax];
int main()
{
int n;
cin >> n;
for(int i = 1;i <= n; i++){
cin >> v[i].sz >> v[i].cost;
}
sort(v + 1, v + n + 1);
for(int i = 1;i <= n ; i++)
sum[i] = sum[i - 1] + v[i].cost;
ll smax = -inf;
ll smin = inf;
for(int i = 1;i <= n; i++){
smax = MAX(smax, sum[i] - v[i].sz - smin);
smin = MIN(smin, sum[i - 1] - v[i].sz);
}
cout << smax;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |