Codeforces 1591A - Life of a Flower Solution
///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include <iostream>
using namespace std;
int main()
{
int ts,sum,i,j,num;
cin>>ts;
while(ts--)
{
sum=1;
cin>>num;
int ar[1000],m=0;
for(i=0; i<num; i++)
{
cin>>ar[i];
}
sum=sum+ar[0];
for(i=1; i<num; i++)
{
if(ar[i-1]==0&&ar[i]==0)
{
cout<<"-1"<<endl;
m=1;
break;
}
else if(ar[i-1]>0&&ar[i]>0)
sum+=5;
else
sum+=ar[i];
}
if(m==0)
cout<<sum<<endl;
}
}
No comments