Please optimize this code

                                     problem name-Recruit Villagers
                                      difficulty rating -1270

#include

using namespace std;

int main() {
// your code goes here
int n;
cin>>n;
int m,x;
cin>>m>>x;
int arr[n][3];
for(int i=0;i<n;i++){
for(int j=0;j<3;j++){
cin>>arr[i][j];
}
}
int temp0,temp1,temp2;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(arr[i][2]>arr[j][2]){

          temp0=arr[i][0];
          temp1=arr[i][1];
          temp2=arr[i][2];
          
          arr[i][0]=arr[j][0];
          arr[i][1]=arr[j][1];
          arr[i][2]=arr[j][2];
          
          arr[j][0]=temp0;
          arr[j][1]=temp1;
          arr[j][2]=temp2;
          
      }
  }

}
for(int i=n-1;i>=0;i–){
if(arr[i][1]!=m*arr[i][0]+x){
cout<<arr[i][2]<<endl;
break;
}
}
return 0;
}