Advertisement
Josif_tepe

Untitled

Jun 17th, 2023
1,007
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <vector>
  4. #include <set>
  5. #include <map>
  6. #include <sstream>
  7. #include <cstdio>
  8. #include <algorithm>
  9. #include <stack>
  10. #include <queue>
  11. #include <cmath>
  12. #include <iomanip>
  13. #include <fstream>
  14. using namespace std;
  15.  
  16.  
  17.  
  18.  
  19. using namespace std;
  20.  
  21. int main()
  22. {
  23.     int n,k;
  24.     cin>>n>>k;
  25.     int niza[n];
  26.      
  27.     for(int i=0; i<n; i++)
  28.     {
  29.         cin>>niza[i];
  30.     }
  31.     int seq[k];
  32.     for(int i=0; i<k; i++)
  33.     {
  34.         cin>>seq[i];
  35.         seq[i]--;
  36.     }
  37.     int cnt[n+1];
  38.     memset(cnt,0,sizeof(cnt));
  39.     int MAX=0;
  40.     int turn=0;
  41.     int tmp=0;
  42.     for(int i=0; i<k; i++)
  43.     {
  44.         memset(cnt, 0, sizeof cnt);
  45.         MAX=0;
  46.         turn=0;
  47.         long long alice=0;
  48.         long long bob=0;
  49.         tmp=0;
  50.         for(int j=0; j<=seq[i]; j++)
  51.         {
  52.             cnt[niza[j]]++;
  53.             MAX=max(MAX,niza[j]);
  54.         }
  55.         for(int j = 0; j < n; j++){
  56.             while(MAX > 0 and cnt[MAX] == 0)
  57.             {
  58.                 MAX--;
  59.             }
  60.         if(MAX > tmp){
  61.             cnt[MAX] --;
  62.             if(turn % 2 == 0){
  63.                 alice += MAX;
  64.             }
  65.             else{
  66.                 bob += MAX;
  67.             }
  68.              
  69.         }
  70.         else{
  71.             if(turn % 2 == 0){
  72.                 alice += tmp;
  73.             }
  74.             else{
  75.                 bob += tmp;
  76.             }
  77.             tmp = 0;
  78.         }
  79.             int next = seq[i] + j + 1;
  80.             if(next < n){
  81.                 if(niza[next] > MAX){
  82.                     tmp = niza[next];
  83.                 }
  84.                 else{
  85.                     cnt[niza[next]]++;
  86.                 }
  87.             }
  88.             turn ^= 1;
  89.          
  90.         }
  91.          cout<<alice-bob<<endl;
  92.     }
  93.     return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement