Two changes are required, use long long int instead of unsigned long long int and use return keyword in the edge case where r > m. This works:
#include<bits/stdc++.h>
using namespace std;
void solve(){
long long int x,r,m;
cin>>x>>r>>m;
r=r60;
m=m60;
if(r>m){
cout<<“NO”<<"\n";
return;
}
long long int reSec = r-x;
long long int avSec = m-x;
long long int maxSec = avSec/2;
if(maxSec >= reSec){
cout<<“YES”<<"\n";
return;
}
cout<<“NO”<<"\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t>0){
solve();
t–;
}
}
what is the answer for this?
why my code isnt getting accepted?
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
long long r,x,m;
cin>>x>>r>>m;
r*=60;
m*=60;
if(x>=m)
cout<<“YES”<<endl;
else if ( m<r)
cout<<“NO”<<endl;
else if(x+2*(r-x)<=m)
cout<<“YES”<<endl;
else
cout<<“NO”<<endl;
}
return 0;
}
its giving wa.
I think it should be “YES” as 1200 is enough to cover 600 seconds.
it shows WA although it pass all test cases
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
long long int t;
cin>>t;
while(t–)
{
long long int energy,require,allocated;
cin>>energy>>require>>allocated; // 60 3 4
require=60require; // 180
allocated=allocated60; // 240
if(energy>=require)
{
cout<<"YES"<<endl;
}
else
{
long long int firsttime = energy; //60
long long int remainingtime = require - energy; //(180- 60) = 120
long long int need= remainingtime*2; //240
long long int totaltime= firsttime+need; //60 + 240 = 300.
cout<<totaltime;
if(totaltime<=allocated)
cout << “YES\n”;
else cout << “NO\n”;
}
}
return 0;
}
//it shows WA although it pass all test cases
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
long long int t;
cin>>t;
while(t–)
{
long long int energy,require,allocated;
cin>>energy>>require>>allocated; // 60 3 4
require = 60; // 180
allocated=60; // 240
if(energy>=require)
{
cout<<"YES"<<endl;
}
else
{
long long int firsttime = energy; //60
long long int remainingtime = require - energy; //(180- 60) = 120
long long int need= remainingtime*2; //240
long long int totaltime= firsttime+need; //60 + 240 = 300.
//cout<<totaltime;
if(totaltime<=allocated)
cout << “YES\n”;
else cout << “NO\n”;
}
}
return 0;
}
youre right …this must be the code
#include
using namespace std;
int main(){
int t;
cin>>t;
long long int x,r,m;
while(t–){
cin>>x>>r>>m;
r*=60;
m*=60;
if(m<r){
cout<<“NO”<<endl;
continue;
}
else{
if(r<=x){
cout<<“YES”<<endl;
continue;
}
if(r>x&&m>x){
r=r-x;
m=m-x;
if(2*r<=m){
cout<<“YES”<<endl;
}
else{
cout<<“NO”<<endl;
}
}
else{
cout<<“NO”<<endl;
}
}
}
return 0;
}