-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathalgorithm.cpp
More file actions
40 lines (32 loc) · 747 Bytes
/
algorithm.cpp
File metadata and controls
40 lines (32 loc) · 747 Bytes
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
#include <limits>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
void testcase() {
int n; std::cin >> n;
std::vector<std::pair<int, int>> b(n);
for (int i = 0; i < n; i++) {
int l, p; std::cin >> l >> p;
b[i] = std::make_pair(p, l);
}
std::sort(b.begin(), b.end());
int count = 1;
for (int i = 1, p = b[0].first; i < n;) {
int next = b[n - 1].first + b[n - 1].second;
for (; i < n && next > b[i].first; i++)
next = std::min(next, std::max(p + b[i].second, b[i].first));
p = next;
count++;
}
std::cout << count << std::endl;
}
int main() {
std::ios_base::sync_with_stdio(false);
int t;
std::cin >> t;
for (int i = 0; i < t; ++i)
testcase();
}