제출 #874261

#제출 시각아이디문제언어결과실행 시간메모리
874261tsumondaiArt Exhibition (JOI18_art)C++14
100 / 100
163 ms21436 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME  (1.0 * clock() / CLOCKS_PER_SEC)

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int N = 5e5 + 5;
 
const int oo = 1e18, mod = 1e9 + 7;
 
int n, m, k;
vector<ii> arts;

void process() {
	sort(arts.begin(), arts.end());
	int res=-oo, mx=-oo, pref=0;
	foru(i,0,n-1) {
		mx=max(mx, -pref+arts[i].fi);
		res=max(res, (pref+arts[i].se)-arts[i].fi+mx);
		pref+=arts[i].se;
		//cout << mx << ' ' << res << ' ' << pref << '\n';
	}
	cout << res;
    return;
}

signed main() {
    cin.tie(0)->sync_with_stdio(false);
    //freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
    cin >> n;
    foru(i,1,n) {
    	int sz, va;
    	cin >> sz >> va;
    	arts.pb({sz, va});
    }
    process();
    cerr << "Time elapsed: " << __TIME << " s.\n";
    return 0;
}

/*
Xét các trường hợp đặc biệt
Kiểm tra lại input/output
Cố gắng trâu
Lật ngược bài toán
Calm down and get VOI 
Stream of thought:
S=total value
find max of s-(a[max]-a[min]);
first, sort by value?
subtask 1: bitmask
subtask 2: dp
subtask 3: dp w/ data structure
subtask 4: something nlogn?? (dp w/ data struct?)
dq?
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...