-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbaidu2.cpp
52 lines (47 loc) · 910 Bytes
/
baidu2.cpp
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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct Duration
{
int cost;
int due;
Duration(int c, int d): cost(c), due(d) {}
};
bool CanBeComplete(vector<Duration>& works)
{
auto comp = [](const Duration& lhs, const Duration& rhs)
{
return lhs.due < rhs.due;
};
std::sort(works.begin(), works.end(), comp);
int cur_time = 0;
for (size_t i = 0; i != works.size(); ++i)
{
cur_time += works[i].cost;
if (cur_time > works[i].due) return false;
}
return true;
}
int main()
{
int num_group;
cin >> num_group;
while (num_group--)
{
int num_work;
cin >> num_work;
vector<Duration> works;
for (int c, d; num_work--;)
{
cin >> c >> d;
works.emplace_back(c, d);
}
// group io done
if (CanBeComplete(works))
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}