제출 #1316996

#제출 시각아이디문제언어결과실행 시간메모리
1316996djsksbrbfArt Exhibition (JOI18_art)C++20
50 / 100
131 ms8580 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair <ll, ll> pii;
#define fi first
#define se second
#define pb push_back

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n; cin >>n;
	vector <pii> v;
	v.pb({0, 0});
	for(int i = 1 ; i <= n ; i++){
		int a, b; cin >> a >> b;
		v.pb({a, b});
	}
	sort(v.begin(), v.end());
	
	ll pref[5005];
	pref[0] = 0;
	for(int i = 1 ; i <= n ; i++)pref[i] = pref[i - 1] + v[i].se;
	
	ll ans = 0;
	for(int i = 1 ; i <= n; i++){
		for(int j = i ; j <= n ; j++){
			ans = max(ans, pref[j] - pref[i - 1] - v[j].fi + v[i].fi);
		}
	}
	cout << ans << endl;
	
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...