1004

 

Election Time

Time Limit:3000MS  Memory Limit:65536K
Total Submit:49 Accepted:25

Description

The cows are having their first election after overthrowing the tyrannical Farmer John, and Bessie is one of N cows(1<= N <=50,000) running for President. Before the election actually happens,however, Bessie wants to determine who has the best chance of winning.

The election consists of two rounds. In the first round, the K cows (1 <= K <= N) cows with the most votes advance to the second round.In the second round, the cow with the most votes becomes President.

Given that cow i expects to get A_i votes (1 <= A_i <= 1,000,000,000)in the first round and B_i votes (1 <= B_i <=1,000,000,000) in the second round (if he or she makes it), determine which cow is expected to win the election. Happily for you, no vote count appears twice in the A_i list; likewise, no vote count appears twice in the B_i list.

Input

* Line 1: Two space-separated integers: N and K

* Lines 2..N+1: Line i+1 contains two space-separated integers: A_i and B_i

Output

* Line 1: The index of the cow that is expected to win the election.

Sample Input

5 3
3 10
9 2
5 6
8 4
6 5

Sample Output

5
 
     这个题目的意思是通过两次投票,选举总统,第一次投票选出票数最多的k人,
第二次,在选出的k人中再进行投票,票数最高的为总统。
     本题只需两次调用qsort()函数即可。代码如下:
 
#include<stdio.h>
#include<stdlib.h>

struct node
{
    int x;
    int y;
    int num;  
}a[51000];
int comp(const void *a,const void *b)
{
    return (*(node *)a).x<(*(node *)b).x?1:-1;
}
int cmp(const void *a,const void *b)
{
    return (*(node *)a).y<(*(node *)b).y?1:-1;
}
int main()
{
    int m,k,i;
    scanf("%d%d",&m,&k);
    for(i=0;i<m;i++)
    {
        scanf("%d%d",&a[i].x,&a[i].y);
        a[i].num=i+1;
    }
    qsort(a,m,sizeof(a[0]),comp);
    qsort(a,k,sizeof(a[0]),cmp);
    printf("%d/n",a[0].num);
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值