Election Time

阅读: 评论:0

Election Time

Election Time

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 Ai votes (1 ≤ Ai ≤ 1,000,000,000) in the first round and Bi votes (1 ≤ Bi ≤ 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 Ai list; likewise, no vote count appears twice in the Bi list.

Input

  • Line 1: Two space-separated integers: N and K
  • Lines 2..N+1: Line i+1 contains two space-separated integers: Ai and Bi

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
HINT

题意:有n头牛,第一列表示第一轮Ai的投票,第二列表示第二轮Bi的投票,在第一轮排名前k的可以进入第二轮,然后在第二轮找最大的票数,输出牛的序号即可

第一列从大到小排序,在第二列前k个里找个最大的。over

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<stdlib.h>
#include<algorithm>
#define sf(a)   scanf("%d",&a)
#define sff(a,b)   scanf("%d %d",&a,&b)
#define pf(ans)   printf("%dn",ans)
using namespace std;
const int M=50000+10;
struct node
{int Ai;int Bi;int sub;
} nod[M+50];
bool cmp(struct node p,struct node q)
{return p.Ai>q.Ai;
}
int main()
{int n,k;sff(n,k);int i;for(i=1; i<=n; i++){sff(nod[i].Ai,nod[i].Bi);nod[i].sub=i;}sort(nod+1,nod+n+1,cmp);int Max=0,sub=0;for(i=1; i<=k; i++){if(nod[i].Bi>Max){Max=nod[i].Bi;sub=nod[i].sub;}}pf(sub);
}

本文发布于:2024-02-27 18:00:31,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/1709109499114090.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:Election   Time
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23