# Help me in solving DIET problem

### My issue

this code is running correct for sample input on online compilers but giving wrong result on codechef compiler

### My code

``````#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main() {
int t;
cin>>t;
while(t--){
int n,k;
cin>>n>>k;
int arr[n];
int sum=0;
bool ans = true;
int index=-1;
for(int i=1;i<=n;i++){
cin.ignore();
cin>>arr[i];
arr[i]=arr[i]+sum;
// cout<<"arr["<<i<<"] = "<<arr[i]<<endl;
sum= arr[i]-k;
// cout<<"sum = "<<sum<<endl;
if(sum<0){
ans=false;
index=i;
break;
}
}
if(ans){
cout<<"YES"<<endl;
}
else cout<<"No "<<index<<endl;
}
return 0;
}

``````

Problem Link: DIET Problem - CodeChef

my code is not taking the third array as input. i dont know why

@shiwani_143 the logic is simple you just have to do what is told in the question and form conditions.

I have pasted my code below , you can use array instead of vectors.
hope this helps!!

include <bits/stdc++.h>
using namespace std;

int main() {
int t;
cin>>t;
while(t–)
{ int store=0,c=0;
int n,k;
cin>>n>>k;
vectorv;
for(int i=0;i<n;i++)
{
int a;
cin>>a;
v.push_back(a);
}
for(int i=0;i<n;i++)
{

``````        if(v[i]>=k)
{
c=1;

}
else
{
store=i+1;
c=0;
break;
}
v[i+1]+=v[i]-k;
}
if(c)
{
cout<<"YES"<<endl;
}
else
cout<<"NO"<<" "<<store<<endl;
}
return 0;
``````

}