#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
using namespace std;
const int MAXN = 2e5;
const int64_t inf = 1e18;
struct Passanger
{
int64_t d, c;
Passanger(){}
Passanger(int64_t d, int64_t c) : d(d), c(c) {}
};
int64_t X, n, m, W, T;
int64_t sources[MAXN+5];
Passanger passangers[MAXN+5];
int64_t depart[MAXN+5];
int64_t endWaterPoints[MAXN+5];
int findLastPassangerBefore(int64_t rem)
{
int l = 0, r = m - 1, mid;
while(l+1<r)
{
mid = (l+r)/2;
if(passangers[mid].d<rem) l = mid;
else r = mid - 1;
}
if(passangers[r].d<rem) return r;
if(passangers[l].d<rem) return l;
return -1;
}
void init()
{
sort(sources, sources+n);
sort(passangers, passangers+m,
[](const Passanger& A, const Passanger& B)
{
if(A.d!=B.d) return A.d<B.d;
return A.c<B.c;
});
for(int i = 0;i<m;i++) depart[i] = -1;
for(int i = 0;i<n;i++)
{
int ind = findLastPassangerBefore(sources[i]%T);
if(ind!=-1 && depart[ind]==-1) depart[ind] = sources[i];
}
{
int ind = findLastPassangerBefore(X%T);
if(ind!=-1 && depart[ind]==-1) depart[ind] = X;
}
//for(int i = 0;i<m;i++) cout << depart[i] << " ";
//cout << '\n';
}
double dp[MAXN+5];
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> X >> n >> m >> W >> T;
for(int i = 0;i<n;i++) cin >> sources[i];
for(int i = 0;i<m;i++) cin >> passangers[i].d >> passangers[i].c;
init();
int64_t driverWater = X/T + 1;
int64_t endWaterPointsSum = 0;
for(int i = 0;i<m;i++)
{
endWaterPoints[i] = ((X-passangers[i].d+(T-1))/T)*T + passangers[i].d;
endWaterPointsSum += endWaterPoints[i];
//cout << i << "->" << endWaterPoints[i] << '\n';
}
int64_t beginWaterPointsSum = 0;
for(int i = 0;i<m;i++) beginWaterPointsSum += passangers[i].d;
for(int i = 0;i<m;i++)
{
dp[i] = inf;
if(i!=0) dp[i] = dp[i-1];
else dp[i] = 0;
if(depart[i]!=-1)
{
int64_t based = (depart[i]/T)*T;
double changeSum = 0;
for(int j = i;j>=0;j--)
{
double last = ((j==0)?0:dp[j-1]);
changeSum += (double(based + passangers[j].d - endWaterPoints[j])/double(T))*W + passangers[j].c;
//cout << i << " " << j << ": " << last << " + " << changeSum << " || " << based + passangers[j].d << '\n';
dp[i] = min(dp[i], last + changeSum);
}
}
//cout << dp[i] << '\n';
}
//cout << endWaterPointsSum << " - " << beginWaterPointsSum << '\n';
//cout << "all water: " << (endWaterPointsSum-beginWaterPointsSum)/T << '\n';
int64_t ans = round(dp[m-1]) + ((endWaterPointsSum-beginWaterPointsSum)/T)*W + driverWater*W;
cout << ans << '\n';
}
/*
19 1 4 8 7
10
1 20
2 10
4 5
6 5
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |