utkarshh14
BAN USER
Comments (2)
Reputation 10
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
1
of 1 vote
#include<iostream>
using namespace std;
int main(){
int t;
cin>>t;
while(t){
int n;
cin>>n;
int arr[n+1];
for(int i=1;i<=n;i++)
cin>>arr[i];
int dp[1005][1005];
int dp1[1005][1005];
for(int i=0;i<=1000;i++){
for(int j=0;j<=1000;j++)
dp[i][j]=0;
}
dp[0][0]=1;
for(int i=1;i<=n;i++){
for(int j=0;j<=1000;j++){
for(int k=0;k<=1000;k++){
if(j>=arr[i]){
if(dp[jarr[i]][k]){
dp1[j][k]=1;
}
}
if(k>=arr[i]){
if(dp[j][karr[i]]){
dp1[j][k]=1;
}
}
if(dp[j][k]){
dp1[j][k]=1;
}
}
}
for(int j=0;j<=1000;j++){
for(int k=0;k<=1000;k++){
dp[j][k]=dp1[j][k];
dp1[j][k]=0;
}
}
}
int ans=0;
for(int i=1;i<=1000;i++){
if(dp[i][i]){
ans=i;
}
}
cout<<ans<<endl;
}
}

utkarshh14
July 24, 2019 Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Take a look at this code.
 utkarshh14 July 24, 2019It works perfect