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;
typedef long double ld;
const int N = 200000 + 7;
int n;
int q;
int a[N];
int b[N];
int t[N];
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
/// freopen ("input", "r", stdin);
cin >> n >> q;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
for (int iq = 1; iq <= q; iq++) {
cin >> t[iq];
}
ll sol = 0;
for (int i = 1; i <= n; i++) {
int mn = min(a[i], b[i]);
int mx = max(a[i], b[i]);
int start = 1, current = a[i];
for (int j = 1; j <= q; j++) {
if (mn <= t[j] && t[j] < mx) {
start = j + 1;
current = mx;
}
}
int cnt = 0;
for (int j = start; j <= q; j++) {
cnt += (mx <= t[j]);
}
if (cnt % 2 == 0) {
sol += current;
} else {
sol += a[i] + b[i] - current;
}
}
cout << sol << "\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... |