This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// vaziat meshki-ghermeze !
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;
ll dp[N];
ll rif[N];
ll mn[N];
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll X, n, m, W, T;
cin >> X >> n >> m >> W >> T;
vector<pll> D = { {0, 0} }; // D, C
for(int i = 0; i < n; i++)
cin >> rif[i];
rif[n] = X;
int d, c;
for(int i = 0; i < m; i++){
cin >> d >> c;
D.pb({d, c});
}
sort(all(D));
for(int i = 1; i <= m; i++) D[i].S += D[i - 1].S;
memset(mn, 31, sizeof mn);
for(int i = 0; i <= n; i++){
int idx = lower_bound(all(D), pll(rif[i] % T, -1)) - D.begin();
idx --;
assert(0 <= idx);
mn[idx] = min(mn[idx], rif[i]);
}
dp[0] = ((X + T) / T) * W;
for(int i = 1; i <= m; i++){
dp[i] = dp[i - 1] + ( 1 + ((X - D[i].F) / T) ) * W;
// debug(mn[i]);
if(mn[i] >= Inf) continue;
ll fac = mn[i] / T;
// debug(fac);
for(int j = 0; j < i; j++)
dp[i] = min(dp[i], dp[j] + (D[i].S - D[j].S) + (i - j) * fac * W);
}
//
// for(auto [d, c] : D) cerr << "(" << d << ", " << c << ")\n";
// for(int i = 0; i <= m; i++) cerr << dp[i] << ' ';
cerr << '\n';
//
cout << dp[m] << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |