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>
- using namespace std;
- using namespace std;
- int main()
- {
- int n,k;
- cin>>n>>k;
- int niza[n];
- for(int i=0; i<n; i++)
- {
- cin>>niza[i];
- }
- int seq[k];
- for(int i=0; i<k; i++)
- {
- cin>>seq[i];
- seq[i]--;
- }
- int cnt[n+1];
- memset(cnt,0,sizeof(cnt));
- int MAX=0;
- int turn=0;
- int tmp=0;
- for(int i=0; i<k; i++)
- {
- memset(cnt, 0, sizeof cnt);
- MAX=0;
- turn=0;
- long long alice=0;
- long long bob=0;
- tmp=0;
- for(int j=0; j<=seq[i]; j++)
- {
- cnt[niza[j]]++;
- MAX=max(MAX,niza[j]);
- }
- for(int j = 0; j < n; j++){
- while(MAX > 0 and cnt[MAX] == 0)
- {
- MAX--;
- }
- if(MAX > tmp){
- cnt[MAX] --;
- if(turn % 2 == 0){
- alice += MAX;
- }
- else{
- bob += MAX;
- }
- }
- else{
- if(turn % 2 == 0){
- alice += tmp;
- }
- else{
- bob += tmp;
- }
- tmp = 0;
- }
- int next = seq[i] + j + 1;
- if(next < n){
- if(niza[next] > MAX){
- tmp = niza[next];
- }
- else{
- cnt[niza[next]]++;
- }
- }
- turn ^= 1;
- }
- cout<<alice-bob<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement