Election Time

编程入门 行业动态 更新时间:2024-10-18 06:04:14

<a href=https://www.elefans.com/category/jswz/34/1761098.html style=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("%d\n",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);
}

更多推荐

Election Time

本文发布于:2024-02-27 18:00:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1707665.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Election   Time

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!