-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathw5_p3.cpp
More file actions
74 lines (61 loc) · 1.33 KB
/
Copy pathw5_p3.cpp
File metadata and controls
74 lines (61 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <bits/stdc++.h>
using namespace std;
struct Potato
{
int start, end;
Potato(int s, int e)
{
start = s;
end = e;
}
bool operator<(const Potato &other) const
{
if (end == other.end)
return start < other.start;
return end < other.end;
}
};
int main()
{
cin.tie(nullptr), ios::sync_with_stdio(false);
int N;
cin >> N;
// vector<Potato> potatoes;
list<Potato> potatoes;
for (int i = 0; i < N; i++)
{
int start, end;
cin >> start >> end;
Potato p(start, end);
potatoes.push_back(p);
}
// sort(potatoes.begin(), potatoes.end());
potatoes.sort();
int today = 1;
int eat_count = 0;
int i = 0;
int temp = 0;
auto it = potatoes.begin();
while (!potatoes.empty())
{
int eat_limit = 3;
while (eat_limit > 0 && it != potatoes.end())
{
if (it->start <= today && it->end >= today)
{
eat_count++;
eat_limit--;
it = potatoes.erase(it);
}
else if (it->start < today)
{
it = potatoes.erase(it);
}
else
it++;
}
today++;
it = potatoes.begin();
}
cout << eat_count;
}