# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
24923 | tlwpdus | 코알라 (JOI13_koala) | C11 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll tree[530000], d, a, n;
ll b[100100], t[100100];
int key = 262144;
void upd(int s, int e, ll val) {
s+=key;e+=key;
while(s<=e) {
if (s%2==1) tree[s] = max(tree[s],val);
if (e%2==0) tree[e] = max(tree[e],val);
s = (s+1)>>1; e = (e-1)>>1;
}
}
ll getv(int idx) {
ll maxi = -(1LL<<50);
idx+=key;
while(idx>0) {
maxi = max(maxi,tree[idx]);
idx>>=1;
}
return maxi;
}
vector<ll> comp;
void com(ll t[]) {
int i;
for (i=0;i<n;i++) {
comp.push_back(t[i]%d);
comp.push_back((t[i]+1)%d);
}
comp.push_back(d);
sort(comp.begin(),comp.end());
comp.erase(unique(comp.begin(),comp.end()),comp.end());
}
ll mokx(ll a, ll b) {
if (a>0) return (a-1)/b+1;
return a/b;
}
int loc(ll val) {
return lower_bound(comp.begin(),comp.end(),val)-comp.begin();
}
ll f[100100];
void solve() {
int i;
upd(loc(0),loc(0),0);
upd(loc(1),loc(d),-a);
for (i=1;i<n;i++) {
f[i] = getv(loc(t[i]%d))-(t[i]/d)*a+b[i];
upd(loc(0),loc(t[i]%d),-(mokx(-t[i],d)*a)+f[i]);
upd(loc((t[i]+1)%d),loc(d),-(mokx(d-t[i],d)*a)+f[i]);
}
printf("%lld\n",f[n-1]);
}
int main() {
ll kt, mt;
int i;
for (i=1;i<key*2;i++) tree[i] = -(1LL<<50);
scanf("%lld%lld%lld%lld%lld",&kt,&mt,&d,&a,&n);
t[0] = 0; t[n+1] = mt-kt;
for (i=1;i<=n;i++) {
scanf("%lld%lld",&t[i],&b[i]);
t[i]-=kt;
}
n+=2;
com(t);
solve();
return 0;
}