# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1105661 | KDM_Dvali | Nile (IOI24_nile) | C++17 | 0 ms | 0 KiB |
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;
typedef long long ll;
vector<ll> calculate_costs(vector<int> W, vector<int> A, vector<int> B, vector<int> E) {
int n = W.size();
int q = E.size();
vector<ll> R(q, 0);
ll sb = 0;
for (int i = 0; i < n; i++) {
sb += B[i];
}
for (int i = 0; i < q; i++) {
ll d = E[i];
long long pmin = LLONG_MAX;
if (n % 2 == 0) {
R[i] = sb;
continue;
} else {
for (int j = 0; j < n; j++) {
if (j % 2 == 0) {
pmin = min(pmin, (long long)A[j] - B[j]);
}
if (j > 0 && j < n - 1) {
if (W[j + 1] - W[j - 1] <= d) {
pmin = min(pmin, (long long)A[j] - B[j]);
}
}
}
}
R[i] = pmin + sb;
}
return R;
}
int main() {
int n, q;
cin >> n >> q;
vector<int> W(n), A(n), B(n), E(q);
for (int i = 0; i < n; i++) {
W[i] = i + 1;
cin >> A[i] >> B[i];
}
for (int i = 0; i < q; i++) {
cin >> E[i];
}
vector<ll> result = calculate_costs(W, A, B, E);
for (size_t i = 0; i < result.size(); i++) {
cout << result[i] << " ";
}
cout << endl;
return 0;
}