I don’t know much about python. But try this
1
2
5 5
I have made some changes in the code now it is working
https://www.codechef.com/viewsolution/34502629
One point : you do not need to check constraints. Input itself will be according to what is given in the question.
> def a():
> chefmoney=0
> icream=5
> t=input()
> l=input()
> l2=l.strip().split()
> l1=list(map(int,l2))
> for i in l1:
> if(i==icream) and (chefmoney==0):
> chefmoney=chefmoney+icream
> if(i>icream) and ((i-icream)>chefmoney):
> return "NO"
> if(i>icream) and ((i-icream==chefmoney)):
> return "YES"
> n=int(input())
> for i in range(n):
> x=a()
> print(x)
>
> it shows EOFError on line n=int(input())
>
> can i know why
if the change required is 10 can we give that as 2 5 rupee coins
yeah
What’s wrong in this?
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t–){
int n,ar[n];
cin>>n;
for(int i=1;i<=n;i++){
cin>>ar[i];
}
int dp[n+1],flag=0;
dp[0]=0;
for(int i=1;i<=n;i++){
if(ar[i]==5)
dp[i]=dp[i-1]+1;
if(ar[i]==10)
dp[i]=(dp[i-1]>=1)?dp[i-1]-1:flag++;
if(ar[i]==15)
dp[i]=(dp[i-1]>=2)?dp[i-1]-2:flag++;
}
if(flag==0)
cout<<“YES”<<endl;
else
cout<<“NO”<<endl;
}
return 0;
}
Can you please check what’s wrong in this code? I get the correct outputs during custom run but it shows runtime error
https://www.codechef.com/viewsolution/34532525
This error is caused due to invalid memory reference in line 7
i.e. without taking input n you declared
int ar[n];
I have corrected the code
see this: CodeChef: Practical coding for everyone
Thank you so much
@sebastian @anon40522502 can you tell what is wrong in this code
it is giving wrong answer for both subtasks
solution link: [CodeChef: Practical coding for everyone]
I have already explained in this conversation that breaking loop without taking all necessary input will result in WA.
In my code, I have made a loop for taking pseudo input
see my code (the second loop)
https://www.codechef.com/viewsolution/33699739
@towncoder_ps
i have tried the same logic, but it’s not working for any subtask. Here is my logic
answer =0
for each user_coin {
returns = user_coin - 5;
if returns == 5
if (5Coins > 0)
5Coins–;
10Coins++;
else
answer = 1;
break;
else if returns == 10
if (10Coins > 0)
10Coins–;
else if ( 5Coins >= 2)
5Coins-=2;
else
answer = 1;
break;
else
5Coins++;
}
if answer == 1
print NO
else
print YES
below is my submission
https://www.codechef.com/viewsolution/34548043
Can any one please suggest which test case am i missing ? it would be great help
Thanks
see this:
https://www.codechef.com/viewsolution/34550996
if you still have any doubt then ask.
#include
using namespace std;
int main() {
int t;
cin>> t ;
while(t–){
int x ;
cin >> x ;
int arr[3]={0}, cash[x]={0},reply=1;
for(int i=0; i<x ; i++){
cin >> cash[i];
if(cash[i]==5){
arr[0]++;
}
if (cash[i]==10){
if(arr[0]>0){
arr[0]–;
arr[1]++;
}
else{
reply = -1;
break;
}
}
if(cash[i]==15){
if(arr[1]>0){
arr[1]–;
arr[2]++;
}
else if(arr[0]>1){
arr[0]=arr[0]-2;
arr[2]++;
}
else {
reply = -1;
break;
}
}
}
if (reply==1)
cout << “YES\n”;
else
cout << “NO\n”;
}
// your code goes here
return 0;
}
What is wrong in this code? Pls someone help meto find the problem
@anon40522502 thanks for your reply, i thought i am flushing so i don’t need to read remaining data. Any way thank you so much for your help
import java.util.;
import java.lang.;
import java.io.*;
class Codechef {
public static boolean chefIcecream(int[] arr){
int count = 0;
for(int i = 0; i < arr.length; i++){
if(arr[i] == 5){
count += 5;
}else{
if(count + 5 >= arr[i]){
count = count + 5 - arr[i];
}else{
return false;
}
}
}
return true;
}
public static void main (String[] args)
{
Scanner scn = new Scanner(System.in);
int t = scn.nextInt();
while(t-->0){
int n = scn.nextInt();
int arr[] = new int[n];
for(int i = 0; i < n; i++){
arr[i] = scn.nextInt();
}
System.out.println(chefIcecream(arr) ? "YES" : "NO");
}
}
}
what’s wrong in this
It is running absolutely fine for all custom input but shows NZEC error for default
#include <stdio.h>
int main() {
int t;
scanf("%d",&t);
while(t–){
int n;
scanf("%d",&n);
int ar[n];
for(int i=1;i<=n;i++){
scanf("%d",&ar[i]);
}
int count5=0,count10=0,flag=0;
for(int i=1;i<=n;i++){
if(ar[i]==5){
count5++;
}
if(ar[i]==10){
count10++;
if(count5>=1)
count5–;
else flag++;
}
if(ar[i]==15){
if(count10>=1)
count10–;
else if(count5>=2)
count5=count5-2;
else
flag++;
}
}
if(flag==0)
printf(“yes”);
else
printf(“no”);
}
return 0;
}
i am getting wrong answer in C in both the cases. pls help
@vinaychaurasia, for below test case your program is returning “NO” but it should be “YES”
1
5
5 5 10 10 15