-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathkickstartroundh-solution3.cpp
More file actions
70 lines (66 loc) · 1.33 KB
/
kickstartroundh-solution3.cpp
File metadata and controls
70 lines (66 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
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
using namespace std;
typedef long long ll;
#ifdef iq
mt19937 rnd(228);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif
int main() {
#ifdef iq
freopen("a.in", "r", stdin);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
auto solve = [&] () {
int n, k;
cin >> n >> k;
vector <pair <int, int> > e;
for (int i = 0; i < n; i++) {
int l, r;
cin >> l >> r;
e.push_back({l, r});
}
sort(e.begin(), e.end());
int last = 0;
int ans = 0;
for (int i = 0; i < n; i++) {
e[i].first = max(e[i].first, last);
if (e[i].first < e[i].second) {
int ret = (e[i].second - e[i].first + k - 1) / k;
ans += ret;
last = e[i].first + ret * k;
}
}
cout << ans;
};
for (int tc = 1; tc <= t; tc++) {
cout << "Case #" << tc << ": ";
solve();
cout << '\n';
}
}