-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFARIDA.cpp
68 lines (67 loc) · 1019 Bytes
/
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
#include<iostream>
#include<vector>
using namespace std;
int main()
{
long int T;
cin>> T;
for (long int s = 0; s < T; ++s)
{
long int N = 0;
cin>>N;
if(N == 0)
{
cout<<"Case "<<s+1<<": "<<0<<"\n";
continue;
}
vector<long int> arr(N);
for (long int i = 0; i < N; ++i)
cin>>arr[i];
vector<long int> ans(N);
vector<long int> filled(N,0);
for (long int i = 0; i < N; ++i)
{
if (i == 0)
{
ans[i] = arr[i];
filled[i] = 1;
}
else if( i == 1)
{
if(arr[1] >= arr[0])
{
ans[1] = arr[1];
filled[1] = 1;
}
else
{
ans[1] = arr[0];
}
}
else
{
if(filled[i-1] == 0)
{
ans[i] = arr[i] + ans[i-1];
filled[i] = 1;
}
else
{
long int res1 = arr[i] + ans[i-2];
long int res2 = ans[i-1];
if(res1 >= res2)
{
ans[i] = res1;
filled[i] = 1;
}
else
{
ans[i] = res2;
}
}
}
}
cout<<"Case "<<s+1<<": "<<ans[N-1]<<"\n";
}
return 0;
}