#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 101;
int n, k, m, a[N], b[N], t[N];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> k >> m;
for (int i = 0; i < m; ++i)
cin >> a[i] >> b[i] >> t[i];
int cur = 0, ans = 0;
for (int i = 0; i < m && a[i] <= k; ++i)
if (k - a[i] < t[i])
cur += b[i];
ans = max(ans, cur);
cur = 0;
for (int i = m - 1; i >= 0 && a[i] >= k; --i)
if (a[i] - k < t[i])
cur += b[i];
ans = max(ans, cur);
for (int i = 0; i < m && a[i] <= k; ++i) {
int tot = 2 * (k - a[i]);
cur = 0;
int j = i;
while (j < m && a[j] <= k) {
if (k - a[j] < t[j])
cur += b[j];
++j;
}
while (j < m) {
if (tot + a[j] - k < t[j])
cur += b[j];
++j;
}
ans = max(ans, cur);
}
for (int i = m - 1; i >= 0 && a[i] >= k; --i) {
int tot = 2 * (a[i] - k);
cur = 0;
int j = i;
while (j >= 0 && a[j] >= k) {
if (a[j] - k < t[j])
cur += b[j];
--j;
}
while (j >= 0) {
if (tot + k - a[j] < t[j])
cur += b[j];
--j;
}
ans = max(ans, cur);
}
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |