Solutions are presented as using the least memory and the fastest execution time. It also takes the top
10 most recent solutions from each language. If you want to limit to a specific index, click the
"Solved" button and go to that problem.
Problems
A duck hunter is doing his favorite thing, hunting. He lives in a two dimensional world and is located at point (0, 0) . As he doesn't like walking for his prey, he prefers to shoot only vertically up (because in this case, the ducks fall straight into his hands). The hunter doesn't reload the gun immediately — r or more seconds must pass between the shots. When the hunter shoots up, the bullet immediately hits all the ducks who are directly above the hunter. In a two dimensional world each duck is a horizontal segment that moves horizontally in the negative direction of the Ox axis at the speed 1 length unit per second. For each duck we know the values h i and t i — the x -coordinates of its head (the left end of the segment) and its tail (the right end of the segment) at time 0 . The height where the duck is flying isn't important as the gun shoots vertically up to the infinite height and hits all the ducks on its way. What maximum number of ducks can the hunter shoot? The duck is considered shot by the hunter if at the moment of the shot at least one of its point intersects the Oy axis. After the hunter shoots the duck, it falls and it can't be shot anymore. The hunter cannot make shots before the moment of time 0. The first line of the input contains integers n , r ( 1 ≤ n ≤ 200 000 , 1 ≤ r ≤ 10 9 ) — the number of ducks and the minimum time in seconds between the shots. Then n lines follow, each of them contains two integers h i , t i ( - 10 9 ≤ h i < t i ≤ 10 9 ) — the x -coordinate of the head and tail of the i -th duck at the moment 0 . Print a single integer — the maximum number of ducks that can be shot by the hunter. In the first sample the hunter must shoot at time 0, this shot kills ducks 1 and 3. Then the hunter needs to reload the gun and shoot again at time 3. His second shot hits the tail of duck 2. In the second sample the hunter can make shots at times 0 and 6 to hit three ducks. |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|
13904378 |
130705009 |
B |
Oct. 27, 2015, 7:27 p.m. |
OK |
GNU C++ |
TESTS |
36 |
436 |
43110400 |
|
3200 |
|
10996302 |
surwdkgo |
B |
May 4, 2015, 1:31 p.m. |
OK |
GNU C++ |
TESTS |
36 |
436 |
43212800 |
|
3200 |
|
11353562 |
nikacimakuridze |
B |
May 30, 2015, 6:53 a.m. |
OK |
GNU C++ |
TESTS |
36 |
436 |
57344000 |
|
3200 |
|
18515768 |
yutaka1999 |
B |
June 16, 2016, 8:32 a.m. |
OK |
GNU C++ |
TESTS |
36 |
452 |
19968000 |
|
3200 |
|
11085489 |
daidailanlan |
B |
May 13, 2015, 5:34 a.m. |
OK |
GNU C++ |
TESTS |
36 |
467 |
57344000 |
|
3200 |
|
40986681 |
ReaLNero1 |
B |
July 30, 2018, 8:41 p.m. |
OK |
GNU C++ |
TESTS |
36 |
483 |
43110400 |
|
3200 |
|
15964689 |
arthur.nascimento |
B |
Feb. 11, 2016, 10:12 p.m. |
OK |
GNU C++ |
TESTS |
36 |
514 |
32563200 |
|
3200 |
|
11951203 |
liutianyi000 |
B |
July 6, 2015, 5:16 p.m. |
OK |
GNU C++ |
TESTS |
36 |
561 |
87040000 |
|
3200 |
|
26136838 |
Jin_Haonan |
B |
April 5, 2017, 6:40 a.m. |
OK |
GNU C++ |
TESTS |
36 |
639 |
45977600 |
|
3200 |
|
11018303 |
Lweb |
B |
May 7, 2015, 6:24 a.m. |
OK |
GNU C++ |
TESTS |
36 |
701 |
83968000 |
|
3200 |
|
11661990 |
ftiasch |
B |
June 19, 2015, 5:22 a.m. |
OK |
GNU C++11 |
TESTS |
36 |
327 |
6963200 |
|
3200 |
|
15028036 |
matthew99 |
B |
Dec. 26, 2015, 8 a.m. |
OK |
GNU C++11 |
TESTS |
36 |
452 |
181350400 |
|
3200 |
|
22406987 |
geniucos |
B |
Nov. 22, 2016, 4 p.m. |
OK |
GNU C++11 |
TESTS |
36 |
498 |
259686400 |
|
3200 |
|
11001269 |
krijgertje |
B |
May 4, 2015, 10:22 p.m. |
OK |
GNU C++11 |
TESTS |
36 |
514 |
242073600 |
|
3200 |
|
11261442 |
BSBandme |
B |
May 25, 2015, 7:02 a.m. |
OK |
GNU C++11 |
TESTS |
36 |
561 |
86630400 |
|
3200 |
|
57817798 |
py_ultron |
B |
July 26, 2019, 8:46 p.m. |
OK |
GNU C++11 |
TESTS |
36 |
624 |
113152000 |
|
3200 |
|
56823287 |
GREED_VI |
B |
July 11, 2019, 2:23 a.m. |
OK |
GNU C++11 |
TESTS |
36 |
655 |
198656000 |
|
3200 |
|
56823184 |
GREED_VI |
B |
July 11, 2019, 2:18 a.m. |
OK |
GNU C++11 |
TESTS |
36 |
655 |
198656000 |
|
3200 |
|
56823117 |
luogu_bot2 |
B |
July 11, 2019, 2:15 a.m. |
OK |
GNU C++11 |
TESTS |
36 |
655 |
198656000 |
|
3200 |
|
56823109 |
GREED_VI |
B |
July 11, 2019, 2:15 a.m. |
OK |
GNU C++11 |
TESTS |
36 |
655 |
198656000 |
|
3200 |
|
35138948 |
Dalgerok |
B |
Feb. 10, 2018, 10:41 p.m. |
OK |
GNU C++14 |
TESTS |
36 |
670 |
259993600 |
|
3200 |
|
69950155 |
gongsuidashen |
B |
Feb. 1, 2020, 8:43 a.m. |
OK |
GNU C++17 |
TESTS |
36 |
436 |
7168000 |
|
3200 |
|
52223173 |
jinjonik |
B |
April 2, 2019, 7:49 a.m. |
OK |
GNU C++17 |
TESTS |
36 |
701 |
113254400 |
|
3200 |
|
11001674 |
winger |
B |
May 5, 2015, 12:53 a.m. |
OK |
Java 8 |
TESTS |
36 |
1544 |
38604800 |
|
3200 |
|
11010200 |
mobinramezani |
B |
May 6, 2015, 5:18 a.m. |
OK |
Java 8 |
TESTS |
36 |
1590 |
38502400 |
|
3200 |
|
11262802 |
BackendDeveloper |
B |
May 25, 2015, 9:47 a.m. |
OK |
Java 8 |
TESTS |
36 |
1591 |
38604800 |
|
3200 |
|
11137330 |
Los_Angelos_Laycurse |
B |
May 18, 2015, 4:44 p.m. |
OK |
MS C++ |
TESTS |
36 |
935 |
16896000 |
|
3200 |
remove filters
Back to search problems