#include <bits/stdc++.h>
using namespace std;
#pragma gcc optimise("ofast,unroll-loops")
#pragma gcc target("avx")
#define int long long
int a[40005], b[40005];
bool nums[40005];
signed main() {
cin.tie(0);
cin.sync_with_stdio(0);
int n, k; cin >> n >> k;
int total=0;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
total+=a[i];
}
for (int i = 0; i < k; i++) {
int t; cin >> t;
for (int j = 0; j < n; j++) {
if (nums[j]) {
if (b[j] <= t) {
nums[j]=false;
total=total-b[j]+a[j];
}
}
else {
if (a[j] <= t) {
nums[j]=true;
total=total-a[j]+b[j];
}
}
}
}
cout << total << "\n";
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |