#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
#define pii pair<int, int>
#define fst first
#define snd second
using namespace std;
const int INF = 1e9 + 7;
int N, K, X;
int cur[2];
vector<int> C;
vector<pii> op;
int val[300005];
ll ret = 0;
int main()
{
ios :: sync_with_stdio(0); cin.tie(0);
cin >> N >> K >> X;
C.push_back(-INF); C.push_back(INF);
for (int i = 0; i < N; i++)
{
int L, t, R; cin >> L >> t >> R; L--;
C.push_back(L); C.push_back(R);
op.push_back({L, 1});
op.push_back({R, -1});
if (L + t < R)
{
C.push_back(L + t);
op.push_back({L + t, 2});
op.push_back({R, -2});
}
}
sort(C.begin(), C.end());
C.resize(unique(C.begin(), C.end()) - C.begin());
sort(op.begin(), op.end());
int j = 0;
for (int i = 0; i < C.size(); i++)
{
for (; j < op.size() && op[j].fst <= C[i]; j++)
{
if (op[j].snd < 0) {cur[-op[j].snd - 1]--;}
else {cur[op[j].snd - 1]++;}
}
if (cur[0] >= K) val[i] = cur[1];
//cerr << i << ": " << C[i] << " " << cur[0] << " " << cur[1] << "\n";
}
j = 0; ll tmp = 0;
for (int i = 1; i < C.size(); i++)
{
while (j < i - 1 && C[i] - C[j] > X)
{
ret = max(ret, (ll)(X - C[i - 1] + C[j]) * val[i - 1] + tmp);
tmp -= (ll)(C[j + 1] - C[j]) * val[j]; j++;
}
if (C[i] - C[i - 1] <= X) tmp += (ll)(C[i] - C[i - 1]) * val[i - 1];
else j++;
if (j) ret = max(ret, tmp + (ll)(X - C[i] + C[j]) * val[j - 1]);
else ret = max(ret, tmp);
}
cout << ret << "\n";
return 0;
}
Compilation message
autobahn.cpp: In function 'int main()':
autobahn.cpp:49:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for (int i = 0; i < C.size(); i++)
| ~~^~~~~~~~~~
autobahn.cpp:51:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for (; j < op.size() && op[j].fst <= C[i]; j++)
| ~~^~~~~~~~~~~
autobahn.cpp:61:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for (int i = 1; i < C.size(); i++)
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 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 |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 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 |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
114 ms |
7324 KB |
Output is correct |
22 |
Correct |
115 ms |
7320 KB |
Output is correct |
23 |
Correct |
124 ms |
7340 KB |
Output is correct |
24 |
Correct |
118 ms |
7312 KB |
Output is correct |
25 |
Correct |
123 ms |
7316 KB |
Output is correct |
26 |
Correct |
121 ms |
7304 KB |
Output is correct |
27 |
Correct |
110 ms |
7272 KB |
Output is correct |
28 |
Correct |
114 ms |
7324 KB |
Output is correct |
29 |
Correct |
122 ms |
7248 KB |
Output is correct |