#include <stdio.h> #include <stdlib.h> using namespace std; typedef struct thing{ int apple; int peer; int index; }; int cmp( const void *a, const void *b ){ thing *pa = (thing *)a; thing *pb = (thing *)b; if( pa->apple == pb->apple){ if( pa->peer == pb->peer){ return pa->index - pa->index; } return pa->peer < pb->peer; } return (*(thing *)a).apple<(*(thing *)b).apple; } int main(){ int t; int n,m; int a,b; scanf("%d", &t ); while(t--){ scanf("%d %d", &n, &m); thing th[n]; for( int i=0; i<n; i++ ){ scanf("%d%d", &th[i].apple,&th[i].peer); th[i].index = i+1; } qsort(th,n,sizeof(thing),cmp); for( int i=0; i<m-1; i++ ){ printf("%d ", th[i].index); } printf("%d\n", th[m-1].index); } return 0; } |
Double click to view unformatted code.