ABC337(A-C)

A

#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int suma=0;
  int sumb=0;
  int a,b;
  while(n--){
    cin>>a>>b;
    suma+=a;
    sumb+=b;
  }
  if(suma>sumb)cout<<"Takahashi"<<endl;
  else if(suma<sumb)cout<<"Aoki"<<endl;
  else if(suma==sumb)cout<<"Draw"<<endl;
  return 0;
}

B

#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  string s0=s;
  for(auto i:s){
    if(i!='A'&&i!='B'&&i!='C'){
        cout<<"No"<<endl;
        return 0;
    }
  }
sort(s.begin(),s.end());
if(s0==s)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}  

C

#include<bits/stdc++.h>
using namespace std;
struct people{
    int id;
    int num;
};
bool cmp(people a,people b){
    return a.num<b.num;
}
int finds(people a[],int size,int key){
    int low = 0; 
    int high = size-1; 
    int mid;
    while(low <= high)    
    {
      mid = low+(high-low>>1);     
      if(key < a[mid].num)           
          high = mid-1;            
      else if(key > a[mid].num)     
          low = mid+1;            
      else                         
          return mid;
        }
    return -1;              
}

int main()
{
    int n;
    cin>>n;
    people a[n];
    int key;
    for(int i=0;i<n;i++){
        a[i].id=i+1;
        cin>>a[i].num;
        if(a[i].num==-1)key=a[i].id;
    }
    cout<<key<<" ";
    sort(a,a+n,cmp);
    int n0=n-1;
    while(n0--){
        key=a[finds(a,n,key)].id;
        cout<<key<<" ";
    }
return 0;
}