CSES - Aalto Competitive Programming 2024 - wk2 - Wed - Results
Submission details
Task:Binge watching
Sender:aalto2024b_010
Submission time:2024-09-11 17:00:58 +0300
Language:C++11
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.16 sdetails
#5ACCEPTED0.15 sdetails
#6ACCEPTED0.22 sdetails
#70.00 sdetails
#80.00 sdetails
#9ACCEPTED0.00 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:74:13: warning: unused variable 'startc' [-Wunused-variable]
   74 |         int startc = movies[v].first, endc = movies[v].second;
      |             ^~~~~~
input/code.cpp:75:39: warning: unused variable 'endn' [-Wunused-variable]
   75 |         int startn = movies[b].first, endn = movies[b].second;
      |                                       ^~~~
input/code.cpp:18:12: warning: unused variable 'm' [-Wunused-variable]
   18 |     int n, m, k;
      |            ^
input/code.cpp:18:15: warning: unused variable 'k' [-Wunused-variable]
   18 |     int n, m, k;
      |               ^
input/code.cpp:45:9: warning: unused variable 'currenti' [-Wunused-variable]
   45 |     int currenti = 0, nexti = 0;
      |         ^~~~~~~~
input/code.cpp:45:23: warning: unused variable 'nexti' [-Wunused-variable]
   45 |     int currenti = 0, nexti = 0;
      |                       ^~~~~

Code

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;





struct sort_pred {
    bool operator()(const std::pair<int,int> &left, const std::pair<int,int> &right) {
        return left.second < right.second;
    }
};

int main() {
    int n, m, k;
    cin >> n;

    vector<pair<int, int>> movies(n);
    vector< pair<int, int> > movie_lengths(n);

    for (int i = 0; i < n; ++i) {
        
        cin >> movies[i].first >> movies[i].second;
        movie_lengths[i].first = movies[i].second - movies[i].first;
        movie_lengths[i].second = i;
        
        }

    //sort(movies.begin(), movies.end());
    sort(movie_lengths.begin(), movie_lengths.end());


    sort(movies.begin(), movies.end(), sort_pred());

    //for (int i = 0; i < n; ++i) cout << '('  << movies[i].first << ' ' << movies[i].second << ')' << endl;
    

    //int k = 0;
    //while(k >)


    int currenti = 0, nexti = 0;
    int nmovies = 1;

    /*

    while (currenti < n and nexti < n) {
        int i =  movie_lengths[currenti].second;
        int j =  movie_lengths[nexti].second;


        int startc = movies[i].first, endc = movies[i].second;
        int startn = movies[j].first, endn = movies[j].second;

        //cout << "COMP " << startc << ' ' << endc << ") vs (" << startn << ' ' << endn << endl;

        if (endc <= startn) {
            ++nmovies;

        }



    }
 */
    int v = 0; int b = 0;

   

    for (int i = 0; i <= n; ++i) {
        int startc = movies[v].first, endc = movies[v].second;
        int startn = movies[b].first, endn = movies[b].second;

        //cout << "COMP " << startc << ' ' << endc << ") vs (" << startn << ' ' << endn << endl;



        if (endc <= startn) {
            ++nmovies;

            //++v;
            v = b;
            ++b;
            
        } else {
            ++b;
        }
    }

    cout << nmovies << endl;

}

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: ACCEPTED

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

correct output
4

user output
4

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: ACCEPTED

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

correct output
725

user output
725

Test 7

Verdict:

input
3
1 1000
2 3
5 6

correct output
2

user output
3

Test 8

Verdict:

input
3
3 4
5 6
7 8

correct output
3

user output
4

Test 9

Verdict: ACCEPTED

input
2
1 2
3 4

correct output
2

user output
2