#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
#define REP(i, n) for(int i = 0;i < n;i ++)
#define REP1(i, n) for(int i = 1;i <= n;i ++)
#define FILL(i, n) memset(i, n, sizeof(i))
#define X first
#define Y second
#define pb push_back
#define SZ(_a) ((int)(_a).size())
#define ALL(_a) (_a).begin(), (_a).end()
#ifdef brian
template<typename T>void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...t>void _do(T &&x, t &&...X){cerr<<x<<", ";_do(X...);}
#define debug(...) {\
fprintf(stderr, "%s - %d (%s) = ", __PRETTY_FUNCTION__, __LINE__, #__VA_ARGS__);\
_do(__VA_ARGS__);\
}
#define IOS()
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define debug(...)
#define endl '\n'
#endif
const ll MAXn = 2e3 + 5;
const ll INF = ll(3e18);
const ll MOD = 1000000007;
struct tg{
ll l, r, bs;
};
ll x[MAXn];
ii dt[MAXn];
ll d[MAXn], c[MAXn], nx[MAXn], pnx[MAXn], mx[MAXn];
vector<tg> v;
ll dp[MAXn];
int main(){
IOS();
ll L, n, m, W, T;
cin>>L>>n>>m>>W>>T;
x[0] = 0;
REP1(i, n)cin>>x[i];
x[n + 1] = L;
REP1(i, m)cin>>dt[i].X>>dt[i].Y;
sort(dt + 1, dt + m + 1);
REP1(i, m)d[i] = dt[i].X, c[i] = dt[i].Y;
ll tt = 0;
REP(i, m + 1) tt += (L - d[i]) / T + 1;
tt *= W;
debug(tt);
REP1(i, m)debug(i, d[i]);
REP(i, n + 2)
{
ll t = lower_bound(d + 1, d + 1 + m, x[i] % T) - d;
debug(i, x[i] % T, t);
if(t == m + 1)t = 0;
nx[i] = t;
}
REP(i, n + 2)debug(i, nx[i]);
REP(i, n + 1)
{
ll a = nx[i], b = nx[i + 1] - 1;
ll pa = (a == 0 ? (x[i] / T + 1) * T : x[i] / T * T + d[a]);
if(a > x[i + 1])continue;
if(b < 0)b = m;
if(b == 0)continue;
ll pb = x[i + 1] / T * T + d[b];
ll bs = x[i + 1] / T * T;
if(pb - pa != d[b] - d[a])v.pb({1, b, bs});
else v.pb({a, b, bs});
}
sort(ALL(v), [](tg &a, tg &b){return a.r < b.r;});
for(auto &p:v)debug(p.l, p.r, p.bs);
ll it = 0;
REP1(i, m)mx[i] = -1;
REP1(i, m)
{
dp[i] = dp[i - 1];
while(it < SZ(v) && v[it].r <= i)
{
for(int j = v[it].l;j <= v[it].r;j ++)mx[j] = max(mx[j], ((L - (v[it].bs + d[j])) / T + 1) * W);
it ++;
}
ll tmp = 0;
for(int j = i;j > 0;j --)
{
if(mx[j] == -1)break;
tmp += mx[j] - c[j];
dp[i] = max(dp[i], dp[j-1] + tmp);
}
}
REP1(i, m)debug(i, mx[i]);
cout<<tt - dp[m]<<endl;
}
Compilation message
coach.cpp: In function 'int main()':
coach.cpp:79:12: warning: unused variable 'p' [-Wunused-variable]
for(auto &p:v)debug(p.l, p.r, p.bs);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
416 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
416 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
416 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
416 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |