#include <bits/stdc++.h>
using namespace std;
#define int long long
struct Line {
int a;
int b;
__int128 eval(int x) { return (__int128)a * 1LL * x + b; }
};
const int N = 2e5 + 10;
long long X, T;
int n, m, W;
long long a[N];
long long b[N], B[N];
long long c[N], C[N];
int order[N];
__int128 pref[N];
__int128 dp[N];
__int128 ind[N];
__int128 cnt[N];
vector<Line> lines;
vector<__int128> all;
map<__int128, int> start_to_index;
__int128 get(int x) {
__int128 ans = 1e36;
for(Line l : lines) ans = min(ans, l.eval(x));
return ans;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> X >> n >> m >> W >> T;
for(int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
for(int i = 1; i <= m; i++) cin >> B[i] >> C[i];
for(int i = 1; i <= m; i++) order[i] = i;
sort(order + 1, order + m + 1, [&](int i, int j) {
return B[i] < B[j];
});
for(int i = 1; i <= m; i++) {
b[i] = B[order[i]];
c[i] = C[order[i]];
all.push_back(b[i]);
start_to_index[b[i]] = i;
pref[i] = pref[i - 1] + (__int128)c[i];
cnt[i] = X / T + (b[i] <= X % T);
ind[i] = -1;
}
sort(all.begin(), all.end());
n++;
a[n] = X;
// for(int i : all) cout << i << " ";
// cout << "\n";
for(int i = n; i >= 1; i--) {
int temp = a[i] % T;
int index = lower_bound(all.begin(), all.end(), temp) - all.begin();
index--;
if(index == -1) continue;
ind[start_to_index[(a[i] - (temp - all[index])) % T]] = a[i] - (temp - all[index]);
}
// for(int i = 1; i <= m; i++) cout << ind[i] << " ";
// cout << "\n";
// for(int i = 1; i <= m; i++) cout << cnt[i] << " ";
// cout << "\n";
for(__int128 i = 1; i <= m; i++) {
dp[i] = dp[i - 1] + (__int128)W * cnt[i];
if(ind[i] != -1) dp[i] = min(dp[i], (__int128)get((__int128)W * (ind[i] / T)) + pref[i] + (__int128)W * i * (ind[i] / T));
lines.push_back({-i, (int)dp[i] - pref[i]});
}
// for(int i = 1; i <= m; i++) cout << dp[i] << " ";
// cout << "\n";
cout << (int)dp[m] + (int)(X / T + 1) * W;
return 0;
}
Compilation message
coach.cpp: In function 'int main()':
coach.cpp:74:20: warning: narrowing conversion of '- i' from '__int128' to 'long long int' [-Wnarrowing]
74 | lines.push_back({-i, (int)dp[i] - pref[i]});
| ^~
coach.cpp:74:35: warning: narrowing conversion of '(((__int128)((long long int)dp[i])) - pref[i])' from '__int128' to 'long long int' [-Wnarrowing]
74 | lines.push_back({-i, (int)dp[i] - pref[i]});
| ~~~~~~~~~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
10588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
10588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
10588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
10588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |