# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
527758 |
2022-02-18T08:08:00 Z |
KoD |
Autobahn (COI21_autobahn) |
C++17 |
|
115 ms |
7824 KB |
#include <bits/stdc++.h>
using std::vector;
using std::array;
using std::pair;
using std::tuple;
int lowb(const std::vector<int>& v, const int x) {
return std::lower_bound(v.begin(), v.end(), x) - v.begin();
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int N, K, X;
std::cin >> N >> K >> X;
vector<int> L(N), T(N), R(N), cx;
for (int i = 0; i < N; ++i) {
std::cin >> L[i] >> T[i] >> R[i];
R[i] += 1;
cx.push_back(L[i]);
cx.push_back(L[i] + T[i]);
cx.push_back(R[i]);
}
std::sort(cx.begin(), cx.end());
cx.erase(std::unique(cx.begin(), cx.end()), cx.end());
const int n = cx.size();
vector<int> exist(n), coeff(n);
for (int i = 0; i < N; ++i) {
exist[std::lower_bound(cx.begin(), cx.end(), L[i]) - cx.begin()] += 1;
exist[std::lower_bound(cx.begin(), cx.end(), R[i]) - cx.begin()] -= 1;
if (L[i] + T[i] < R[i]) {
coeff[std::lower_bound(cx.begin(), cx.end(), L[i] + T[i]) - cx.begin()] += 1;
coeff[std::lower_bound(cx.begin(), cx.end(), R[i]) - cx.begin()] -= 1;
}
}
for (int i = 1; i < n; ++i) {
exist[i] += exist[i - 1];
coeff[i] += coeff[i - 1];
}
for (int i = 0; i < n; ++i) {
if (exist[i] < K) {
coeff[i] = 0;
}
}
long long sum = 0, ans = 0;
for (int i = 0, j = 0; i < n; ++i) {
while (j + 1 < n and cx[j + 1] - cx[i] <= X) {
sum += (cx[j + 1] - cx[j]) * coeff[j];
j += 1;
}
ans = std::max(ans, sum + coeff[j] * (X - (cx[j] - cx[i])));
if (i == j) {
j += 1;
} else {
sum -= (cx[i + 1] - cx[i]) * coeff[i];
}
}
for (int i = n - 1, j = n - 1; i >= 0; --i) {
while (j > 0 and cx[i] - cx[j - 1] <= X) {
sum += (cx[j] - cx[j - 1]) * coeff[j - 1];
j -= 1;
}
ans = std::max(ans, sum + (j == 0 ? 0 : coeff[j - 1]) * (X - (cx[i] - cx[j])));
if (i == j) {
j -= 1;
} else {
sum -= (cx[i] - cx[i - 1]) * coeff[i - 1];
}
}
std::cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
296 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
312 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
296 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
312 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
1 ms |
300 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
296 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
312 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
1 ms |
300 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
109 ms |
7736 KB |
Output is correct |
22 |
Correct |
107 ms |
7768 KB |
Output is correct |
23 |
Correct |
115 ms |
7824 KB |
Output is correct |
24 |
Correct |
104 ms |
7772 KB |
Output is correct |
25 |
Incorrect |
108 ms |
7808 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |