Task: | Binge watching |
Sender: | aalto2024b_002 |
Submission time: | 2024-09-11 16:32:19 +0300 |
Language: | C++ (C++20) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.00 s | details |
#3 | ACCEPTED | 0.00 s | details |
#4 | ACCEPTED | 0.15 s | details |
#5 | ACCEPTED | 0.14 s | details |
#6 | ACCEPTED | 0.20 s | details |
#7 | ACCEPTED | 0.00 s | details |
#8 | ACCEPTED | 0.00 s | details |
#9 | ACCEPTED | 0.00 s | details |
Compiler report
input/code.cpp: In function 'int main(int, char**)': input/code.cpp:74:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare] 74 | while (i < movies.size()) { | ~~^~~~~~~~~~~~~~~
Code
#include <algorithm> #include <iostream> #include <utility> #include <vector> using namespace std; template <typename T> std::ostream &operator<<(std::ostream &os, const vector<T> &obj) { bool first = true; for (const auto &o : obj) { if (first) { cout << o; first = false; } else { cout << ' ' << o; } } cout << endl; return os; } std::ostream &operator<<(std::ostream &os, const vector<pair<int, int>> &obj) { for (const auto &o : obj) { cout << o.first << ' ' << o.second << endl; } cout << endl; return os; } /** Maija has taken a day off from work and is going to binge watch as many movies as she can. She has listed out all the movies airing on TV today. Given the list, find the maximum number of movies she can watch from beginning to end. Input The first input line contains an integer n which is the number of movies. After this, there are n lines that describe the movies. Each line has two integers a and b which are the starting and ending times of a movie. Output Print one integer which is the maximum number of movies. Constraints 1 \le n \le 2 \cdot 10^5 1 \le a < b \le 10^9 Example Input: 3 3 5 4 9 5 8 Output: 2 */ vector<pair<int, int>> movies; int main(int argc, char **argv) { int n; cin >> n; movies = vector<pair<int, int>>(n); for (int i = 0; i < n; ++i) { cin >> movies[i].first; cin >> movies[i].second; } sort(movies.begin(), movies.end(), [](auto a, auto b) { return a.second < b.second; }); // cout << movies; int i = 0; int count = 0; int end_time = -1; while (i < movies.size()) { auto &m = movies[i]; if (m.first < end_time) { } else { end_time = m.second; count++; } i++; } cout << count << 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: 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 |