华为4月13晚笔试
第二题代码。过了25%,不知道哪里错了,求个大佬帮忙看看!!!!
#华为笔试##华为##实习##笔试题目#// 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; }