fork(1) download
  1. #include <bits/stdc++.h>
  2. #define S second
  3. #define F first
  4. #define MP make_pair
  5. int const N=100001;
  6. using namespace std;
  7. priority_queue<int>q;
  8. int t[N];
  9. int main() {
  10. ios_base::sync_with_stdio(0);
  11. cin.tie(0);
  12. int n,a,b,wyn=0;
  13. cin>>n;
  14. for(int i=0;i<n-1;i++){
  15. cin>>a>>b;
  16. if(a==1) q.push(-1*b);
  17. else{
  18. if(b<=q.size()){
  19. while(b<=q.size()){
  20. q.pop();
  21. }
  22. }
  23. }
  24. }
  25. cin>>a>>b;
  26. if(q.size()>=b){
  27. while(!q.empty()){
  28. wyn-=q.top();
  29. q.pop();
  30. }
  31. cout<<wyn;
  32. }
  33. else cout<<-1;
  34. }
Success #stdin #stdout 0.01s 5284KB
stdin
5
1 10
1 12
0 2
1 1
0 3
stdout
-1