#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb emplace_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
#ifdef DEBUG
#define debug(args...) _debug(args)
void _debug(const char* format, ...) {
va_list args;
va_start(args, format);
vprintf(format, args);
va_end(args);
}
#else
#define debug(args...)
#endif
#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 10
int x, n, m, w, t;
int s[MAXN];
ii dc[MAXN];
int cnt[MAXN];
ll dp(int ri, int msk) {
if (ri == n) return 0;
vii v;
int mn = s[ri] / t * t;
REP (i, 0, m) {
if (!(msk & (1 << i))) continue;
int cur = (s[ri] - dc[i].FI) / t * t + dc[i].FI;
if (cur > mn) {
v.pb(cur, i);
}
}
int prv = ri == 0 ? 0 : s[ri - 1];
int k1 = s[ri] / t, k2 = (prv - 1) / t + 1;
if (prv - 1 < 0) prv--;
ll sum = (ll) (k2 - k1 + 1) * w;
REP (i, 0, m) {
int k1 = (s[ri] - dc[i].FI) / t, k2 = (prv - dc[i].FI - 1) / t + 1;
if (prv - dc[i].FI - 1 < 0) k2--;
if (s[ri] - dc[i].FI < 0) k1--;
cnt[i] = k1 - k2 + 1;
if (msk & (1 << i)) {
sum += (ll) cnt[i] * w;
//debug(" %d %s: %lld %d %d %lld\n", ri, bitset<4>(msk).to_string().c_str(), i, cnt[i], w, sum);
}
}
sort(ALL(v), greater<ii>());
int tmsk = msk;
ll res = dp(ri + 1, msk) + sum;
debug(" %d %s: %lld\n", ri, bitset<4>(msk).to_string().c_str(), sum);
REP (_, 0, v.size()) {
sum -= w;
auto [_a, i] = v[_];
tmsk ^= (1 << i);
sum += dc[i].SE;
debug(" %d %s: %lld\n", ri, bitset<4>(msk).to_string().c_str(), sum);
mnto(res, dp(ri + 1, tmsk) + sum);
}
debug("%d %s: %lld\n", ri, bitset<4>(msk).to_string().c_str(), res);
return res;
}
int main() {
scanf("%d%d%d%d%d", &x, &n, &m, &w, &t);
REP (i, 0, n) {
scanf("%d", &s[i]);
}
sort(s, s + n);
s[n] = x;
n++;
REP (i, 0, m) {
scanf("%d%d", &dc[i].FI, &dc[i].SE);
}
sort(dc, dc + m);
printf("%lld\n", dp(0, (1 << m) - 1));
return 0;
}
/*
19 1 4 8 7
10
1 20
2 10
4 5
6 5
*/
Compilation message
coach.cpp: In function 'll dp(int, int)':
coach.cpp:8:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
8 | #define REP(i, s, e) for (int i = s; i < e; i++)
......
76 | REP (_, 0, v.size()) {
| ~~~~~~~~~~~~~~
coach.cpp:76:2: note: in expansion of macro 'REP'
76 | REP (_, 0, v.size()) {
| ^~~
coach.cpp: In function 'int main()':
coach.cpp:89:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
89 | scanf("%d%d%d%d%d", &x, &n, &m, &w, &t);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
coach.cpp:91:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
91 | scanf("%d", &s[i]);
| ~~~~~^~~~~~~~~~~~~
coach.cpp:97:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
97 | scanf("%d%d", &dc[i].FI, &dc[i].SE);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |