답안 #46276

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
46276 2018-04-18T17:22:42 Z fredbr Art Exhibition (JOI18_art) C++17
0 / 100
2 ms 376 KB
#include <bits/stdc++.h>

#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> ii;

const int maxn = 500010;
const ll inf = 0x3f3f3f3f3f3f3f;

ll p[maxn];
ii v[maxn];

ll a[maxn];
ll b[maxn];

ll s[maxn];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;

	for (int i = 1; i <= n; i++) cin >> v[i].ff >> v[i].ss;

	sort(v+1, v+1+n);

	for (int i = 1; i <= n; i++) p[i] = p[i-1] + v[i].ss;

	for (int i = 1; i <= n; i++) a[i] = -p[i-1] + v[i].ff;

	for (int i = 1; i <= n; i++) b[i] = p[i]-v[i].ff;

	for (int i = n; i >= 1; i--) s[i] = max(s[i+1], b[i]);

	ll ans = -inf;

	for (int i = 1; i <= n; i++) ans = max(ans, a[i]+s[i]);

	cout << ans << "\n";
}
# 결과 실행 시간 메모리 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 -