#Competitive Programming Problem Check

119 messages · Page 1 of 1 (latest)

jolly egret
#

I got a problem, and a solution to this problem. And I want to check if it's correct

Problem K. Camera Fine
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes
Balloon color: Orange
Suleiman has just obtained his driver's license and wants to show everyone how fast his car can go. He drives his car to Airport Road and starts speeding. On his way back, notifications begin appearing on his phone: one fine after another. Fortunately, Suleiman's car records its speed at various locations along the road, and he also remembers the location of every speed camera and the speed limit associated with each one.
According to the law, Suleiman is only fined if his speed exceeds the camera's speed limit by more than 9 km/h. If he is fined by a camera, the amount he must pay for that specific camera is equal to the difference between his speed and the camera's speed limit.
Your task is to determine the number of times Suleiman is fined and the total amount he must pay.
Input

  • The first line contains two integers n and m (1 <= n, m <= 2 * 10^5): the number of recorded car logs and the number of cameras.
  • Each of the following n lines contains two integers pi and si (1 <= pi, si <= 10^9): the car's position on the road and Suleiman's speed at that position.
  • Each of the following m lines contains two integers ci and li (1 <= ci, li <= 10^9): the camera's location and its specific speed limit.
    Note: It is guaranteed that all pi values are distinct, all ci values are distinct, and every camera location ci appears within the recorded car positions.
    Output
    Print two integers: the number of times Suleiman was fined and the total amount of the fines.
    Examples
    Example 1
    Standard Input:
    3 2
    10 100
    20 80
    30 120
    10 80
    30 110
    Standard Output:
    2 30
    Example 2
    Standard Input:
    4 4
    1 30
    2 40
    3 50
    4 60
    1 10
    2 20
    3 30
    4 40
    Standard Output:
    4 80
    Example 3
    Standard Input:
    1 1
    7 19
    7 10
    Standard Output:
    0 0
blazing archBOT
#

This post has been reserved for your question.

Hey @jolly egret! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 720 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

jolly egret
#

Is it correct?

#

So the first link is just an optimized version

#

So the two versions are identical other than Big O and efficiency, right?

buoyant shoal
jolly egret
#

Yes

jolly egret
#

I reimplemented what I wrote in the competition

buoyant shoal
jolly egret
#

Yes. It matches all samples

#

All the outputs are correct

buoyant shoal
#

yes they should be equivalent from what I can see

jolly egret
#

So my solution is correct?

buoyant shoal
#

But I could imagine it not liking the line break

buoyant shoal
#

You are using System.out.println(amount + " " + total); to print your output

#

this adds a line break at the end

#

maybe it doesn't like that

jolly egret
#

Um, the judge is a real human

buoyant shoal
#

Does it tell you the example of where your program delivered a wrong answer?

jolly egret
#

So trailing lines and spaces are fine

jolly egret
#

It just says wrong answer

#

I just click on submit, and the judge reviews my code and has a lot of test cases

#

If it was an online judge, like it auto reviews inputs and outputs like LeetCode, it may be wrong yes, but it's not. A real human reviews it

jolly egret
#

So I want to appeal, maybe they rechange it and I become firdt

#

I am second currently

buoyant shoal
#

So there was a solution from you that was accepted?

jolly egret
buoyant shoal
#

I see

#

I thought you had another accepted solution for that problem

#

Maybe you can talk with other people who succeeded at that problem?

jolly egret
#

Yeah Yeah it was somewhat accepted, like logically it was correct. But TLE

jolly egret
#

And I don't have their contacts

buoyant shoal
jolly egret
buoyant shoal
#

Are you sure it's considered correct if the time limit was exceeded? Like if the time limit is exceeded and it's wrong, you would still get time limit exceeded I guess?

jolly egret
jolly egret
#

Of course it will TLE

#

I optimized the code to a Map lookup instead of nested loops

#

And it had the same results

#

Do you see any logical errors or anything that may be wrong?

buoyant shoal
#

I think the parsing is a bit weird when it doesn't match the expected input but you shouldn't need to work with invalid input ig

#

I don't see a logic error

jolly egret
#

Ughhhh I lost the 100% Scholarship because of a judge's problem? I appealed when I was there and he said it was wrong. But now I am sure it was right.

#

I got a 75% scholarship one. Okay thanks, I will call them tomorrow

blazing archBOT
jolly egret
buoyant shoal
jolly egret
#

I gave claude the problem statement and it literally solved the same exact way. Gemini and ChatGPT too said it was 100% correct

#

Okay have a great day/night!

zealous yarrow
#

Logic looks correct. Why are you using this FastReader instead of Scanner?

jolly egret
#

BufferedReader is way faster

buoyant shoal
#

I am not sure whether that makes that big of a difference here tbh

zealous yarrow
#

Then wrap the Scanner around a BufferedReader.

buoyant shoal
jolly egret
#

A scanner is way slower than BufferedReader. So I used FastReader

#

I used a scanner in the competition yes, but only when inputs are small

#

Like two integers or something

#

But when it starts going near 100k integers. I used FastReader

jolly egret
#

Just don't care about input taking, the problem is that they rejected it when it is right, which costed me the first place in the comp

zealous yarrow
#

I mean, No - Wrong Answer is a hell of a feedback...

buoyant shoal
jolly egret
#

I used to get Wrong Answer because of Integer Overflow, I changed to long and I started getting TLE instead, which means it became Correct but exceeded time limit, which I expected because I used nested loops for large inputs. I solved it and used a HashMap and it gets Wrong Answer. Although it's 100% correct

zealous yarrow
#

Yes, I think using a HashMap is the think they want to see there.

jolly egret
#

Yep. I used it

jolly egret
#

I gave claude the problem, it literally wrote what I wrote. Exactly the same thing

#

And Gave 5 other AIs, and all said it's correct

#

So I came here to check from a real human

#

You and Daniel both said it's correct

buoyant shoal
#

I think I said it looks correct, not it's definitely correct

jolly egret
#

Dude because they rejected this problem, I lost first place and got second 😭

zealous yarrow
#

Well maybe the first place just bribed more money.

jolly egret
#

🥹🥹🥹

#

Maybe

#

I had more experience too. They had 25 cheat sheets. Which is allowed, you have 25 sheets you can write whatever you want to use in the competition

#

I didn't have that. I didn't write anything

#

And I coded in NetBeans which may be the worst IDE for Java ever for me

#

No autocomplete no good syntax highlighting

#

Etc

#

So I got more potential and got wronged uh

zealous yarrow
#

Was this with time limit?

jolly egret
#

Like the answer got rejected with time limit?

#

No

#

It said Wrong Answer. Not TLE

zealous yarrow
#

No, I mean the whole contest

jolly egret
#

Oh yeah. The competition's time was 4 hours

#

Solved 7 problems, and this should be the eigth to get us to the first place. But it was rejected for some reason

jolly egret
zealous yarrow
#

Time limit for the task was written in the description, thx.

jolly egret
#

Yeah. Thought you didn't see it

#

There was a clarification button, that you can send messages to the judges to clarify something about a task. So I clarified that I am sure my code is correct and stuff. And he replied with No Response - Read Problem Statement then I clarified again, and he replied A judge will come to your table soon

#

And when he came, he hinted What is larger than an integer? I instantly realized that it was an overflow problem

#

I changed it to longs, and I started getting TLE. Which is expected

#

Changed it to the Map, the code that you saw. And it had a wrong answer. I told the judge to recheck, and he still said no, it's wrong

zealous yarrow
#

Do you still have the input file?

jolly egret
#

There is no input file

#

They just give you samples

jolly egret
#

And it's not a memory problem, Java can easily fit 200k Long entries in 256 MB

#

Those 200k entries may just be 20 MB. Which is nothing for the space we got

zealous yarrow
#

Sure, that shouldn't be a problem. 200,000*8*2=3,200,000, so 3MB. Enough room for the map overhead.

jolly egret
#

Oh thought it was 20 MB

#

Because of Map overhead

#

So there is no problem here, it should have been accepted

zealous yarrow
#

3MB is only for the raw numbers.