# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
145315 |
2019-08-19T15:02:09 Z |
gs18103 |
코알라 (JOI13_koala) |
C++14 |
|
121 ms |
8176 KB |
#include <bits/stdc++.h>
#define LINF 1000000000000000000LL
using namespace std;
typedef long long ll;
ll t[101010];
ll tree[404040], b[101010], dp[101010];
vector <ll> num;
ll update(int node, int s, int e, int k, ll val) {
if(s == e) return tree[node] = max(tree[node], val);
int m = (s+e)>>1;
if(k <= m) tree[node] = max(tree[node*2+1], update(node*2, s, m, k, val));
else tree[node] = max(tree[node*2], update(node*2+1, m+1, e, k, val));
return tree[node];
}
ll cal(int node, int s, int e, int l, int r) {
if(s > r || e < l) return -LINF;
if(s >= l && e <= r) return tree[node];
int m = (s+e)>>1;
return max(cal(node*2, s, m, l, r), cal(node*2+1, m+1, e, l, r));
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
ll K, M, D, n;
ll A;
cin >> K >> M >> D >> A >> n;
M -= K;
for(int i = 1; i <= n; i++) {
cin >> t[i] >> b[i];
t[i] -= K;
num.push_back(t[i] % D);
}
num.push_back(M % D);
t[n+1] = M;
sort(num.begin(), num.end());
for(int i = 0; i < 404040; i++) tree[i] = -LINF;
update(1, 0, num.size()-1, 0, 0LL);
for(int i = 1; i <= n+1; i++) {
int k = lower_bound(num.begin(), num.end(), t[i] % D) - num.begin();
dp[i] = max(cal(1, 0, num.size()-1, 0, k-1) - A, cal(1, 0, num.size()-1, k, num.size()-1)) + b[i];
update(1, 0, num.size()-1, k, dp[i]);
}
cout << dp[n+1] - A * (M / D);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3576 KB |
Output is correct |
2 |
Correct |
6 ms |
3440 KB |
Output is correct |
3 |
Correct |
5 ms |
3576 KB |
Output is correct |
4 |
Correct |
5 ms |
3576 KB |
Output is correct |
5 |
Correct |
5 ms |
3576 KB |
Output is correct |
6 |
Correct |
5 ms |
3576 KB |
Output is correct |
7 |
Correct |
5 ms |
3576 KB |
Output is correct |
8 |
Correct |
5 ms |
3576 KB |
Output is correct |
9 |
Correct |
6 ms |
3556 KB |
Output is correct |
10 |
Correct |
6 ms |
3576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
7788 KB |
Output is correct |
2 |
Correct |
92 ms |
7404 KB |
Output is correct |
3 |
Correct |
35 ms |
6644 KB |
Output is correct |
4 |
Correct |
93 ms |
7792 KB |
Output is correct |
5 |
Correct |
51 ms |
6472 KB |
Output is correct |
6 |
Correct |
38 ms |
5364 KB |
Output is correct |
7 |
Incorrect |
43 ms |
7792 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
121 ms |
8176 KB |
Output is correct |
2 |
Correct |
117 ms |
7860 KB |
Output is correct |
3 |
Correct |
104 ms |
7788 KB |
Output is correct |
4 |
Correct |
96 ms |
7732 KB |
Output is correct |
5 |
Correct |
72 ms |
6776 KB |
Output is correct |
6 |
Correct |
54 ms |
5976 KB |
Output is correct |