Skip to content

Commit 463893d

Browse files
committed
Create 1637C-AndrewAndStones.cpp
1 parent a9b66fe commit 463893d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

1637C-AndrewAndStones.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <cstdio>
2+
typedef long long ll;
3+
4+
int main(){
5+
6+
long t; scanf("%ld", &t);
7+
while(t--){
8+
long n; scanf("%ld", &n);
9+
bool ones(true), threeodd(false); ll cnt(0);
10+
for(long p = 0; p < n; p++){
11+
ll x; scanf("%lld", &x);
12+
if(p == 0 || p == n - 1){continue;}
13+
if(n == 3 && p == 1){threeodd = x % 2;}
14+
if(x > 1){ones = false;}
15+
cnt += (x + 1) / 2;
16+
}
17+
18+
bool impossible = ones || threeodd;
19+
printf("%lld\n", impossible ? (-1) : cnt);
20+
}
21+
22+
}

0 commit comments

Comments
 (0)