#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> vec;
long long sum = 0;
while (n--) {
int a, b;
cin >> a >> b;
if (b == 0) sum += a;
else vec.push_back(a);
}
sort(vec.begin(), vec.end());
for (int i = vec.size() - 1; i >= 0; i--) {
if (vec[i] > sum) sum+=vec[i];
else sum *= 2;
}
cout << sum << endl;
}
全部评论
(0) 回帖