// High above the clouds there is a rainbow...
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxn=1e5+10,mod=1e9+7;
const ll inf=1e18;
ll a[maxn], d[maxn], dp[maxn], W, T;
pll p[maxn];
vector<pair<int,ll> >vec[maxn];
ll val[maxn];
void add(int l,int r,ll x){
while(l<r)
val[l]=min(val[l],x), l++;
}
ll ask(int pos){
return val[pos];
}
int main(){
fill(val,val+maxn,inf);
ios_base::sync_with_stdio(false);cin.tie(0);
ll x; int n,m; cin>>x>>n>>m>>W>>T;
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
a[n++]=x;
ll ans=W*((x/T)+1);
p[0]={0,inf}, d[0]=0;
for(int i=1;i<=m;i++){
cin>>p[i].F>>p[i].S;
d[i]=p[i].F;
p[i].S-= W* (x/T), ans+= W* (x/T);
if( (p[i].F%T) < (x%T) ) p[i].S-= W, ans+=W;
}
m++;
sort(p,p+m), sort(d,d+m);
ll lst=0;
for(int i=0;i<n;i++){
int A=lower_bound(d,d+m,lst %T)-d, B=lower_bound(d,d+m,a[i] %T)-d;
if( lst< (a[i]/T)*T ) A=0;
if(A!=B) vec[B].PB({A,a[i]/T});
lst=a[i];
}
for(int i=1;i<=m;i++){
for(auto p:vec[i])
add(p.F,i, p.S);
dp[i]=0;
ll num=0;
for(int j=i-1;j>=0;j--){
dp[i]= min(dp[i], num+dp[j]);
if(ask(j)==inf) break;
num+= p[j].S + W*ask(j);
}
}
return cout<<dp[m]+ans<<endl,0;
}
// Deathly mistakes:
// * Read the problem curfully.
// * Check maxn.c
// * Overflows.
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3456 KB |
Output is correct |
2 |
Correct |
4 ms |
3456 KB |
Output is correct |
3 |
Correct |
5 ms |
3584 KB |
Output is correct |
4 |
Correct |
5 ms |
3456 KB |
Output is correct |
5 |
Correct |
4 ms |
3456 KB |
Output is correct |
6 |
Correct |
4 ms |
3584 KB |
Output is correct |
7 |
Correct |
4 ms |
3456 KB |
Output is correct |
8 |
Correct |
4 ms |
3456 KB |
Output is correct |
9 |
Correct |
4 ms |
3456 KB |
Output is correct |
10 |
Correct |
4 ms |
3456 KB |
Output is correct |
11 |
Correct |
4 ms |
3456 KB |
Output is correct |
12 |
Correct |
4 ms |
3456 KB |
Output is correct |
13 |
Correct |
4 ms |
3456 KB |
Output is correct |
14 |
Correct |
5 ms |
3456 KB |
Output is correct |
15 |
Correct |
5 ms |
3456 KB |
Output is correct |
16 |
Correct |
4 ms |
3456 KB |
Output is correct |
17 |
Correct |
4 ms |
3456 KB |
Output is correct |
18 |
Correct |
4 ms |
3456 KB |
Output is correct |
19 |
Correct |
4 ms |
3456 KB |
Output is correct |
20 |
Correct |
4 ms |
3584 KB |
Output is correct |
21 |
Correct |
4 ms |
3456 KB |
Output is correct |
22 |
Correct |
5 ms |
3456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3456 KB |
Output is correct |
2 |
Correct |
4 ms |
3456 KB |
Output is correct |
3 |
Correct |
5 ms |
3584 KB |
Output is correct |
4 |
Correct |
5 ms |
3456 KB |
Output is correct |
5 |
Correct |
4 ms |
3456 KB |
Output is correct |
6 |
Correct |
4 ms |
3584 KB |
Output is correct |
7 |
Correct |
4 ms |
3456 KB |
Output is correct |
8 |
Correct |
4 ms |
3456 KB |
Output is correct |
9 |
Correct |
4 ms |
3456 KB |
Output is correct |
10 |
Correct |
4 ms |
3456 KB |
Output is correct |
11 |
Correct |
4 ms |
3456 KB |
Output is correct |
12 |
Correct |
4 ms |
3456 KB |
Output is correct |
13 |
Correct |
4 ms |
3456 KB |
Output is correct |
14 |
Correct |
5 ms |
3456 KB |
Output is correct |
15 |
Correct |
5 ms |
3456 KB |
Output is correct |
16 |
Correct |
4 ms |
3456 KB |
Output is correct |
17 |
Correct |
4 ms |
3456 KB |
Output is correct |
18 |
Correct |
4 ms |
3456 KB |
Output is correct |
19 |
Correct |
4 ms |
3456 KB |
Output is correct |
20 |
Correct |
4 ms |
3584 KB |
Output is correct |
21 |
Correct |
4 ms |
3456 KB |
Output is correct |
22 |
Correct |
5 ms |
3456 KB |
Output is correct |
23 |
Correct |
4 ms |
3456 KB |
Output is correct |
24 |
Correct |
5 ms |
3584 KB |
Output is correct |
25 |
Correct |
4 ms |
3456 KB |
Output is correct |
26 |
Correct |
4 ms |
3456 KB |
Output is correct |
27 |
Correct |
4 ms |
3456 KB |
Output is correct |
28 |
Correct |
4 ms |
3456 KB |
Output is correct |
29 |
Correct |
4 ms |
3456 KB |
Output is correct |
30 |
Correct |
5 ms |
3584 KB |
Output is correct |
31 |
Correct |
4 ms |
3456 KB |
Output is correct |
32 |
Correct |
4 ms |
3456 KB |
Output is correct |
33 |
Correct |
4 ms |
3456 KB |
Output is correct |
34 |
Correct |
4 ms |
3456 KB |
Output is correct |
35 |
Correct |
5 ms |
3456 KB |
Output is correct |
36 |
Correct |
4 ms |
3584 KB |
Output is correct |
37 |
Correct |
4 ms |
3456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3456 KB |
Output is correct |
2 |
Correct |
4 ms |
3456 KB |
Output is correct |
3 |
Correct |
5 ms |
3584 KB |
Output is correct |
4 |
Correct |
5 ms |
3456 KB |
Output is correct |
5 |
Correct |
4 ms |
3456 KB |
Output is correct |
6 |
Correct |
4 ms |
3584 KB |
Output is correct |
7 |
Correct |
4 ms |
3456 KB |
Output is correct |
8 |
Correct |
4 ms |
3456 KB |
Output is correct |
9 |
Correct |
4 ms |
3456 KB |
Output is correct |
10 |
Correct |
4 ms |
3456 KB |
Output is correct |
11 |
Correct |
4 ms |
3456 KB |
Output is correct |
12 |
Correct |
4 ms |
3456 KB |
Output is correct |
13 |
Correct |
4 ms |
3456 KB |
Output is correct |
14 |
Correct |
5 ms |
3456 KB |
Output is correct |
15 |
Correct |
5 ms |
3456 KB |
Output is correct |
16 |
Correct |
4 ms |
3456 KB |
Output is correct |
17 |
Correct |
4 ms |
3456 KB |
Output is correct |
18 |
Correct |
4 ms |
3456 KB |
Output is correct |
19 |
Correct |
4 ms |
3456 KB |
Output is correct |
20 |
Correct |
4 ms |
3584 KB |
Output is correct |
21 |
Correct |
4 ms |
3456 KB |
Output is correct |
22 |
Correct |
5 ms |
3456 KB |
Output is correct |
23 |
Correct |
4 ms |
3456 KB |
Output is correct |
24 |
Correct |
5 ms |
3584 KB |
Output is correct |
25 |
Correct |
4 ms |
3456 KB |
Output is correct |
26 |
Correct |
4 ms |
3456 KB |
Output is correct |
27 |
Correct |
4 ms |
3456 KB |
Output is correct |
28 |
Correct |
4 ms |
3456 KB |
Output is correct |
29 |
Correct |
4 ms |
3456 KB |
Output is correct |
30 |
Correct |
5 ms |
3584 KB |
Output is correct |
31 |
Correct |
4 ms |
3456 KB |
Output is correct |
32 |
Correct |
4 ms |
3456 KB |
Output is correct |
33 |
Correct |
4 ms |
3456 KB |
Output is correct |
34 |
Correct |
4 ms |
3456 KB |
Output is correct |
35 |
Correct |
5 ms |
3456 KB |
Output is correct |
36 |
Correct |
4 ms |
3584 KB |
Output is correct |
37 |
Correct |
4 ms |
3456 KB |
Output is correct |
38 |
Correct |
9 ms |
3712 KB |
Output is correct |
39 |
Correct |
13 ms |
3712 KB |
Output is correct |
40 |
Correct |
13 ms |
3788 KB |
Output is correct |
41 |
Correct |
10 ms |
3584 KB |
Output is correct |
42 |
Correct |
10 ms |
3584 KB |
Output is correct |
43 |
Correct |
9 ms |
3584 KB |
Output is correct |
44 |
Correct |
10 ms |
3712 KB |
Output is correct |
45 |
Correct |
9 ms |
3712 KB |
Output is correct |
46 |
Correct |
12 ms |
3712 KB |
Output is correct |
47 |
Correct |
13 ms |
3684 KB |
Output is correct |
48 |
Correct |
9 ms |
3584 KB |
Output is correct |
49 |
Correct |
8 ms |
3584 KB |
Output is correct |
50 |
Correct |
9 ms |
3584 KB |
Output is correct |
51 |
Correct |
10 ms |
3712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3456 KB |
Output is correct |
2 |
Correct |
4 ms |
3456 KB |
Output is correct |
3 |
Correct |
5 ms |
3584 KB |
Output is correct |
4 |
Correct |
5 ms |
3456 KB |
Output is correct |
5 |
Correct |
4 ms |
3456 KB |
Output is correct |
6 |
Correct |
4 ms |
3584 KB |
Output is correct |
7 |
Correct |
4 ms |
3456 KB |
Output is correct |
8 |
Correct |
4 ms |
3456 KB |
Output is correct |
9 |
Correct |
4 ms |
3456 KB |
Output is correct |
10 |
Correct |
4 ms |
3456 KB |
Output is correct |
11 |
Correct |
4 ms |
3456 KB |
Output is correct |
12 |
Correct |
4 ms |
3456 KB |
Output is correct |
13 |
Correct |
4 ms |
3456 KB |
Output is correct |
14 |
Correct |
5 ms |
3456 KB |
Output is correct |
15 |
Correct |
5 ms |
3456 KB |
Output is correct |
16 |
Correct |
4 ms |
3456 KB |
Output is correct |
17 |
Correct |
4 ms |
3456 KB |
Output is correct |
18 |
Correct |
4 ms |
3456 KB |
Output is correct |
19 |
Correct |
4 ms |
3456 KB |
Output is correct |
20 |
Correct |
4 ms |
3584 KB |
Output is correct |
21 |
Correct |
4 ms |
3456 KB |
Output is correct |
22 |
Correct |
5 ms |
3456 KB |
Output is correct |
23 |
Correct |
4 ms |
3456 KB |
Output is correct |
24 |
Correct |
5 ms |
3584 KB |
Output is correct |
25 |
Correct |
4 ms |
3456 KB |
Output is correct |
26 |
Correct |
4 ms |
3456 KB |
Output is correct |
27 |
Correct |
4 ms |
3456 KB |
Output is correct |
28 |
Correct |
4 ms |
3456 KB |
Output is correct |
29 |
Correct |
4 ms |
3456 KB |
Output is correct |
30 |
Correct |
5 ms |
3584 KB |
Output is correct |
31 |
Correct |
4 ms |
3456 KB |
Output is correct |
32 |
Correct |
4 ms |
3456 KB |
Output is correct |
33 |
Correct |
4 ms |
3456 KB |
Output is correct |
34 |
Correct |
4 ms |
3456 KB |
Output is correct |
35 |
Correct |
5 ms |
3456 KB |
Output is correct |
36 |
Correct |
4 ms |
3584 KB |
Output is correct |
37 |
Correct |
4 ms |
3456 KB |
Output is correct |
38 |
Correct |
9 ms |
3712 KB |
Output is correct |
39 |
Correct |
13 ms |
3712 KB |
Output is correct |
40 |
Correct |
13 ms |
3788 KB |
Output is correct |
41 |
Correct |
10 ms |
3584 KB |
Output is correct |
42 |
Correct |
10 ms |
3584 KB |
Output is correct |
43 |
Correct |
9 ms |
3584 KB |
Output is correct |
44 |
Correct |
10 ms |
3712 KB |
Output is correct |
45 |
Correct |
9 ms |
3712 KB |
Output is correct |
46 |
Correct |
12 ms |
3712 KB |
Output is correct |
47 |
Correct |
13 ms |
3684 KB |
Output is correct |
48 |
Correct |
9 ms |
3584 KB |
Output is correct |
49 |
Correct |
8 ms |
3584 KB |
Output is correct |
50 |
Correct |
9 ms |
3584 KB |
Output is correct |
51 |
Correct |
10 ms |
3712 KB |
Output is correct |
52 |
Runtime error |
24 ms |
8448 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
53 |
Halted |
0 ms |
0 KB |
- |