First he got 5 rupee coin. On second purchase when customer gave him a 10 rupee coin he returned the 5 rupee coin and thus left with a 10 rupee coin. For third purchase customer again gave him a 10 rupee this time he has not left with a 5 rupee coin so this transaction is not possible.
So keep the count of coins of 5 and 10.
And handle the case of 15 rupee coin carefully.
Ok… I thought that 5 10 and 15 are in denominations. I didn’t think them as whole coin.
Ok Thank you for clarifying this.
Now I have design another solution.
Thank you so much.
There are a few things to fix in your code.
First, your first two import statements don’t have the *.
Second, you don’t need to test for whether or not T is between 0 and 100. All that the problem means is that they will not give any inputs out of those restraints.
Third, you can get rid of num15, as it isn’t used, as well as the array. You only need each input once so there’s no need to store them in an array.
Fourth is that in this part of your code:
else if(a[i]==15) {
if(num10>0) {
num15++;
num10--;
}else if(num5>1) {
num15++;
num5=num5-10;
}else {System.out.println("NO");
break;}
}
You’re doing num5=num5-10 for some reason. I think you meant num5-=2, or num5 = num5-2.
That should help you. You’re code’s also only printing out two answers, but I think that’s a problem with my IDE.
Also, just a side note, for faster I/O, use BufferedReader br = new BufferedReader(new InputStreamReader(System.in));, and StringTokenizer st = new StringTokenizer(br.readLine()); instead of the Scanner.
Yup, got your point, that was my first code so got bit confused clear now. Thankx buddy
https://www.codechef.com/viewsolution/34907488
Please provide guidance . The code works as per the constraints of the question , but still gives , total score = 0% . Why ?
@rajarshi_basu some one provide some guidance . This is second reply . How much to wait .
why do author questions when you cannot provide support ?
https://www.codechef.com/viewsolution/34907488
Please provide guidance . The code works as per the constraints of the question , but still gives , total score = 0% . Why ?
After each test case value of five, ten and flag should be initialized 0.
please send me the link to your codechef submission which gives WA.
I have Written the same code in java but it is not getting accepted. Can anyone tell me what’s the problem there.
import java.util.Scanner;
public class ChefAndStrings {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
for (int i = 0; i < t; i++) {
int n = s.nextInt();
int[] arr = new int[n];
int c5=0,c10=0;
boolean result=true;
for (int j = 0; j < n; j++) {
int coin = s.nextInt();
if(coin==5) {
c5+=1;
}
else if(coin==10) {
if(c5>0) {
c5--;
c10++;
}
else {
result=false;
break;
}
}
else if(coin==15) {
if(c10>0) {
c10--;
}
else if(c5>=2) {
c5-=2;
}
else {
result=false;
break;
}
}
}
if(result)
System.out.println("YES");
else
System.out.println("NO");
}
}
}
Oh, I see, means I have to store the complete line of input in an array.
Thanks, man.
Now my submission get accepted.
Why my code is showing NZEC error that too for line 1??? I’m new to codechef please help me out…what I’m suppose to do???why is this happening even though my code gives proper outputs???
CodeChef: Practical coding for everyone
Read the question again and see what you have to print. Also, never break without taking whole input
I don’t know much about python, but there is some issue in taking input. Also, when you have found f=0 then break the loop
Your AC code CodeChef: Practical coding for everyone
There were 2 problems. First you need to see if 10 rupee coin is available then you have to give it. Second there was input of array in single line. You can not use int(input())
Okay…Thank so much you : ) I’ll implement the changes …
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl “\n”
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin>>t;
while(t--)
{
ll n,x,c5=0,c10=0,flag=1;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>x;
if(x==5)
c5++;
else if(x==10 && c5>=1)
c10++,c5--;
else if(x==15 && (c5>=2 || c10>=1 ))
if(c10>=1)
c10--;
else
c5-=2;
}
if(flag)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
Can anyone tell me what wrong in this?