# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1055336 |
2024-08-12T17:37:17 Z |
juicy |
코알라 (JOI13_koala) |
C++17 |
|
47 ms |
4124 KB |
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 1e5 + 5;
const long long inf = 1e18;
int k, m, d, a, n;
int t[N], b[N];
long long ft[2][N], dp[N];
void upd(long long *s, int i, long long x) {
for (; i < N; i += i & -i) {
s[i] = max(s[i], x);
}
}
long long qry(long long *s, int i) {
long long res = -inf;
for (; i; i -= i & -i) {
res = max(res, s[i]);
}
return res;
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> k >> m >> d >> a >> n;
t[0] = k, t[n + 1] = m;
vector<int> comp = {k % d, m % d};
for (int i = 1; i <= n; ++i) {
cin >> t[i] >> b[i];
comp.push_back(t[i] % d);
}
sort(comp.begin(), comp.end());
comp.erase(unique(comp.begin(), comp.end()));
for (auto it : {0, 1}) {
fill(ft[it] + 1, ft[it] + N, -inf);
}
for (int i = 0; i <= n + 1; ++i) {
int p = lower_bound(comp.begin(), comp.end(), t[i] % d) - comp.begin() + 1;
if (i) {
dp[i] = max(qry(ft[0], p), qry(ft[1], N - p)) - (long long) (t[i] / d) * a + b[i];
}
upd(ft[0], p + 1, dp[i] + (long long) (t[i] / d - 1) * a);
upd(ft[1], N - p, dp[i] + (long long) (t[i] / d) * a);
}
cout << dp[n + 1];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
4124 KB |
Output is correct |
2 |
Correct |
21 ms |
4060 KB |
Output is correct |
3 |
Correct |
10 ms |
3584 KB |
Output is correct |
4 |
Correct |
21 ms |
4060 KB |
Output is correct |
5 |
Correct |
12 ms |
3500 KB |
Output is correct |
6 |
Correct |
9 ms |
3296 KB |
Output is correct |
7 |
Correct |
15 ms |
4068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
4060 KB |
Output is correct |
2 |
Correct |
29 ms |
4060 KB |
Output is correct |
3 |
Correct |
47 ms |
4052 KB |
Output is correct |
4 |
Correct |
22 ms |
4060 KB |
Output is correct |
5 |
Correct |
18 ms |
3500 KB |
Output is correct |
6 |
Correct |
14 ms |
3292 KB |
Output is correct |