HS08TEST - Editorial

X, Y = input(’’).split()
X = float(X)
Y = float(Y)
if X%5 == 0 and X + 0.5 < Y:
Y=Y - X - 0.50
else:
Y=Y

print(Y)
why is this not working?

#include

using namespace std;

int main()

{

int y,x;

cin>>x>>y;

if ( (x%5==0) && (x < (y+.50)))

cout << (y - x) - 0.50;

else

cout<<y;

return 0;

}

//----> what is wrong in this? why my memory limit is exceeding and it is showing approx15000kb?

You have to return value not print.

x,y=input().split()
y=float(y)
x=float(x)

if (x%5==0.00 and x>0 and y>=0 and x<=2000 and y<=2000):
if (float(x)<(y-0.50)):
print(f"{(y - float(x) - 0.50):.2f}",)
else:
print(f"{y:.2f}")
else:
print(f"{y:.2f}")

it shows error

you look new in competitive programming as you use printf. Its good think to add printf and make your code beautifull but its not needed in competitive programming though.

#include
using namespace std;

int main() {
// your code goes here

//variables
int X, Y; // X is need, Y is balance
float fee = 0.5; // bank fee
cin >> X >> Y; // reads and stores X and Y
float fx = X; // turns them into floats
float fy = Y;

if( X%5 == 0)//Checks if need is divisible by 5
{
    if( X < Y) // checks if X is less than balance
    {
        fy -= fx;
        fy -= fee;
        printf("%.2f", fy); // prints new balance
    }
    else // if x is greater prints old balance
    {
        printf( "%.2f", fy); 
    }
    
}
else // if x is not divisible by 5, prints out old balance
{
    printf( "%.2f", fy);  
}

return 0;

}

(This solution was longer than all the ones i saw but it worked well for me, when i kept custom inputs it always worked but once i submitted it it always marked it as wrong. It executes in under 1 second and uses 15.232 kb)

Why take the inputs into Integers when it is mentioned that Y will be a Number?

It should have been if(X + fee <= Y) instead.

#include
using namespace std;

int main() {
int x, tot;
float bal;
cin>>x>>tot;

if (x  <= tot- 0.5 )
{
    if (x%5==0)
    bal= tot- x - 0.5;
   
}

else 
{
  bal= tot;
  
}
cout<<"\n"<<bal;

}

Program is showing correct output as given but while submission, it is showing wrong…
Why??

You should at least read the previous comments before blindly posting your code and asking for help.

1 Like

/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
float b=0.0f;
int w=0;
Scanner sc=new Scanner(System.in);
w=sc.nextInt();
b=sc.nextFloat();
if(w>b)
System.out.printf("%.2f",b);
else if(w%5==0)
System.out.printf("%.2f",b-w-0.5);
else
System.out.printf("%.2f",b);
}
}

Could anyone tell me what should I change to make it correct. There are compilation errors but on submitting it, I get a WRONG ANSWER.

Please someone help me out!!

#include
#include <stdio.h>
using namespace std;

int main() {
// your code goes here
int x;
float y;
scanf("%d", &x);
scanf("%f", &y);
if(x>0 && x<=2000 && y>=0 && y<=2000 && x%5==0)
{
if(x>y)
{
printf("%0.2f", y);
}
else if(y>=x)
{
printf("%0.2f", (y-x-0.50));
}
}
else
{
printf("%0.2f", y);
}
return 0;
}

Can someone please tell me what is wrong with this episode?
Thank you in advance!!

have a look at your inner if where you’ve mentioned x>y
don’t forget about bank charges as well… so your condition should be

if(x % 5 == 0 && y >= x+0.5)

just this one if would work

/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int x =sc.nextInt();
double f = sc.nextDouble();

	if((0<=x && x <=2000) && (0<=f && f<=2000) && x<(f-0.50) && x%5==0) {
		System.out.printf("%.2f",f-x-0.50);
	}
	else {
		System.out.printf("%.2f",f);
	}

}
}

whats wrong here??

#include <stdio.h>

int main(void) {
// your code goes here
int X;float Y;
scanf("%u",&X);
scanf("%f",&Y);
if(0<Y<=2000){
if((X%5==0)&&(Y>=(X+0.50))){
Y=Y-(X+0.5);
printf("%.2f",Y);
}
else{
printf("%.2f",Y);
}
}
return 0;
}

here is the correct answer

#include <stdio.h>

int main(void) {
int x;
float y;
scanf("%d %f",&x,&y);
if(x%5==0 && (y>(x+0.50)))
y=y-x-0.50;
printf("%0.2f",y);
}

can anyone help me where i’m going wrong.??

its y>=(x+0.50)
and take format specifier for x as %u so that it takes only positive integers

#include <stdio.h>

int main(void) {

int x;

float z,y,m;

scanf("%d",&x);// withdraw

scanf("%f",&y);// available

z=x%5;

if(0<x<=2000 && 0<y<=2000 && y>x && z == 0)

{

    m=(y-x)-.50;

    printf("%f",m);

}

else if(z!=0)

{

    printf("%f",y);

}

else if (x<y)

{

    printf("%f",y);

}

return 0;

} showing wrong

[KOTLIN]

import java.util.*

val charge: Float = 0.50f

fun main(args: Array) {
val reader = Scanner(System.in)
var input: Int = reader.nextInt()
var balance: Float = reader.nextFloat()

if (isWithdrawCorrect(input) && isBalanceCorrect(balance) && isAccountBalanced(input, balance) && isMultipleOfFive(input)){
    println("%.2f".format(balance - input - charge))
} else {
    println("%.2f".format(balance))
}

}

fun isAccountBalanced(input: Int,input1: Float): Boolean = (input1 - input - charge) > 0

fun isMultipleOfFive(input: Int): Boolean = (input % 5 == 0)

fun isWithdrawCorrect(withdraw: Int): Boolean = 0 < withdraw && withdraw <= 2000

fun isBalanceCorrect(balance: Float): Boolean = 0 <= balance && balance <= 2000

i dont get it. examples are working fine.

nvm… isAccountBalanced was broken. it needed to be >= 0 not > 0 :smiley:

What is wrong with the code? It gives the correct output with sample cases but upon submission it shows wrong answer.

a,b = map(float, input().split())
if (a+0.5<=b):
if(a%5==0):
print("{:.2f}".format(b-a-0.50))
else:
print("{:.2f}".format(b))
else:
print("{:.2f}".format(b))