poj3664Election Time
来源:互联网 发布:javascript 闭包 编辑:程序博客网 时间:2024/06/06 06:16
Description
The cows are having their first election after overthrowing the tyrannical Farmer John, and Bessie is one ofN 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 theAi 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 andBi
Output
* Line 1: The index of the cow that is expected to win the election.
Sample Input
5 33 109 25 68 46 5
Sample Output
5
Source
#include"stdio.h"#include"cstring"#include"iostream"#include"algorithm"using namespace std;struct node{int a;int b;int flag;}vote[50005];bool cmp(const node &a1,const node &a2){return a1.a<a2.a;}int main(int argc, char* argv[]){ int n,k;int i,j,max,temp;max=0;while(cin>>n>>k){for(i=1;i<=n;i++){cin>>vote[i].a>>vote[i].b;vote[i].flag=i;}sort(vote+1,vote+n+1,cmp);for(j=n;j>n-k;j--){if(vote[j].b>max){max=vote[j].b;temp=vote[j].flag;}}cout<<temp<<endl;}return 0;}
- poj3664Election Time
- time
- time
- TIME
- Time
- TIME
- Time
- time
- Time
- time
- time
- time
- time
- Time
- TIME
- time
- time
- Time
- 16 PHP 数组排序函数
- 一些定义
- 1057. Stack
- JavaScript经典代码【二】【FLASH中调用JS方法】
- android 常用adb命令
- poj3664Election Time
- 【HihoCoder】最长回文子串
- Struts2返回JSON数据的具体应用范例
- android账号与同步之同步实现
- 学习笔记
- 番茄插件常用快捷键
- sql server unique index 开启 ignore_dup_key 去除重复数据
- Spring+ibatis示例
- java.lang.UnsupportedClassVersionError: Bad version number in .class file