# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
431249 | 2021-06-17T10:30:51 Z | faresbasbs | Fortune Telling 2 (JOI14_fortune_telling2) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> #pragma GCC target ("Ofast") #pragma GCC target ("avx2") using namespace std; int n,k,a[40001],b[40001]; int main(){ cin >> n >> k; for(int i = 1 ; i <= n ; i += 1){ cin >> a[i] >> b[i]; } for(int i = 1 ; i <= k ; i += 1){ int f; cin >> f; for(int j = 1 ; j <= n ; j += 1){ if(a[j] <= f){ swap(a[j],b[j]); } } } long long ans = 0; for(int i = 1 ; i <= n ; i += 1){ ans += a[i]; } cout << ans << endl; }