// we have defined the necessary header files here for this problem. // If additional header files are needed in your program, please import here. #include<bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int ans = 0; vector<pair<int, int>> tmp; for(int i = 0; i < n; ++i){ int a, b; cin >> a >> b; tmp.push_back(make_pair(a, b)); } sort(tmp.begin(), tmp.end(), [](pair<int, int>&; a, pair<int, int>&; b){ return a.first == b.first ? a.second > b.second : a.first < b.first; }); int start = 0; for(int i = 1; i <= 7 * 105 &;&; start < n; ++i){ for(int j = start; j < n; ++j){ if(tmp[j].first >= i){ ans += tmp[j].second; start = j + 1; break; } } } cout << ans; return 0; } 第二题25%,不知道哪里有问题
1 2

相关推荐

点赞 评论 收藏
分享
牛客网
牛客企业服务