poj——3664——Election Time

阅读: 评论:0

poj——3664——Election Time

poj——3664——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

#include<iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int n,k;
const int M=50010;
struct node
{int a;int b;int num;
}Node[M];
int cmpa(node a,node b)
{if(a.a!=b.a)return a.a>b.a;elsereturn a.b>b.b;
}
int cmpb(node a,node b)
{if(a.b!=b.b)return a.b>b.b;elsereturn a.a>b.a;
}
int main()
{while(cin>>n>>k){for(int i=0;i<n;i++){scanf("%d%d", &Node[i].a, &Node[i].b);Node[i].num=i+1;}sort(Node,Node+n,cmpa);sort(Node,Node+k,cmpb);printf("%dn",Node[0].num);}return 0;
} 


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

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

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

上一篇:冬季集训1.22
下一篇:Election Time
标签:poj   Time   Election
留言与评论(共有 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