This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int LIMIT=(200000*2)+5;
int level[LIMIT];
int Objetivos, Rounds;
vector<pair<int,int>> Campo;
int bucket[LIMIT];
int bucle(){
  int c1 = 0; bool myArcher=0;
  for(int i=0;i<2*Objetivos;i++){
    if(i == 0){
        if(Campo[i].first == 1) c1 ++;
        if(Campo[i].second == 1) c1++;
        if(Campo[i].first==level[1] || Campo[i].second==level[1]) myArcher=1;
    }else{
      if(Campo[i].first)c1++;
      if(Campo[i].second)c1++;
      if(Campo[i].first==level[1] || Campo[i].second==level[1]) myArcher=1;
    }
    if(c1 > 1){
      Campo.push_back(make_pair(1,0));
      c1--;
    } else if(c1 == 1){
      if(myArcher){
        Campo.push_back(make_pair(level[1],0));
        myArcher=0;
        if(i+1 >= Objetivos) return (Objetivos - ((Rounds - i+1) % Objetivos));
      }else{
        Campo.push_back(make_pair(0, 0));
      }
    }else{
      Campo.push_back(make_pair(0, 0));
    }
  }
}
int nobucle(){
  for(int i=0;i<=Objetivos;i++){
    bucket[i]=0;
  }
  int pos=0;
  for(int i=0;i<Objetivos;i++){
    if(Campo[i].first==0) bucket[i+1]++;
    if(Campo[i].second==0) bucket[i+1]++;
    if(Campo[i].first==level[1] || Campo[i].second==level[1])pos=i+1; 
  }
  int c0=bucket[1];
  bool myArcher=0;
  bucket[1]=0;
  if(pos==1) myArcher=1;
  for(int i=Objetivos;i>=2;i--){
    if(pos==i)myArcher=1;
    if(bucket[i]==0 && c0==0 && myArcher){
      pos=i;
      myArcher=0;
    }else if(bucket[i]==0 && c0!=0){
      c0--;
      bucket[i]++;
    }else if(bucket[i]>0){
      c0+=bucket[i]-1;
      bucket[i]=1;
    }
  }
  c0=bucket[1];
  myArcher=0;
   if(pos==1) myArcher=1;
  bucket[1]=0;
  for(int i=Objetivos;i>=2;i--){
    if(pos==i)myArcher=1;
    if(bucket[i]==0 && c0==0 && myArcher){
      pos=i;
      myArcher=0;
    }else if(bucket[i]==0 && c0!=0){
      c0--;
      bucket[i]++;
    }else if(bucket[i]>0){
      c0+=bucket[i]-1;
      bucket[i]=1;
    }
  }
  return pos;
}
int solve(int ini){
  Campo.clear();
  bool x,y;
  for(int i=2, j=1; i<=2*Objetivos;i+=2,j++){
    x=(level[i]<level[1])?1:0;
    y=(level[i+1]<level[1])?1:0;
    if(j==ini){ 
      Campo.push_back(make_pair(x,level[1]));
      i--;
    }else Campo.push_back(make_pair(x,y));
  }
  int z=0;
  if(level[1]<=Objetivos+1){
    z=bucle();
  }else{
    z=nobucle();
  }
  return z;
}
int main(){
  ios_base::sync_with_stdio(0);cin.tie();
  cin>>Objetivos>>Rounds;
  for(int i=1;i<=Objetivos*2;i++){
    cin>>level[i];
  }
  int res,mpos,pos;
  for(int i=1;i<=Objetivos;i++){
    pos=solve(i);
    if(mpos>=pos){
      mpos=pos;
      res=i;
    }
  }
  cout<<res;
}
Compilation message (stderr)
archery.cpp: In function 'int bucle()':
archery.cpp:35:1: warning: control reaches end of non-void function [-Wreturn-type]
   35 | }
      | ^
archery.cpp: In function 'int main()':
archery.cpp:115:9: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
  115 |   cout<<res;
      |         ^~~
archery.cpp:110:5: warning: 'mpos' may be used uninitialized in this function [-Wmaybe-uninitialized]
  110 |     if(mpos>=pos){
      |     ^~| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |