-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path14930_FARIDA.cpp
84 lines (79 loc) · 1.09 KB
/
14930_FARIDA.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
TASK: Princess Farida
ALGO: dynamic programming
Input:
6
5
1 2 3 4 5
1
10
3
2 4 3
0
9
1 3 5 9 7 10 1 10 100
4
4 3 2 1
Output:
Case 1: 9
Case 2: 10
Case 3: 5
Case 4: 0
Case 5: 122
Case 6: 6
*/
#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int t;
scanf("%d", &t);
for(int i=0; i<t; i++)
{
long n;
scanf("%ld", &n);
vector<long long> monsters(n, 0);
for(long j=0; j<n; j++)
{
scanf("%lld", &monsters[j]);
}
long long ret=0;
if(n>3)
{
monsters[n-3]+=monsters[n-1];
for(long j=n-4; j>=0; j--)
{
if(monsters[j+2]>monsters[j+3])
monsters[j]+=monsters[j+2];
else
monsters[j]+=monsters[j+3];
}
/*for(int j=0; j<n; j++)
{
printf("%ld ", monsters[j]);
}
printf("\n");*/
for(long j=0; j<2; j++)
{
if(ret<monsters[j])
ret=monsters[j];
}
}
else if(n)
{
for(long j=n-3; j>=0; j--)
{
monsters[j]+=monsters[j+2];
}
for(long j=0; j<(n>2?2:n); j++)
{
if(ret<monsters[j])
ret=monsters[j];
}
}
printf("Case %d: %lld\n", i+1, ret);
}
return 0;
}