Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <vector>
- #include <set>
- #include <map>
- #include <sstream>
- #include <cstdio>
- #include <algorithm>
- #include <stack>
- #include <queue>
- #include <cmath>
- #include <iomanip>
- #include <fstream>
- //#include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- const int INF = (1 << 30);
- const ll inf = (1LL << 60LL);
- const int maxn = 1e5 + 5;
- int n, k;
- int arr[maxn], sortedArr[maxn];;
- int p[maxn];
- int cnt[maxn];
- int tmpArr[maxn];
- bool visited[maxn];
- int main(int argc, const char * argv[]) {
- ios_base::sync_with_stdio(false);
- cin >> n >> k;
- // ifstream cin("in.txt");
- for(int i =0 ; i < n; i ++){
- cin >> arr[i];
- }
- for(int i = 0; i < k; i ++){
- cin >> p[i];
- p[i] --;
- }
- ll A, B;
- int mxx1, mxx2, turn;
- for(int crt= 0; crt < k; crt ++){
- for(int j = 0; j <= n; j ++){
- visited[j] = false;
- cnt[j] = 0;
- }
- mxx1 = 0;
- for(int j = 0; j <= p[crt]; j ++){
- cnt[arr[j]] ++;
- mxx1 = max(mxx1, arr[j]);
- }
- int cc = 0;
- A = B = turn = 0;
- int tmp = 0;
- for(int j = 0; j < n; j ++){
- while(mxx1 > 0 && cnt[mxx1] == 0){
- mxx1 --;
- }
- if(mxx1 > tmp){
- cnt[mxx1] --;
- if(turn == 0){
- A += mxx1;
- }
- else{
- B += mxx1;
- }
- }
- else{
- if(turn == 0){
- A += tmp;
- }
- else{
- B += tmp;
- }
- tmp = 0;
- }
- cc = p[crt] + j + 1;
- if(cc < n){
- if(arr[cc] > mxx1){
- tmp = arr[cc];
- }
- else{
- cnt[arr[cc]] ++;
- }
- }
- turn = 1 - turn;
- }
- cout << (A - B) << "\n";
- }
- return 0;
- }
- /*
- 10 1
- 10 1 4 2 8 7 3 3 10 2
- 10
- 5 1
- 2 4 2 3 5
- 3
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement