Submission #786794

# Submission time Handle Problem Language Result Execution time Memory
786794 2023-07-18T12:51:44 Z Acanikolic Art Exhibition (JOI18_art) C++17
100 / 100
170 ms 16120 KB
#include <bits/stdc++.h>
 
#define ll long long 

#define int long long 
 
#define pb push_back 

#define F first
 
#define S second
 
using namespace std;
 
const long long N = 500000+10;
 
const long long mod = 1e9+7;
 
const long long inf = 1e18;

vector<int>a(N),b(N);

bool cmp(int i,int j) {
	if(a[i] == a[j]) return b[i] < b[j];
	return a[i] < a[j];
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
   //pref[r]-a[r]-pref[l-1]+a[l]
    
	int n,res=0;
	cin >> n;
	vector<int>pref(n,0),order(n,0);
	for(int i=0;i<n;i++) {
		cin >> a[i] >> b[i];
		res = max(res,b[i]);
	}
	iota(order.begin(),order.end(),0);
	sort(order.begin(),order.end(),cmp);
	int mn = inf;
	//for(int i=0;i<n;i++) cout << a[order[i]] << ' ' << b[order[i]] << endl;
	for(int i=0;i<n;i++) {
		pref[i] = b[order[i]];
		if(i > 0) pref[i] += pref[i-1];
		if(mn == inf) {
			mn = -a[order[i]];
			continue;
		}
	//	cout << pref[i] << ' ' << mn << ' ' << a[order[i]] << endl;
		res = max(res,pref[i]-mn-a[order[i]]);
		mn = min(mn,pref[i-1]-a[order[i]]);
	}
	cout << res;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8148 KB Output is correct
2 Correct 3 ms 8148 KB Output is correct
3 Correct 3 ms 8148 KB Output is correct
4 Correct 3 ms 8148 KB Output is correct
5 Correct 3 ms 8148 KB Output is correct
6 Correct 3 ms 8148 KB Output is correct
7 Correct 3 ms 8148 KB Output is correct
8 Correct 3 ms 8148 KB Output is correct
9 Correct 3 ms 8148 KB Output is correct
10 Correct 3 ms 8048 KB Output is correct
11 Correct 4 ms 8116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8148 KB Output is correct
2 Correct 3 ms 8148 KB Output is correct
3 Correct 3 ms 8148 KB Output is correct
4 Correct 3 ms 8148 KB Output is correct
5 Correct 3 ms 8148 KB Output is correct
6 Correct 3 ms 8148 KB Output is correct
7 Correct 3 ms 8148 KB Output is correct
8 Correct 3 ms 8148 KB Output is correct
9 Correct 3 ms 8148 KB Output is correct
10 Correct 3 ms 8048 KB Output is correct
11 Correct 4 ms 8116 KB Output is correct
12 Correct 3 ms 8148 KB Output is correct
13 Correct 3 ms 8164 KB Output is correct
14 Correct 3 ms 8148 KB Output is correct
15 Correct 3 ms 8148 KB Output is correct
16 Correct 3 ms 8148 KB Output is correct
17 Correct 4 ms 8148 KB Output is correct
18 Correct 3 ms 8168 KB Output is correct
19 Correct 3 ms 8168 KB Output is correct
20 Correct 3 ms 8168 KB Output is correct
21 Correct 3 ms 8148 KB Output is correct
22 Correct 3 ms 8168 KB Output is correct
23 Correct 3 ms 8148 KB Output is correct
24 Correct 3 ms 8148 KB Output is correct
25 Correct 3 ms 8148 KB Output is correct
26 Correct 3 ms 8148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8148 KB Output is correct
2 Correct 3 ms 8148 KB Output is correct
3 Correct 3 ms 8148 KB Output is correct
4 Correct 3 ms 8148 KB Output is correct
5 Correct 3 ms 8148 KB Output is correct
6 Correct 3 ms 8148 KB Output is correct
7 Correct 3 ms 8148 KB Output is correct
8 Correct 3 ms 8148 KB Output is correct
9 Correct 3 ms 8148 KB Output is correct
10 Correct 3 ms 8048 KB Output is correct
11 Correct 4 ms 8116 KB Output is correct
12 Correct 3 ms 8148 KB Output is correct
13 Correct 3 ms 8164 KB Output is correct
14 Correct 3 ms 8148 KB Output is correct
15 Correct 3 ms 8148 KB Output is correct
16 Correct 3 ms 8148 KB Output is correct
17 Correct 4 ms 8148 KB Output is correct
18 Correct 3 ms 8168 KB Output is correct
19 Correct 3 ms 8168 KB Output is correct
20 Correct 3 ms 8168 KB Output is correct
21 Correct 3 ms 8148 KB Output is correct
22 Correct 3 ms 8168 KB Output is correct
23 Correct 3 ms 8148 KB Output is correct
24 Correct 3 ms 8148 KB Output is correct
25 Correct 3 ms 8148 KB Output is correct
26 Correct 3 ms 8148 KB Output is correct
27 Correct 4 ms 8304 KB Output is correct
28 Correct 4 ms 8300 KB Output is correct
29 Correct 5 ms 8276 KB Output is correct
30 Correct 5 ms 8404 KB Output is correct
31 Correct 4 ms 8304 KB Output is correct
32 Correct 4 ms 8304 KB Output is correct
33 Correct 4 ms 8276 KB Output is correct
34 Correct 4 ms 8276 KB Output is correct
35 Correct 4 ms 8352 KB Output is correct
36 Correct 4 ms 8276 KB Output is correct
37 Correct 6 ms 8456 KB Output is correct
38 Correct 4 ms 8276 KB Output is correct
39 Correct 4 ms 8276 KB Output is correct
40 Correct 4 ms 8276 KB Output is correct
41 Correct 5 ms 8276 KB Output is correct
42 Correct 4 ms 8276 KB Output is correct
43 Correct 4 ms 8276 KB Output is correct
44 Correct 4 ms 8300 KB Output is correct
45 Correct 5 ms 8304 KB Output is correct
46 Correct 4 ms 8276 KB Output is correct
47 Correct 4 ms 8276 KB Output is correct
48 Correct 5 ms 8276 KB Output is correct
49 Correct 5 ms 8300 KB Output is correct
50 Correct 5 ms 8276 KB Output is correct
51 Correct 4 ms 8276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8148 KB Output is correct
2 Correct 3 ms 8148 KB Output is correct
3 Correct 3 ms 8148 KB Output is correct
4 Correct 3 ms 8148 KB Output is correct
5 Correct 3 ms 8148 KB Output is correct
6 Correct 3 ms 8148 KB Output is correct
7 Correct 3 ms 8148 KB Output is correct
8 Correct 3 ms 8148 KB Output is correct
9 Correct 3 ms 8148 KB Output is correct
10 Correct 3 ms 8048 KB Output is correct
11 Correct 4 ms 8116 KB Output is correct
12 Correct 3 ms 8148 KB Output is correct
13 Correct 3 ms 8164 KB Output is correct
14 Correct 3 ms 8148 KB Output is correct
15 Correct 3 ms 8148 KB Output is correct
16 Correct 3 ms 8148 KB Output is correct
17 Correct 4 ms 8148 KB Output is correct
18 Correct 3 ms 8168 KB Output is correct
19 Correct 3 ms 8168 KB Output is correct
20 Correct 3 ms 8168 KB Output is correct
21 Correct 3 ms 8148 KB Output is correct
22 Correct 3 ms 8168 KB Output is correct
23 Correct 3 ms 8148 KB Output is correct
24 Correct 3 ms 8148 KB Output is correct
25 Correct 3 ms 8148 KB Output is correct
26 Correct 3 ms 8148 KB Output is correct
27 Correct 4 ms 8304 KB Output is correct
28 Correct 4 ms 8300 KB Output is correct
29 Correct 5 ms 8276 KB Output is correct
30 Correct 5 ms 8404 KB Output is correct
31 Correct 4 ms 8304 KB Output is correct
32 Correct 4 ms 8304 KB Output is correct
33 Correct 4 ms 8276 KB Output is correct
34 Correct 4 ms 8276 KB Output is correct
35 Correct 4 ms 8352 KB Output is correct
36 Correct 4 ms 8276 KB Output is correct
37 Correct 6 ms 8456 KB Output is correct
38 Correct 4 ms 8276 KB Output is correct
39 Correct 4 ms 8276 KB Output is correct
40 Correct 4 ms 8276 KB Output is correct
41 Correct 5 ms 8276 KB Output is correct
42 Correct 4 ms 8276 KB Output is correct
43 Correct 4 ms 8276 KB Output is correct
44 Correct 4 ms 8300 KB Output is correct
45 Correct 5 ms 8304 KB Output is correct
46 Correct 4 ms 8276 KB Output is correct
47 Correct 4 ms 8276 KB Output is correct
48 Correct 5 ms 8276 KB Output is correct
49 Correct 5 ms 8300 KB Output is correct
50 Correct 5 ms 8276 KB Output is correct
51 Correct 4 ms 8276 KB Output is correct
52 Correct 168 ms 16116 KB Output is correct
53 Correct 164 ms 16100 KB Output is correct
54 Correct 165 ms 16100 KB Output is correct
55 Correct 164 ms 16084 KB Output is correct
56 Correct 166 ms 16120 KB Output is correct
57 Correct 167 ms 16084 KB Output is correct
58 Correct 170 ms 16100 KB Output is correct
59 Correct 167 ms 16084 KB Output is correct
60 Correct 163 ms 16084 KB Output is correct
61 Correct 164 ms 16084 KB Output is correct
62 Correct 165 ms 16108 KB Output is correct
63 Correct 170 ms 16084 KB Output is correct
64 Correct 164 ms 16116 KB Output is correct
65 Correct 163 ms 16084 KB Output is correct
66 Correct 164 ms 16084 KB Output is correct
67 Correct 163 ms 16108 KB Output is correct
68 Correct 164 ms 16112 KB Output is correct