
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
Output
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小时内删除。
| 留言与评论(共有 0 条评论) |