Election Time

xiaoxiao2021-02-28  63

#include <cstdio> #include <algorithm> using namespace std; struct cow { int vote1; int vote2; int id; bool operator < (const cow& A) const { return this->vote1 < A.vote1; } } cow[50050]; int main() { int n,k; scanf("%d %d",&n,&k); for(int i =0 ;i<n;i++) { int v1,v2; scanf("%d %d",&v1,&v2); cow[i].id=i+1; cow[i].vote1=v1; cow[i].vote2=v2; } sort(cow,cow+n); int maxCow=0,maxId=0; for(int i = n-1;i>=n-k;i--) { if(cow[i].vote2>maxCow) { maxCow=cow[i].vote2; maxId=cow[i].id; } } printf("%d",maxId); }
转载请注明原文地址: https://www.6miu.com/read-49639.html

最新回复(0)