Can anyone Tell me what is wrong with my code . I am getting Wrong answer here.
ASHIGIFT:
#include<bits/stdc++.h>
using namespace std;
bool check(long long int n,long long int x[],long long int y[],long long int c[],long long int d[],long long int e[],long long int p,long long int b)
{
long long int prev = 0;
bool flag = true;
for (int i=0;i<p;i++)
{
long long int j;
for (j= prev;c[j]<=x[i] && j<b;j++)
{
if (n >= d[j])
n+=e[j];
}
prev = j;
if (n >= y[i])
n-=y[i];
else
{
flag = false;
break;
}
}
return flag;
}
long long int total(long long int ss,long long int se,long long int x[],long long int y[],long long int c[],long long int d[],long long int e[],long long int p,long long int b)
{
if (ss < se)
{
long long int mid = ss + (se - ss)/2;
if (check(mid,x,y,c,d,e,p,b))
total(ss,mid,x,y,c,d,e,p,b);
else
total(mid+1,se,x,y,c,d,e,p,b);
}
else if (ss == se)
{
if (check(ss,x,y,c,d,e,p,b))
return ss;
else
return
ss+1;
}
}
int main()
{
int t;
cin>>t;
while(t–)
{
long long int n,p,b,sum = 0;
cin>>n>>p;
long long int x[p],y[p];
for (int i=0;i<p;i++)
{
cin>>x[i]>>y[i];
sum+=y[i];
}
cin>>b;
long long int c[b],d[b],e[b];
for (long long int i=0;i<b;i++)
cin>>c[i]>>d[i]>>e[i];
cout<<total(1,sum,x,y,c,d,e,p,b)+1<<endl;
}
}