View Code of Problem 5

#include<iostream>
using namespace std;

int main(){
  int t;
  while(t<=10&&t>0){
    int n,m;
    cin>>n>>m;
    int a[n][2];
    int k;
    for(int i=0;i<n;i++){
      cin>>a[i][0]>>a[i][1];
    }
    for(int i=0;i<m;i++){
      int temp = -1;
      for(int j=0;j<n;j++){
        if(a[j][0]>temp){
          temp = a[j][0];
          k = j;
        }
      }
      for(int j=0;j<n;j++){
        if(a[j][0]==temp){
          if(a[j][1]>a[k][1])
            k = j;
          else if(a[j][1]==a[k][1]){
            if(j < k)
              k = j;
          }
        }
      }
      return k;
    } 
  }
}

Double click to view unformatted code.


Back to problem 5