This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |