-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsticker.cpp
More file actions
51 lines (37 loc) · 866 Bytes
/
sticker.cpp
File metadata and controls
51 lines (37 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
using namespace std;
int memo[2][100001];
int sticker[2][100001];
int max(int a, int b){
return a > b ? a:b;
}
int score_sticker(int n){
int i, j;
for(i = 0; i < 2; i++){
for(j = 1; j <= n; j++){
cin >> sticker[i][j];
}
}
memo[0][0] = memo[1][0] = 0;
memo[0][1] = sticker[0][1];
memo[1][1] = sticker[1][1];
for(i = 2; i <= n; i++){
memo[0][i] = max(memo[1][i-1], memo[1][i-2]) + sticker[0][i];
memo[1][i] = max(memo[0][i-1], memo[0][i-2]) + sticker[1][i];
}
return max(memo[0][n], memo[1][n]);
}
int main(void){
int i;
int t, n;
cin >> t;
int result[t];
for(i = 0; i < t; i++){
cin >> n;
result[i] = score_sticker(n);
}
for(i = 0; i < t; i++){
cout << result[i] << endl;
}
return 0;
}