#include<bits/stdc++.h>
using namespace std;
int N, M, W, T, how[200009][2];
long long X, dp[200009][2], need[200009], partialC[200009];
const long long INF = 1LL << 60;
pair < int, long long > station[200009];
pair < long long, int > passenger[200009];
void read ()
{
scanf ("%lld %d %d %d %d", &X, &N, &M, &W, &T);
for (int i=1; i<=N; i++)
scanf ("%lld", &station[i].second), station[i].first = station[i].second % T;
if (X % T != 0)
station[++N] = {X % T, X};
sort (station + 1, station + N + 1);
for (int i=1; i<=M; i++)
scanf ("%lld %d", &passenger[i].first, &passenger[i].second);
sort (passenger + 1, passenger + M + 1);
}
int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);
read ();
for (int i=1; i<=M; i++)
need[i] = 1LL * W * ((X - passenger[i].first) / T + 1);
for (int i=0; i<=M; i++)
dp[i][0] = dp[i][1] = INF;
dp[M + 1][1] = 1LL * W * (X / T + 1);
dp[M + 1][0] = INF;
///dp[i][j] = considered all passengers >= i, and j=0/1 depending on whether I've taken i or not
for (int i=1; i<=M; i++)
partialC[i] = partialC[i - 1] + passenger[i].second;
passenger[M + 1].first = T + 1;
int pntr = N + 1; station[N + 1] = {T + 2, 0};
for (int i=M + 1; i>=1; i--)
{
///simple update
if (min (dp[i][0], dp[i][1]) + need[i - 1] < dp[i - 1][1])
dp[i - 1][1] = min (dp[i][0], dp[i][1]) + need[i - 1], how[i - 1][1] = i;
///now suppose some customers ending with i - 1 are to be aborted
while (pntr > 0 && station[pntr].first > passenger[i].first)
pntr --;
///the first one that doesn't get rid of i
if (station[pntr].first < passenger[i - 1].first || i == 1 || pntr == 0 || pntr > N)
continue;///first make sure you can abort i - 1, that ensures you can abort any contiguous segment [j, i - 1]
long long fastestAbort = station[pntr].second;
while (pntr - 1 > 0 && station[pntr - 1].first > passenger[i - 1].first)
pntr --, fastestAbort = min (fastestAbort, station[pntr].second);
///computed fastest abort
long long currDp = min (dp[i][0], dp[i][1]), currSlope = 1LL * W * (fastestAbort / T);
for (int j=i - 1; j>=1; j--)
{
long long curr = currDp + partialC[i - 1] - partialC[j - 1] + 1LL * currSlope * (i - j);
if (curr < dp[j][0])
dp[j][0] = curr, how[j][0] = i;
}
}
printf ("%lld\n", min (dp[0][0], dp[0][1]));
return 0;
}
Compilation message
coach.cpp: In function 'void read()':
coach.cpp:13:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%lld %d %d %d %d", &X, &N, &M, &W, &T);
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
coach.cpp:15:43: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%lld", &station[i].second), station[i].first = station[i].second % T;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
coach.cpp:20:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%lld %d", &passenger[i].first, &passenger[i].second);
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
484 KB |
Output is correct |
4 |
Correct |
3 ms |
484 KB |
Output is correct |
5 |
Correct |
2 ms |
484 KB |
Output is correct |
6 |
Correct |
2 ms |
552 KB |
Output is correct |
7 |
Correct |
2 ms |
552 KB |
Output is correct |
8 |
Correct |
3 ms |
696 KB |
Output is correct |
9 |
Correct |
2 ms |
720 KB |
Output is correct |
10 |
Correct |
3 ms |
720 KB |
Output is correct |
11 |
Correct |
2 ms |
720 KB |
Output is correct |
12 |
Correct |
4 ms |
720 KB |
Output is correct |
13 |
Correct |
4 ms |
720 KB |
Output is correct |
14 |
Correct |
2 ms |
720 KB |
Output is correct |
15 |
Correct |
2 ms |
720 KB |
Output is correct |
16 |
Correct |
2 ms |
720 KB |
Output is correct |
17 |
Correct |
2 ms |
720 KB |
Output is correct |
18 |
Correct |
2 ms |
720 KB |
Output is correct |
19 |
Correct |
3 ms |
720 KB |
Output is correct |
20 |
Correct |
3 ms |
720 KB |
Output is correct |
21 |
Correct |
3 ms |
720 KB |
Output is correct |
22 |
Correct |
2 ms |
720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
484 KB |
Output is correct |
4 |
Correct |
3 ms |
484 KB |
Output is correct |
5 |
Correct |
2 ms |
484 KB |
Output is correct |
6 |
Correct |
2 ms |
552 KB |
Output is correct |
7 |
Correct |
2 ms |
552 KB |
Output is correct |
8 |
Correct |
3 ms |
696 KB |
Output is correct |
9 |
Correct |
2 ms |
720 KB |
Output is correct |
10 |
Correct |
3 ms |
720 KB |
Output is correct |
11 |
Correct |
2 ms |
720 KB |
Output is correct |
12 |
Correct |
4 ms |
720 KB |
Output is correct |
13 |
Correct |
4 ms |
720 KB |
Output is correct |
14 |
Correct |
2 ms |
720 KB |
Output is correct |
15 |
Correct |
2 ms |
720 KB |
Output is correct |
16 |
Correct |
2 ms |
720 KB |
Output is correct |
17 |
Correct |
2 ms |
720 KB |
Output is correct |
18 |
Correct |
2 ms |
720 KB |
Output is correct |
19 |
Correct |
3 ms |
720 KB |
Output is correct |
20 |
Correct |
3 ms |
720 KB |
Output is correct |
21 |
Correct |
3 ms |
720 KB |
Output is correct |
22 |
Correct |
2 ms |
720 KB |
Output is correct |
23 |
Correct |
2 ms |
720 KB |
Output is correct |
24 |
Correct |
2 ms |
720 KB |
Output is correct |
25 |
Correct |
2 ms |
740 KB |
Output is correct |
26 |
Correct |
2 ms |
740 KB |
Output is correct |
27 |
Correct |
2 ms |
740 KB |
Output is correct |
28 |
Correct |
2 ms |
740 KB |
Output is correct |
29 |
Correct |
2 ms |
740 KB |
Output is correct |
30 |
Correct |
3 ms |
740 KB |
Output is correct |
31 |
Correct |
2 ms |
740 KB |
Output is correct |
32 |
Correct |
2 ms |
740 KB |
Output is correct |
33 |
Correct |
3 ms |
740 KB |
Output is correct |
34 |
Correct |
2 ms |
740 KB |
Output is correct |
35 |
Correct |
2 ms |
740 KB |
Output is correct |
36 |
Correct |
2 ms |
740 KB |
Output is correct |
37 |
Correct |
3 ms |
740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
484 KB |
Output is correct |
4 |
Correct |
3 ms |
484 KB |
Output is correct |
5 |
Correct |
2 ms |
484 KB |
Output is correct |
6 |
Correct |
2 ms |
552 KB |
Output is correct |
7 |
Correct |
2 ms |
552 KB |
Output is correct |
8 |
Correct |
3 ms |
696 KB |
Output is correct |
9 |
Correct |
2 ms |
720 KB |
Output is correct |
10 |
Correct |
3 ms |
720 KB |
Output is correct |
11 |
Correct |
2 ms |
720 KB |
Output is correct |
12 |
Correct |
4 ms |
720 KB |
Output is correct |
13 |
Correct |
4 ms |
720 KB |
Output is correct |
14 |
Correct |
2 ms |
720 KB |
Output is correct |
15 |
Correct |
2 ms |
720 KB |
Output is correct |
16 |
Correct |
2 ms |
720 KB |
Output is correct |
17 |
Correct |
2 ms |
720 KB |
Output is correct |
18 |
Correct |
2 ms |
720 KB |
Output is correct |
19 |
Correct |
3 ms |
720 KB |
Output is correct |
20 |
Correct |
3 ms |
720 KB |
Output is correct |
21 |
Correct |
3 ms |
720 KB |
Output is correct |
22 |
Correct |
2 ms |
720 KB |
Output is correct |
23 |
Correct |
2 ms |
720 KB |
Output is correct |
24 |
Correct |
2 ms |
720 KB |
Output is correct |
25 |
Correct |
2 ms |
740 KB |
Output is correct |
26 |
Correct |
2 ms |
740 KB |
Output is correct |
27 |
Correct |
2 ms |
740 KB |
Output is correct |
28 |
Correct |
2 ms |
740 KB |
Output is correct |
29 |
Correct |
2 ms |
740 KB |
Output is correct |
30 |
Correct |
3 ms |
740 KB |
Output is correct |
31 |
Correct |
2 ms |
740 KB |
Output is correct |
32 |
Correct |
2 ms |
740 KB |
Output is correct |
33 |
Correct |
3 ms |
740 KB |
Output is correct |
34 |
Correct |
2 ms |
740 KB |
Output is correct |
35 |
Correct |
2 ms |
740 KB |
Output is correct |
36 |
Correct |
2 ms |
740 KB |
Output is correct |
37 |
Correct |
3 ms |
740 KB |
Output is correct |
38 |
Correct |
5 ms |
764 KB |
Output is correct |
39 |
Correct |
6 ms |
764 KB |
Output is correct |
40 |
Correct |
7 ms |
764 KB |
Output is correct |
41 |
Correct |
6 ms |
764 KB |
Output is correct |
42 |
Correct |
6 ms |
764 KB |
Output is correct |
43 |
Correct |
7 ms |
892 KB |
Output is correct |
44 |
Correct |
5 ms |
892 KB |
Output is correct |
45 |
Correct |
6 ms |
892 KB |
Output is correct |
46 |
Correct |
8 ms |
892 KB |
Output is correct |
47 |
Correct |
6 ms |
892 KB |
Output is correct |
48 |
Correct |
7 ms |
892 KB |
Output is correct |
49 |
Correct |
5 ms |
892 KB |
Output is correct |
50 |
Correct |
5 ms |
892 KB |
Output is correct |
51 |
Correct |
5 ms |
892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
484 KB |
Output is correct |
4 |
Correct |
3 ms |
484 KB |
Output is correct |
5 |
Correct |
2 ms |
484 KB |
Output is correct |
6 |
Correct |
2 ms |
552 KB |
Output is correct |
7 |
Correct |
2 ms |
552 KB |
Output is correct |
8 |
Correct |
3 ms |
696 KB |
Output is correct |
9 |
Correct |
2 ms |
720 KB |
Output is correct |
10 |
Correct |
3 ms |
720 KB |
Output is correct |
11 |
Correct |
2 ms |
720 KB |
Output is correct |
12 |
Correct |
4 ms |
720 KB |
Output is correct |
13 |
Correct |
4 ms |
720 KB |
Output is correct |
14 |
Correct |
2 ms |
720 KB |
Output is correct |
15 |
Correct |
2 ms |
720 KB |
Output is correct |
16 |
Correct |
2 ms |
720 KB |
Output is correct |
17 |
Correct |
2 ms |
720 KB |
Output is correct |
18 |
Correct |
2 ms |
720 KB |
Output is correct |
19 |
Correct |
3 ms |
720 KB |
Output is correct |
20 |
Correct |
3 ms |
720 KB |
Output is correct |
21 |
Correct |
3 ms |
720 KB |
Output is correct |
22 |
Correct |
2 ms |
720 KB |
Output is correct |
23 |
Correct |
2 ms |
720 KB |
Output is correct |
24 |
Correct |
2 ms |
720 KB |
Output is correct |
25 |
Correct |
2 ms |
740 KB |
Output is correct |
26 |
Correct |
2 ms |
740 KB |
Output is correct |
27 |
Correct |
2 ms |
740 KB |
Output is correct |
28 |
Correct |
2 ms |
740 KB |
Output is correct |
29 |
Correct |
2 ms |
740 KB |
Output is correct |
30 |
Correct |
3 ms |
740 KB |
Output is correct |
31 |
Correct |
2 ms |
740 KB |
Output is correct |
32 |
Correct |
2 ms |
740 KB |
Output is correct |
33 |
Correct |
3 ms |
740 KB |
Output is correct |
34 |
Correct |
2 ms |
740 KB |
Output is correct |
35 |
Correct |
2 ms |
740 KB |
Output is correct |
36 |
Correct |
2 ms |
740 KB |
Output is correct |
37 |
Correct |
3 ms |
740 KB |
Output is correct |
38 |
Correct |
5 ms |
764 KB |
Output is correct |
39 |
Correct |
6 ms |
764 KB |
Output is correct |
40 |
Correct |
7 ms |
764 KB |
Output is correct |
41 |
Correct |
6 ms |
764 KB |
Output is correct |
42 |
Correct |
6 ms |
764 KB |
Output is correct |
43 |
Correct |
7 ms |
892 KB |
Output is correct |
44 |
Correct |
5 ms |
892 KB |
Output is correct |
45 |
Correct |
6 ms |
892 KB |
Output is correct |
46 |
Correct |
8 ms |
892 KB |
Output is correct |
47 |
Correct |
6 ms |
892 KB |
Output is correct |
48 |
Correct |
7 ms |
892 KB |
Output is correct |
49 |
Correct |
5 ms |
892 KB |
Output is correct |
50 |
Correct |
5 ms |
892 KB |
Output is correct |
51 |
Correct |
5 ms |
892 KB |
Output is correct |
52 |
Execution timed out |
2048 ms |
14780 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |