Submission #988155

# Submission time Handle Problem Language Result Execution time Memory
988155 2024-05-24T07:04:27 Z Muhammet Art Exhibition (JOI18_art) C++17
0 / 100
1 ms 344 KB
#include <bits/stdc++.h>
using namespace std;

#define N 500005
#define ll long long int
#define sz(x) (int)x.size()
#define ff first
#define ss second

ll T, n, f[N], mx[N];

pair <ll,ll> a[N];

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

	cin >> n;
	ll s = 0;
	for(int i = 1; i <= n; i++){
		cin >> a[i].ff >> a[i].ss;
		s += a[i].ss;
	}
	
	sort(a+1,a+n+1);

	for(int i = n; i >= 1; i--){
		f[i] = f[i+1] + ((a[i].ff-a[i-1].ff) - a[i].ss);
		mx[i] = max(mx[i+1],f[i]);
	}

	ll ans = max(mx[1],0LL), x = 0;
	for(int i = 1; i < n; i++){
		x += ((a[i+1].ff-a[i].ff) - a[i].ss);
		ans = max(ans,x + mx[i+1]);
	}
	ans = (s - (a[n].ff - a[1].ff)) + ans;
	cout << ans;

	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -