Skip to content

Commit

Permalink
Must Do
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashish-kumar7 committed Mar 8, 2020
1 parent 61ba81f commit e5e959a
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions DP/Stickler Theif.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
//code
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int A[n];
for(int i=0;i<n;i++){
cin>>A[i];
}
int sum1=A[0];
int sum2=0;

int result;
for(int i=1;i<n;i++){
if(sum1<sum2){
result=sum2;
}
else{
result=sum1;
}
sum1=sum2+A[i];
sum2=result;
}

cout<<max(sum1,sum2)<<endl;
}
return 0;
}

0 comments on commit e5e959a

Please sign in to comment.