1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| #include<iostream> #include<algorithm> #include<vector> using namespace std;
bool cmp(vector<int> x,vector<int> y) { if(x[0] < y[0]) return true; if(x[0] == y[0]) if(x[1] > y[1]) return true; return false; }
int main() { int m; cin >> m; vector<vector<int>> table(m,vector<int>(2,0)); int max, before_gg = 0, after_w = 0; for(int i = 0;i < m;i++) { cin >> table[i][0] >> table[i][1]; if(table[i][1] == 1) after_w++; } sort(table.begin(),table.end(),cmp); double chance,chance_m = 0; for(int i = 0;i<m;i++) { chance = (before_gg+after_w)/double(m); if(chance >=chance_m) { chance_m = chance; max = table[i][0]; } if(table[i][1] == 0) before_gg++; if(table[i][1] == 1) after_w--; } cout << max << endl; return 0; }
|