Submission details
Task:Binge watching
Sender:aalto25b_003
Submission time:2025-09-10 16:57:09 +0300
Language:C++ (C++17)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#30.00 sdetails
#4ACCEPTED0.08 sdetails
#5ACCEPTED0.05 sdetails
#60.10 sdetails
#7ACCEPTED0.00 sdetails
#8ACCEPTED0.00 sdetails
#9ACCEPTED0.00 sdetails

Compiler report

input/code.cpp: In function 'void solve()':
input/code.cpp:71:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     while(indexa < a.size() and indexb < b.size()) {
      |           ~~~~~~~^~~~~~~~~~
input/code.cpp:71:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     while(indexa < a.size() and indexb < b.size()) {
      |                                 ~~~~~~~^~~~~~~~~~

Code

/*
Maija is a freshly graduated infrastructure architect and has now been given her first job by the local government: to fix the traffic problems at junction 1337.
Before she can start planning any solutions, she needs to understand the nature of the problem. To do this, she starts to analyze the weekly traffic data.
From the records, she extracts the following information for n anonymous cars numbered 1, 2, \dots, n: Car number i enters the junction at some time during the interval [l_i, r_i]. Now, she is going to calculate the maximum possible number of cars trying to enter the junction all at once.
Input
The first line contains an integer n, which is the number of cars.
Each of the next n lines contains two integers, l_i and r_i.
Output
Output the maximum number of cars trying to enter the junction all at once.
Constraints

1 \leq n \leq 10^5
1 \leq l_i \leq r_i \leq 60 \times 60 \times 24 \times 7 = 604800

Example 1
Input:
3
1 4
4 5
4 6

Output:
3

Explanation: all three cars might arrive at the intersection at second 4.
Example 2
Input:
4
1 2
3 5
4 6
7 8

Output:
2

Explanation: both cars 2 and 3 might arrive at the intersection at seconds 4 orĀ 5.
Example 3
Input:
3
1 604800
54332 421232
32323 44444

Output:
2
------------------------------------------------------------------------------------------
*/

#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n; 
    cin >> n;
    vector<int> a;
    vector<int> b;
    
    while (n > 0) {
        n--;
        int l, r;
        cin >> l >> r;
        a.push_back(l);
        b.push_back(r);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    
    int res = 0;
    int indexa = 0, indexb = 0;
    while(indexa < a.size() and indexb < b.size()) {
        if (b[indexb] <= a[indexa]) {
            res++;
            indexb++;
        } else if (b[indexb] > a[indexa]) {
            indexa++;
        }
    }
    cout << res + 1;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    solve();

    return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
10
6 7
4 5
8 9
2 3
...

correct output
10

user output
10

Test 2

Verdict: ACCEPTED

input
10
1 1000
1 1000
1 1000
1 1000
...

correct output
1

user output
1

Test 3

Verdict:

input
10
404 882
690 974
201 255
800 933
...

correct output
4

user output
5

Test 4

Verdict: ACCEPTED

input
200000
177494 177495
157029 157030
6030 6031
15209 15210
...

correct output
200000

user output
200000

Test 5

Verdict: ACCEPTED

input
200000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
...

correct output
1

user output
1

Test 6

Verdict:

input
200000
82334756 323555178
958182284 981100325
649818003 678160906
801994655 889397498
...

correct output
725

user output
199993

Test 7

Verdict: ACCEPTED

input
3
1 1000
2 3
5 6

correct output
2

user output
2

Test 8

Verdict: ACCEPTED

input
3
3 4
5 6
7 8

correct output
3

user output
3

Test 9

Verdict: ACCEPTED

input
2
1 2
3 4

correct output
2

user output
2