# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
372693 |
2021-03-01T10:02:01 Z |
phathnv |
코알라 (JOI13_koala) |
C++11 |
|
128 ms |
5100 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 1;
const ll INF = 1e18;
int k, m, d, a, n;
pair<int, int> t[N];
struct segTree{
int n, a;
vector <int> vals;
vector <ll> maxV;
segTree(const vector <int> &_vals, int _a){
n = _vals.size();
a = _a;
vals = _vals;
maxV.assign(n * 4 + 1, -INF);
}
void update(int id, int l, int r, int u, int v, ll val){
if (v < l || r < u)
return;
if (u <= l && r <= v){
maxV[id] = max(maxV[id], val);
return;
}
int mid = (l + r) >> 1;
update(id << 1, l, mid, u, v, val);
update(id << 1 | 1, mid + 1, r, u, v, val);
}
ll get(int id, int l, int r, int pos){
if (pos < l || r < pos)
return -INF;
ll res = maxV[id];
if (l == r)
return res;
int mid = (l + r) >> 1;
res = max(res, get(id << 1, l, mid, pos));
res = max(res, get(id << 1 | 1, mid + 1, r, pos));
return res;
}
void update(int rem, ll val){
int pos = lower_bound(vals.begin(), vals.end(), rem) - vals.begin() + 1;
update(1, 1, n, 1, pos, val);
update(1, 1, n, pos, n, val - a);
}
ll get(int rem){
int pos = lower_bound(vals.begin(), vals.end(), rem) - vals.begin() + 1;
return get(1, 1, n, pos);
}
};
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> k >> m >> d >> a >> n;
for(int i = 1; i <= n; i++)
cin >> t[i].first >> t[i].second;
m -= k;
for(int i = 1; i <= n; i++)
t[i].first -= k;
k = 0;
sort(t + 1, t + 1 + n);
vector <int> vals;
for(int i = 1; i <= n; i++)
vals.push_back(t[i].first % d);
vals.push_back(k % d);
vals.push_back(m % d);
sort(vals.begin(), vals.end());
vals.resize(unique(vals.begin(), vals.end()) - vals.begin());
segTree ST(vals, a);
ST.update(k % d, 0);
for(int i = 1; i <= n; i++){
int rem = t[i].first % d;
ll val = ST.get(rem) + t[i].second;
ST.update(rem, val);
}
ll ans = ST.get(m % d) - (ll) m / d * a;
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
1776 KB |
Output is correct |
2 |
Correct |
50 ms |
1776 KB |
Output is correct |
3 |
Correct |
21 ms |
1264 KB |
Output is correct |
4 |
Correct |
47 ms |
1776 KB |
Output is correct |
5 |
Correct |
27 ms |
1136 KB |
Output is correct |
6 |
Correct |
17 ms |
1004 KB |
Output is correct |
7 |
Correct |
25 ms |
1776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
124 ms |
3692 KB |
Output is correct |
2 |
Correct |
128 ms |
4972 KB |
Output is correct |
3 |
Correct |
117 ms |
5100 KB |
Output is correct |
4 |
Correct |
104 ms |
5100 KB |
Output is correct |
5 |
Correct |
75 ms |
3312 KB |
Output is correct |
6 |
Correct |
56 ms |
2416 KB |
Output is correct |