이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Source: https://oj.uz/problem/view/JOI17_coach?locale=en
//
#include "bits/stdc++.h"
using namespace std;
#define s second
#define f first
#define pb push_back
typedef long long ll;
#define int long long
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<int> vi;
#define FOR(i, a, b) for (int i = (a); i<b; i++)
bool ckmin(int& a, int b){ return b < a ? a = b, true : false; }
bool ckmax(int& a, int b){ return b > a ? a = b, true : false; }
const int INF = 1e9;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int x, n, m, w, t;
cin >> x >> n >> m >> w >> t;
m++;
vector<array<int, 3> > all(n + m + 1, {-1, -1, 1});
FOR(i, 1, n + 1) {
cin >> all[i][1];
all[i][0] = all[i][1] % t;
all[i][2] = 0;
}
FOR(i, n + 1, n + m) cin >> all[i][0] >> all[i][1];
all[n + m] = {x % t, x, 0};
sort(all.begin(), all.end());
vi prefc(n + m + 1, 0);
vi cnt(n + m + 1, 0);
for (int i = 1; i <= n + m; i++) {
prefc[i] = prefc[i-1] + all[i][1] * all[i][2];
cnt[i] = cnt[i-1] + all[i][2];
}
vi dp(n + m + 1, 0);
int periods = (x / t);
for (int i = 1; i <= n + m; i++) {
// cout << all[i][0] << ' ' << all[i][1] << ' ' << all[i][2] << endl;
if (all[i][2] == 0) { // refill point
dp[i] = dp[i-1];
for (int j = 0; j < i; j++) {
int skip = (all[i][1] - all[i][0]) / t;
ckmin(dp[i], prefc[i] + skip * w * cnt[i] - skip * w * cnt[j] - prefc[j] + dp[j]);
}
} else {
dp[i] = dp[i-1] + w * (periods + (all[i][0] <= (x % t)));
}
}
cout << dp[n + m] + (periods + 1ll) * w << endl;
}
# | 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... |