이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define task "MAXNUM"
#define pl pair<ll, ll>
#define pf push_front
#define pb push_back
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b, c) for (int i=a; i<=b; i+=c)
#define FORE(i, a, b, c) for (int i=a; i>=b; i+=c)
#define VI vector <int>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const int Mod = 123456789;
const int maxn = 5e5+1;
const ll Inf = 3e18;
pl A[maxn+1];
ll B[maxn+2], C[maxn+2], sum2, sum, n, res;
void Read()
{
cin >> n;
FOR(i, 1, n, 1) {
cin >> A[i].fi >> A[i].se;
sum2 += A[i].se;
}
}
void Solve()
{
B[0] = -Inf, C[n+1] = -Inf;
sort (A + 1, A + n + 1);
FOR(i, 1, n, 1) {
B[i] = max(B[i-1], A[i].fi - sum);
sum += A[i].se;
}
FORE(i, n, 1, -1) {
C[i] = max(C[i+1], sum2 - A[i].fi);
sum2 -= A[i].se;
}
//FOR(i, 1, n, 1) cout << B[i] << " " << C[i] << '\n';
FOR(i, 1, n, 1) {
res = max(res, C[i] + B[i]);
}
cout << res;
}
int main()
{
if (fopen (task".inp", "r")) {
freopen (task".inp", "r", stdin);
freopen (task".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t;
for (t=1; t--;)
{
Read(); Solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
art.cpp: In function 'int main()':
art.cpp:51:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | freopen (task".inp", "r", stdin);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
art.cpp:52:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
52 | freopen (task".out", "w", stdout);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |