SER15
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
//a*(a+1)/2
ll N;
cin>>N;
int a=0;
int val=2,n=2;
if(val>n/2)
{
}
vector <ll> A;
for(int i=0;a<=N;i++)
{
a = (i*(i+1))/2;
A.push_back(a);
}
/* for(auto i = A.begin();i!=A.end();i++)
{
cout<<*i<<" ";
}*/
ll l = A.size();
bool t ;
for(int i=0;i<l;i++)
{
for(int j=0;j<l;j++)
{
if(N==A[i]+A[j])
{
t= true;
break;
} else{
t = false;
}
}
if(t==true)
{
break;
}
}
if(t)
{cout<<"YES"<<endl;
}
else
{cout<<"NO"<<endl;
}
return 0;
}
need code for this Q18
ReplyDelete.
.
Given a Binary Tree as pre-order traversal input which has both positive and negative nodes, the task is to find maximum sum level in it.Using level order traversal of tree and queue data structure,solve the problem.For example , A binary tree with pre-order traversal as {4,2,-1,3,6,5,7}:
4
/ \
2 6
/ \ /\
-1 3 5 7
Sum of all nodes of 0th level is 4
Sum of all nodes of 1th level is 8
Sum of all nodes of 2nd level is 14
Hence maximum sum is 14
Mandatory declarations are "struct node *Right;", "struct node *Left;"
INPUT:
The first line of input is the number of nodes in tree N and then followed by the nodes as in pre-order traversal.
OUTPUT:
The output should be the maximum level sum of the tree.