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>
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 (stderr)
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 |
---|
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... |