# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
808705 |
2023-08-05T09:40:13 Z |
vjudge1 |
코알라 (JOI13_koala) |
C++17 |
|
114 ms |
3512 KB |
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pill pair<int,ll>
#define mem(a, b) memset(a, b, sizeof(a))
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define name "test"
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
template <typename T1, typename T2> bool maxi(T1 &a, T2 b){if (a < b){a = b; return 1;} return 0;}
template <typename T1, typename T2> bool mini(T1 &a, T2 b){if (a > b){a = b; return 1;} return 0;}
struct SEGTREE{
ll val[N << 2];
SEGTREE(){};
void update(int id, int l, int r, int i, ll x){
if (l > i || r < i) return;
if (l == r) return void(val[id] = x);
int m = (l + r) >> 1;
if (m >= i) update(id << 1, l, m, i, x);
else update(id << 1 | 1, m + 1, r, i, x);
val[id] = max(val[id << 1], val[id << 1 | 1]);
}
ll get(int id, int l, int r, int u, int v){
if (l > v || r < u) return -oo;
if (l >= u && r <= v) return val[id];
int m = (l + r) >> 1;
return max(get(id << 1, l, m, u, v), get(id << 1 | 1, m + 1, r, u, v));
}
} ST;
int s, t;
int limDis, downPower, n;
int b[N];
pii a[N];
void input(){
cin >> s >> t >> limDis >> downPower >> n;
for (int i = 1; i <= n; i++)
cin >> a[i].fi >> a[i].se;
}
void prepare(){
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++)
b[i] = a[i].fi;
}
int update(ll &res, int i, int j){
int id = lower_bound(b, b + n + 1, b[i] - j * limDis) - b;
ll tmp = ST.get(1, 0, n, id, i - 1) - downPower * j;
maxi(res, tmp + a[i].se);
return id - 1;
}
void solveUp(){
prepare();
int pre_place = s;
b[0] = s;
for (int i = 1; i <= n; i++){
int k = (b[i] - pre_place) / limDis + ((b[i] - pre_place) % limDis > 0);
ll res = -oo;
int id = update(res, i, k);
if (id >= 0){
k = (b[i] - b[id]) / limDis + ((b[i] - b[id]) % limDis > 0);
update(res, i, k);
}
ST.update(1, 0, n, i, res);
pre_place = b[i];
}
int k = (t - pre_place) / limDis + ((t - pre_place) % limDis > 0);
ll ans = -oo;
for (int j = k; j <= k + 1; j++){
int id = lower_bound(b, b + n + 1, t - j * limDis) - b;
ll tmp = ST.get(1, 0, n, id, n) - j * downPower;
maxi(ans, tmp);
}
cout << ans;
}
int main(){
// load();
input();
solveUp();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
92 ms |
3512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
114 ms |
3444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |