Untitled
unknown
c_cpp
a year ago
819 B
5
Indexable
#include <bits/stdc++.h> using i64 = long long; void solve() { int n; std::cin >> n; i64 ans = 0; std::vector<std::pair<int, int>> l(n); for (int i = 0; i < n; i++) { int a, b; std::cin >> a >> b; l[i] = {a, -b}; } std::sort(l.begin(), l.end()); int cnt = 0; for (int i = 0, j = 0; i < n; i++) { if (i >= j) { cnt++; ans += -l[i].second; } while (j < n && l[j].first <= cnt) { j++; } cnt = std::max(0, i + 1 - j); } std::cout << ans << "\n"; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int t; std::cin >> t; while (t--) { solve(); } return 0; }
Editor is loading...
Leave a Comment