답안 #79985

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
79985 2018-10-17T20:23:42 Z Genezio Art Exhibition (JOI18_art) C++14
100 / 100
321 ms 254888 KB
#include<bits/stdc++.h>

using namespace std;

const int N = 500010;

#define ll long long int
#define F first
#define S second

pair<ll,ll> v[N];
ll dp[N][2];
int n;

ll f(int x,int y) {
	if(dp[x][y]>=0) return dp[x][y];
	ll aux = v[x].S-v[x].F+v[x-1].F;
	if(y) {
		if(x==n) return aux;
		return dp[x][y]=max(aux,aux+f(x+1,y));
	} else {
		if(x==n) return v[x].S;
		return dp[x][y]=max({v[x].S,f(x+1,y),v[x].S+f(x+1,y+1)});
	}
}

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

	cin>>n;
	for(int i=1;i<=n;i++) {
		cin>>v[i].F>>v[i].S;
	}
	sort(v+1,v+n+1);
	memset(dp,-1,sizeof(dp));
	cout<<f(1,0)<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8184 KB Output is correct
2 Correct 9 ms 8324 KB Output is correct
3 Correct 9 ms 8364 KB Output is correct
4 Correct 10 ms 8440 KB Output is correct
5 Correct 8 ms 8440 KB Output is correct
6 Correct 11 ms 8492 KB Output is correct
7 Correct 8 ms 8584 KB Output is correct
8 Correct 8 ms 8588 KB Output is correct
9 Correct 8 ms 8588 KB Output is correct
10 Correct 8 ms 8588 KB Output is correct
11 Correct 8 ms 8588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8184 KB Output is correct
2 Correct 9 ms 8324 KB Output is correct
3 Correct 9 ms 8364 KB Output is correct
4 Correct 10 ms 8440 KB Output is correct
5 Correct 8 ms 8440 KB Output is correct
6 Correct 11 ms 8492 KB Output is correct
7 Correct 8 ms 8584 KB Output is correct
8 Correct 8 ms 8588 KB Output is correct
9 Correct 8 ms 8588 KB Output is correct
10 Correct 8 ms 8588 KB Output is correct
11 Correct 8 ms 8588 KB Output is correct
12 Correct 8 ms 8588 KB Output is correct
13 Correct 8 ms 8588 KB Output is correct
14 Correct 8 ms 8740 KB Output is correct
15 Correct 8 ms 8740 KB Output is correct
16 Correct 9 ms 8740 KB Output is correct
17 Correct 8 ms 8760 KB Output is correct
18 Correct 11 ms 8768 KB Output is correct
19 Correct 8 ms 8776 KB Output is correct
20 Correct 8 ms 8784 KB Output is correct
21 Correct 8 ms 8808 KB Output is correct
22 Correct 8 ms 8832 KB Output is correct
23 Correct 8 ms 8840 KB Output is correct
24 Correct 8 ms 8848 KB Output is correct
25 Correct 10 ms 8856 KB Output is correct
26 Correct 8 ms 8864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8184 KB Output is correct
2 Correct 9 ms 8324 KB Output is correct
3 Correct 9 ms 8364 KB Output is correct
4 Correct 10 ms 8440 KB Output is correct
5 Correct 8 ms 8440 KB Output is correct
6 Correct 11 ms 8492 KB Output is correct
7 Correct 8 ms 8584 KB Output is correct
8 Correct 8 ms 8588 KB Output is correct
9 Correct 8 ms 8588 KB Output is correct
10 Correct 8 ms 8588 KB Output is correct
11 Correct 8 ms 8588 KB Output is correct
12 Correct 8 ms 8588 KB Output is correct
13 Correct 8 ms 8588 KB Output is correct
14 Correct 8 ms 8740 KB Output is correct
15 Correct 8 ms 8740 KB Output is correct
16 Correct 9 ms 8740 KB Output is correct
17 Correct 8 ms 8760 KB Output is correct
18 Correct 11 ms 8768 KB Output is correct
19 Correct 8 ms 8776 KB Output is correct
20 Correct 8 ms 8784 KB Output is correct
21 Correct 8 ms 8808 KB Output is correct
22 Correct 8 ms 8832 KB Output is correct
23 Correct 8 ms 8840 KB Output is correct
24 Correct 8 ms 8848 KB Output is correct
25 Correct 10 ms 8856 KB Output is correct
26 Correct 8 ms 8864 KB Output is correct
27 Correct 14 ms 9256 KB Output is correct
28 Correct 11 ms 9384 KB Output is correct
29 Correct 11 ms 9512 KB Output is correct
30 Correct 11 ms 9640 KB Output is correct
31 Correct 11 ms 9768 KB Output is correct
32 Correct 11 ms 9896 KB Output is correct
33 Correct 11 ms 10024 KB Output is correct
34 Correct 11 ms 10152 KB Output is correct
35 Correct 10 ms 10280 KB Output is correct
36 Correct 11 ms 10464 KB Output is correct
37 Correct 10 ms 10536 KB Output is correct
38 Correct 11 ms 10664 KB Output is correct
39 Correct 11 ms 10792 KB Output is correct
40 Correct 11 ms 10920 KB Output is correct
41 Correct 10 ms 11048 KB Output is correct
42 Correct 11 ms 11172 KB Output is correct
43 Correct 10 ms 11300 KB Output is correct
44 Correct 12 ms 11428 KB Output is correct
45 Correct 10 ms 11556 KB Output is correct
46 Correct 10 ms 11696 KB Output is correct
47 Correct 10 ms 11812 KB Output is correct
48 Correct 11 ms 11940 KB Output is correct
49 Correct 11 ms 12068 KB Output is correct
50 Correct 11 ms 12232 KB Output is correct
51 Correct 18 ms 12504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8184 KB Output is correct
2 Correct 9 ms 8324 KB Output is correct
3 Correct 9 ms 8364 KB Output is correct
4 Correct 10 ms 8440 KB Output is correct
5 Correct 8 ms 8440 KB Output is correct
6 Correct 11 ms 8492 KB Output is correct
7 Correct 8 ms 8584 KB Output is correct
8 Correct 8 ms 8588 KB Output is correct
9 Correct 8 ms 8588 KB Output is correct
10 Correct 8 ms 8588 KB Output is correct
11 Correct 8 ms 8588 KB Output is correct
12 Correct 8 ms 8588 KB Output is correct
13 Correct 8 ms 8588 KB Output is correct
14 Correct 8 ms 8740 KB Output is correct
15 Correct 8 ms 8740 KB Output is correct
16 Correct 9 ms 8740 KB Output is correct
17 Correct 8 ms 8760 KB Output is correct
18 Correct 11 ms 8768 KB Output is correct
19 Correct 8 ms 8776 KB Output is correct
20 Correct 8 ms 8784 KB Output is correct
21 Correct 8 ms 8808 KB Output is correct
22 Correct 8 ms 8832 KB Output is correct
23 Correct 8 ms 8840 KB Output is correct
24 Correct 8 ms 8848 KB Output is correct
25 Correct 10 ms 8856 KB Output is correct
26 Correct 8 ms 8864 KB Output is correct
27 Correct 14 ms 9256 KB Output is correct
28 Correct 11 ms 9384 KB Output is correct
29 Correct 11 ms 9512 KB Output is correct
30 Correct 11 ms 9640 KB Output is correct
31 Correct 11 ms 9768 KB Output is correct
32 Correct 11 ms 9896 KB Output is correct
33 Correct 11 ms 10024 KB Output is correct
34 Correct 11 ms 10152 KB Output is correct
35 Correct 10 ms 10280 KB Output is correct
36 Correct 11 ms 10464 KB Output is correct
37 Correct 10 ms 10536 KB Output is correct
38 Correct 11 ms 10664 KB Output is correct
39 Correct 11 ms 10792 KB Output is correct
40 Correct 11 ms 10920 KB Output is correct
41 Correct 10 ms 11048 KB Output is correct
42 Correct 11 ms 11172 KB Output is correct
43 Correct 10 ms 11300 KB Output is correct
44 Correct 12 ms 11428 KB Output is correct
45 Correct 10 ms 11556 KB Output is correct
46 Correct 10 ms 11696 KB Output is correct
47 Correct 10 ms 11812 KB Output is correct
48 Correct 11 ms 11940 KB Output is correct
49 Correct 11 ms 12068 KB Output is correct
50 Correct 11 ms 12232 KB Output is correct
51 Correct 18 ms 12504 KB Output is correct
52 Correct 278 ms 55968 KB Output is correct
53 Correct 270 ms 68744 KB Output is correct
54 Correct 263 ms 81380 KB Output is correct
55 Correct 284 ms 93976 KB Output is correct
56 Correct 259 ms 106588 KB Output is correct
57 Correct 259 ms 119272 KB Output is correct
58 Correct 276 ms 132072 KB Output is correct
59 Correct 262 ms 144620 KB Output is correct
60 Correct 321 ms 157236 KB Output is correct
61 Correct 262 ms 169576 KB Output is correct
62 Correct 260 ms 181788 KB Output is correct
63 Correct 261 ms 193836 KB Output is correct
64 Correct 260 ms 206520 KB Output is correct
65 Correct 286 ms 218016 KB Output is correct
66 Correct 260 ms 230296 KB Output is correct
67 Correct 263 ms 242700 KB Output is correct
68 Correct 281 ms 254888 KB Output is correct