video explanation>>>
#include <iostream>
#include<string>
#include<cmath>
#include<bits/stdc++.h>
#define ll long long
#define PI 3.14
#define pb push_back
#define pob pop_back
#define sv(a) sort(a.begin(),a.end())//sorting for vector//
#define sa(a,n) sort(a,a+n)//sorting for array//
#define MOD 1000000007
#define fi first
#define se second
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t,n;
cin>>t;
while(t--)
{
cin>>n;
int v[n];
int change;
for(int i=0;i<n;i++)cin>>v[i];
int coins[3]={0};
for(int i=0;i<n;i++)
{
change=v[i]-5;
if(change==0 )
{
coins[0]++;
}
else if(change==5 )
{
coins[1]++;
if(coins[0]*5>=change)
{
coins[0]--;
}
else
{
cout<<"NO"<<endl;
coins[1]--;
break;
}
}
else if(change==10)
{
coins[2]++;
if(coins[1]*10>=change )
{
coins[1]--;
}
else
{
cout<<"NO"<<endl;
coins[2]--;
break;
}
}
}
int d=coins[0]*5+coins[1]*10+coins[2]*15;
if(d==(n*5))
{
cout<<"YES"<<endl;
}
}
return 0;
}
``` this is partially correct and my seocnd constraint goes wrong but how?pls help whats wrong?
t = int(input())
for i in range(t):
n = int(input())
l = [int(i) for i in input().split()][:n]
five_count = 0
ten_count = 0
result = True
for j in range(n):
if l[j] == 5:
five_count += 1
elif l[j] == 10:
ten_count += 1
if five_count > 0:
five_count -= 1
else:
result = False
else:
if five_count >= 2:
five_count -= 2
elif ten_count > 0:
ten_count -= 1
else:
result = False
if not result:
print("NO")
else:
print("YES")
Can anyone help what is wrong in this code? Subtask 2 is not working correctly.
Solution: CodeChef: Practical coding for everyone
You can see this
Code
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define lld long long int
int main() {
// your code goes here
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lld t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
cin>>arr[i];
int i,cnt5=0,cnt10=0;
for(i=0;i<n;i++)
{
if(arr[i]==5)
cnt5++;
if(arr[i]==10)
{
if(cnt5>0)
{
cnt10++;
cnt5--;
}
else
break;
}
if(arr[i]==15)
{
if(cnt10>0)
cnt10--;
else if(cnt5>1)
cnt5-=2;
else
break;
}
}
if(i==n)
cout<<"YES\n";
else
cout<<"NO\n";
}
}
If you didn’t understood then ask. You are not considering the case when you can give 2 five coins when user gives 15.
Why is my subtask 2 wrong? I have considered the case of two five-rupee coins when buyer givers Rs 15. Please help me out
At least send submission link.
I think you should first take condition of giving single coin of 10 in case of 15.
Okay let me try.
correct answer now! Oh yes! i should save more of 5 as it is flexible. Thank you so much for helping me out!
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
long int n;
cin>>n;
long int arr[3]={0},temp,cash[n]={0},flag=1;
for(long int i=0;i<n;i++)
{
cin>>cash[i];
if(cash[i]==5)
{
arr[0]++;
}
if(cash[i]==10)
{
if(arr[0]>0)
{
arr[0]–;
arr[1]++;
}
else
{
flag=-1;
break;
}
}
else if(cash[i]==15)
{
if(arr[1]>0)
{
arr[1]–;
arr[2]++;
}
else if(arr[0]>=2)
{
arr[0]=arr[0]-2;
arr[2]++;
}
else
{
flag=-1;
break;
}
}
}
if(flag==1)
{
cout<<"YES\n";
}
else
{
cout<<"NO\n";
}
}
}
Can someone help me to find why i am getting wrong answer ?
why we taking rs 10 variable extra if we can pay rs 15 exchange from total or from rs 5??
there are two mistakes:
first, the decrement operator should be like - - instead of -
second, your code does not takes all necessary inputs i.e. breaking loop without taking all inputs
I had the same problem so I made a loop for taking pseudo input
see this : CodeChef: Practical coding for everyone
although your logic is correct
see the second loop
https://www.codechef.com/viewsolution/34086655
my first subtask is giving wrong answer while second runs just fine.
what did i do wrong. please help.
@sebastian @anon40522502
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
