# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
319648 | 2020-11-06T01:24:42 Z | arnold518 | Long Distance Coach (JOI17_coach) | C++14 | 573 ms | 49872 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 4e5; ll X, W, T; int N, M, K; vector<pll> V; ll SS[MAXN+10]; pll C[MAXN+10]; ll A[MAXN+10]; ll dp[MAXN+10]; map<ll, ll> MM; ll S[MAXN+10], TT[MAXN+10]; struct Line { ll a, b; }; long double cross(Line p, Line q) { return (long double)(q.b-p.b)/(p.a-q.a); } struct CHT { vector<Line> S; void push(Line p) { if(!S.empty() && S.back().a==p.a) { if(S.back().b<=p.b) return; S.pop_back(); } while(S.size()>1 && cross(S[S.size()-1], p)>=cross(S[S.size()-2], S[S.size()-1])) S.pop_back(); S.push_back(p); } ll query(ll x) { int lo=0, hi=S.size(); while(lo+1<hi) { int mid=lo+hi>>1; if(cross(S[mid], S[mid-1])>=x) lo=mid; else hi=mid; } return S[lo].a*x+S[lo].b; } }cht; int main() { scanf("%lld%d%d%lld%lld", &X, &N, &M, &W, &T); for(int i=1; i<=N; i++) scanf("%lld", &SS[i]); sort(SS+1, SS+N+1, greater<ll>()); { ll x, y; x=X%T; y=X/T; MM[x]=-y; } for(int i=1; i<=N; i++) { ll x, y; x=SS[i]%T; y=SS[i]/T; MM[x]=-y; } for(int i=1; i<=M; i++) { scanf("%lld%lld", &C[i].first, &C[i].second); dp[0]+=C[i].second; MM[C[i].first]=C[i].second; dp[0]+=W*(X/T); if(C[i].first<=X%T) dp[0]+=W; } dp[0]+=W*(X/T+1); K=MM.size(); int t=1, P; for(auto it : MM) { if(it.first==X%T) P=t; A[t++]=it.second; } for(int i=1; i<=K; i++) { if(A[i]>0) { S[i]=S[i-1]+X/T; TT[i]=TT[i-1]+1; if(i<=P) S[i]++; } else { S[i]=S[i-1]; TT[i]=TT[i-1]; } } for(int i=1; i<=K; i++) { cht.push({TT[i-1], W*S[i-1]+dp[i-1]}); if(A[i]>0) { dp[i]=dp[i-1]-A[i]; } else { dp[i]=cht.query(W*A[i])-W*(A[i]*TT[i]+S[i]); } } printf("%lld\n", dp[K]); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 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 |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 512 KB | Output is correct |
13 | Correct | 1 ms | 364 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 364 KB | Output is correct |
16 | Correct | 1 ms | 364 KB | Output is correct |
17 | Correct | 1 ms | 364 KB | Output is correct |
18 | Correct | 1 ms | 364 KB | Output is correct |
19 | Correct | 1 ms | 512 KB | Output is correct |
20 | Correct | 1 ms | 492 KB | Output is correct |
21 | Correct | 1 ms | 364 KB | Output is correct |
22 | Correct | 1 ms | 364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 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 |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 512 KB | Output is correct |
13 | Correct | 1 ms | 364 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 364 KB | Output is correct |
16 | Correct | 1 ms | 364 KB | Output is correct |
17 | Correct | 1 ms | 364 KB | Output is correct |
18 | Correct | 1 ms | 364 KB | Output is correct |
19 | Correct | 1 ms | 512 KB | Output is correct |
20 | Correct | 1 ms | 492 KB | Output is correct |
21 | Correct | 1 ms | 364 KB | Output is correct |
22 | Correct | 1 ms | 364 KB | Output is correct |
23 | Correct | 1 ms | 364 KB | Output is correct |
24 | Correct | 1 ms | 492 KB | Output is correct |
25 | Correct | 1 ms | 364 KB | Output is correct |
26 | Correct | 1 ms | 364 KB | Output is correct |
27 | Correct | 1 ms | 364 KB | Output is correct |
28 | Correct | 1 ms | 512 KB | Output is correct |
29 | Correct | 1 ms | 364 KB | Output is correct |
30 | Correct | 1 ms | 364 KB | Output is correct |
31 | Correct | 1 ms | 512 KB | Output is correct |
32 | Correct | 1 ms | 364 KB | Output is correct |
33 | Correct | 1 ms | 364 KB | Output is correct |
34 | Correct | 1 ms | 492 KB | Output is correct |
35 | Correct | 1 ms | 364 KB | Output is correct |
36 | Correct | 1 ms | 364 KB | Output is correct |
37 | Correct | 1 ms | 492 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 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 |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 512 KB | Output is correct |
13 | Correct | 1 ms | 364 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 364 KB | Output is correct |
16 | Correct | 1 ms | 364 KB | Output is correct |
17 | Correct | 1 ms | 364 KB | Output is correct |
18 | Correct | 1 ms | 364 KB | Output is correct |
19 | Correct | 1 ms | 512 KB | Output is correct |
20 | Correct | 1 ms | 492 KB | Output is correct |
21 | Correct | 1 ms | 364 KB | Output is correct |
22 | Correct | 1 ms | 364 KB | Output is correct |
23 | Correct | 1 ms | 364 KB | Output is correct |
24 | Correct | 1 ms | 492 KB | Output is correct |
25 | Correct | 1 ms | 364 KB | Output is correct |
26 | Correct | 1 ms | 364 KB | Output is correct |
27 | Correct | 1 ms | 364 KB | Output is correct |
28 | Correct | 1 ms | 512 KB | Output is correct |
29 | Correct | 1 ms | 364 KB | Output is correct |
30 | Correct | 1 ms | 364 KB | Output is correct |
31 | Correct | 1 ms | 512 KB | Output is correct |
32 | Correct | 1 ms | 364 KB | Output is correct |
33 | Correct | 1 ms | 364 KB | Output is correct |
34 | Correct | 1 ms | 492 KB | Output is correct |
35 | Correct | 1 ms | 364 KB | Output is correct |
36 | Correct | 1 ms | 364 KB | Output is correct |
37 | Correct | 1 ms | 492 KB | Output is correct |
38 | Correct | 3 ms | 876 KB | Output is correct |
39 | Correct | 3 ms | 876 KB | Output is correct |
40 | Correct | 3 ms | 876 KB | Output is correct |
41 | Correct | 3 ms | 876 KB | Output is correct |
42 | Correct | 3 ms | 876 KB | Output is correct |
43 | Correct | 2 ms | 748 KB | Output is correct |
44 | Correct | 3 ms | 876 KB | Output is correct |
45 | Correct | 3 ms | 876 KB | Output is correct |
46 | Correct | 2 ms | 876 KB | Output is correct |
47 | Correct | 3 ms | 1004 KB | Output is correct |
48 | Correct | 3 ms | 876 KB | Output is correct |
49 | Correct | 3 ms | 1024 KB | Output is correct |
50 | Correct | 4 ms | 876 KB | Output is correct |
51 | Correct | 3 ms | 876 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 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 |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 512 KB | Output is correct |
13 | Correct | 1 ms | 364 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 364 KB | Output is correct |
16 | Correct | 1 ms | 364 KB | Output is correct |
17 | Correct | 1 ms | 364 KB | Output is correct |
18 | Correct | 1 ms | 364 KB | Output is correct |
19 | Correct | 1 ms | 512 KB | Output is correct |
20 | Correct | 1 ms | 492 KB | Output is correct |
21 | Correct | 1 ms | 364 KB | Output is correct |
22 | Correct | 1 ms | 364 KB | Output is correct |
23 | Correct | 1 ms | 364 KB | Output is correct |
24 | Correct | 1 ms | 492 KB | Output is correct |
25 | Correct | 1 ms | 364 KB | Output is correct |
26 | Correct | 1 ms | 364 KB | Output is correct |
27 | Correct | 1 ms | 364 KB | Output is correct |
28 | Correct | 1 ms | 512 KB | Output is correct |
29 | Correct | 1 ms | 364 KB | Output is correct |
30 | Correct | 1 ms | 364 KB | Output is correct |
31 | Correct | 1 ms | 512 KB | Output is correct |
32 | Correct | 1 ms | 364 KB | Output is correct |
33 | Correct | 1 ms | 364 KB | Output is correct |
34 | Correct | 1 ms | 492 KB | Output is correct |
35 | Correct | 1 ms | 364 KB | Output is correct |
36 | Correct | 1 ms | 364 KB | Output is correct |
37 | Correct | 1 ms | 492 KB | Output is correct |
38 | Correct | 3 ms | 876 KB | Output is correct |
39 | Correct | 3 ms | 876 KB | Output is correct |
40 | Correct | 3 ms | 876 KB | Output is correct |
41 | Correct | 3 ms | 876 KB | Output is correct |
42 | Correct | 3 ms | 876 KB | Output is correct |
43 | Correct | 2 ms | 748 KB | Output is correct |
44 | Correct | 3 ms | 876 KB | Output is correct |
45 | Correct | 3 ms | 876 KB | Output is correct |
46 | Correct | 2 ms | 876 KB | Output is correct |
47 | Correct | 3 ms | 1004 KB | Output is correct |
48 | Correct | 3 ms | 876 KB | Output is correct |
49 | Correct | 3 ms | 1024 KB | Output is correct |
50 | Correct | 4 ms | 876 KB | Output is correct |
51 | Correct | 3 ms | 876 KB | Output is correct |
52 | Correct | 551 ms | 48224 KB | Output is correct |
53 | Correct | 349 ms | 48356 KB | Output is correct |
54 | Correct | 498 ms | 47460 KB | Output is correct |
55 | Correct | 486 ms | 47896 KB | Output is correct |
56 | Correct | 432 ms | 48100 KB | Output is correct |
57 | Correct | 446 ms | 47972 KB | Output is correct |
58 | Correct | 461 ms | 48484 KB | Output is correct |
59 | Correct | 439 ms | 47716 KB | Output is correct |
60 | Correct | 427 ms | 47460 KB | Output is correct |
61 | Correct | 446 ms | 47716 KB | Output is correct |
62 | Correct | 453 ms | 47980 KB | Output is correct |
63 | Correct | 220 ms | 49872 KB | Output is correct |
64 | Correct | 340 ms | 48484 KB | Output is correct |
65 | Correct | 332 ms | 48532 KB | Output is correct |
66 | Correct | 329 ms | 48424 KB | Output is correct |
67 | Correct | 330 ms | 48484 KB | Output is correct |
68 | Correct | 332 ms | 48632 KB | Output is correct |
69 | Correct | 548 ms | 48228 KB | Output is correct |
70 | Correct | 571 ms | 48192 KB | Output is correct |
71 | Correct | 550 ms | 48244 KB | Output is correct |
72 | Correct | 555 ms | 48228 KB | Output is correct |
73 | Correct | 538 ms | 48248 KB | Output is correct |
74 | Correct | 548 ms | 48100 KB | Output is correct |
75 | Correct | 573 ms | 48228 KB | Output is correct |
76 | Correct | 528 ms | 48356 KB | Output is correct |
77 | Correct | 452 ms | 48204 KB | Output is correct |
78 | Correct | 470 ms | 48444 KB | Output is correct |
79 | Correct | 530 ms | 47844 KB | Output is correct |
80 | Correct | 561 ms | 47844 KB | Output is correct |