POJ 3664 Election Time

Election Time

Time Limit: 1000MS Memory Limit: 65536K

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

思路:

先对Ai排序,然后再规定k内的元素找最大,然后输出。

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 50010;
struct Cow {
    int a;
    int b;
    int id;
    bool friend operator < (Cow a, Cow b) {
        return a.a > b.a;
    }
};
Cow cow[maxn];
int main() {
    ios::sync_with_stdio(false);
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &cow[i].a, &cow[i].b);
        cow[i].id = i + 1;
    }
    sort(cow, cow + n);
    int k = 0, Max = 0;
    for (int i = 0; i < m; i++) {
        if (Max < cow[i].b) {
            k = i;
            Max = cow[i].b;
        }
    }
    printf("%d", cow[k].id);
    return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值