document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <bits/stdc++.h>
  2. #define MP make_pair
  3. typedef long long LL;
  4. using namespace std;
  5. const int SIZE = 1e6+10;
  6. LL rating[SIZE];
  7. bool lose[SIZE];
  8. int main(){
  9.     int N,M;
  10.     scanf("%d%d",&N,&M);
  11.     for(int i=1;i<=N;i++){
  12.         int x;
  13.         scanf("%d",&x);
  14.         rating[i]=x;
  15.     }
  16.     set<pair<LL,int> >H;
  17.     for(int i=1;i<=N;i++){
  18.         if(rating[i]>=rating[1])H.insert(MP(rating[i],i));
  19.         else lose[i]=1;
  20.     }
  21.     for(int i=0;i<M;i++){
  22.         int k;
  23.         scanf("%d",&k);
  24.         for(int j=0;j<k;j++){
  25.             int p,d;
  26.             scanf("%d%d",&p,&d);
  27.             if(!lose[p]){
  28.                 H.erase(H.find(MP(rating[p],p)));
  29.                 rating[p]+=d;
  30.                 H.insert(MP(rating[p],p));
  31.             }
  32.         }
  33.         while(H.begin()->second!=1){
  34.             lose[H.begin()->second]=1;
  35.             H.erase(H.begin());
  36.         }
  37.     }
  38.     printf("%d\\n",(int)H.size()-1);
  39.     return 0;
  40. }
');