# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
27481 | suhgyuho_william | Long Distance Coach (JOI17_coach) | C++14 | 0 ms | 6904 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define lld long long
#define pii pair<int,int>
#define pll pair<lld,lld>
#define pb push_back
#define next nextt
#define Inf 1000000000
#define Linf 1000000000000000000LL
#define Mod 1000000007
using namespace std;
int N,M;
lld X,W,T,ans;
lld a[200002];
struct data{
lld d,c;
}b[200002];
bool check[200002];
lld get(lld x){
return ((X-x)/T+1)*W;
}
int main(){
scanf("%lld %d %d %lld %lld",&X,&N,&M,&W,&T);
for(int i=1; i<=N; i++){
scanf("%lld",&a[i]);
}
sort(a+1,a+N+1);
ans += get(0);
for(int i=1; i<=M; i++){
scanf("%lld %lld",&b[i].d,&b[i].c);
ans += get(b[i].d);
if(ans > Linf) while(true);
}
sort(b+1,b+M+1,[&](data &x,data &y){
return x.d < y.d;
});
a[N+1] = X;
for(int i=1; i<=N+1; i++){
lld s,e;
s = max(a[i-1],(a[i]/T)*T)+1;
e = a[i]-1;
if(s > e) continue;
s %= T; e %= T;
if(e < b[1].d || b[M].d < s) continue;
int it1,it2,l,r;
l = 1; r = M;
while(l <= r){
int m = (l+r)>>1;
if(b[m].d >= s){
it1 = m;
r = m-1;
}else l = m+1;
}
l = 1; r = M;
while(l <= r){
int m = (l+r)>>1;
if(b[m].d <= e){
it2 = m;
l = m+1;
}else r = m-1;
}
if(it1 > it2) continue;
int it;
lld small = 0,sum = 0;
for(int j=it2; j>=it1; j--){
if(check[j]) continue;
sum += b[j].c;
if(sum > Linf) while(true);
sum -= get((a[i]/T)*T+b[j].d);
if(small > sum){
small = sum;
it = j;
}
}
if(small == 0) continue;
ans += small;
for(int j=it2; j>=it; j--) check[j] = true;
}
printf("%lld\n",ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |