#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
const bool typetest = 0;
const ll Inf = 2e18;
const int N = 1e5 + 5;
ll k, m, d, a, b[N], dp[N];
int n;
ll t[N];
void Read()
{
cin >> k >> m >> d >> a >> n;
for (int i = 1; i <= n; ++i)
cin >> t[i] >> b[i];
t[0] = k;
t[n + 1] = m;
}
void Solve()
{
dp[0] = 0;
if(n > 5e3){
cout << "0";
return;
}
for (int i = 1; i <= n + 1; ++i)
{
dp[i] = -Inf;
for (int j = 0; j < i; ++j)
dp[i] = max(dp[i], dp[j] - (ll)ceil((ld)(t[i] - t[j]) * 1.0 / d) * a);
dp[i] += b[i];
}
cout << dp[n + 1];
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t(1);
if (typetest)
cin >> t;
for (int _ = 1; _ <= t; ++_)
{
Read();
Solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
364 KB |
Output is correct |
2 |
Correct |
3 ms |
364 KB |
Output is correct |
3 |
Correct |
4 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
3 ms |
364 KB |
Output is correct |
6 |
Correct |
3 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
3 ms |
364 KB |
Output is correct |
9 |
Correct |
3 ms |
364 KB |
Output is correct |
10 |
Correct |
3 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
1900 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
24 ms |
2028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |