View Code of Problem 5

#include <stdio.h>

int main() {
    int t,n,m;
    int i,j,k;
    int a,b;
    long int temp;
    long int f[100000],cp[100000];
    int index[100000];
    scanf("%d",&t);
    while (t>0) {
        scanf("%d %d",&n,&m);
        for(i=0;i<n;i++) {
            scanf("%d %d",&a,&b);
            f[i] = a*100000+b;
            cp[i] = f[i];

        }

        int count = 0;
        for(i=0;i<n;i++) {
            for(j=i;j<n;j++) {
                if(cp[j]>cp[i]) {
                    temp = cp[i];
                    cp[i] = cp[j];
                    cp[j] = temp;
                }
            }
            long int max = cp[i];
            
            for(k=0;k<n;k++) {
                if (max == f[k]) {
                    index[count] = k;
                    count++;
                    break;
                }
            }
        }
        for(i=0;i<m;i++) {
            printf("%d",index[i]+1);
            if (i !=m-1) {
                printf(" ");
            }
        }
        printf("\n");
        t--;
    }
    
    return 0;
}

Double click to view unformatted code.


Back to problem 5