CNOTE: Chef and Notebooks
Link for the problem: CNOTE
Solution:
Chef wants to write X pages long poetry and there are Y pages left in the current notebook. So he needs to buy a notebook at least X-Y pages long notebook. He has only K rubles left.
=> We will try to find a notebook having at least X-Y pages and price not greater than K.
i) if we get the notebook print "LuckyChef"
ii) else print "UnluckyChef"
Code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int x,y,k,n,l,i,f=0;
scanf("%d %d %d %d",&x,&y,&k,&n);
l=x-y;
for(i=0;i<n;i++)
{
int p,c;
scanf("%d %d",&c,&p);
if(p<=k&&c>=l&&f==0)
{
f=1;
printf("LuckyChef\n");
}
}
if(f==0)
printf("UnluckyChef\n");
}
return 0;
}
Link for the problem: CNOTE
Solution:
Chef wants to write X pages long poetry and there are Y pages left in the current notebook. So he needs to buy a notebook at least X-Y pages long notebook. He has only K rubles left.
=> We will try to find a notebook having at least X-Y pages and price not greater than K.
i) if we get the notebook print "LuckyChef"
ii) else print "UnluckyChef"
Code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int x,y,k,n,l,i,f=0;
scanf("%d %d %d %d",&x,&y,&k,&n);
l=x-y;
for(i=0;i<n;i++)
{
int p,c;
scanf("%d %d",&c,&p);
if(p<=k&&c>=l&&f==0)
{
f=1;
printf("LuckyChef\n");
}
}
if(f==0)
printf("UnluckyChef\n");
}
return 0;
}
No comments:
Post a Comment