Advertisement
Ahmed_Negm

Untitled

May 3rd, 2022
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include<iostream>
  3. #include<cmath>
  4. #include<iomanip>
  5. #include<algorithm>
  6. #include<cstdlib>
  7. #include<cstring>
  8. #include<vector>
  9. #include<utility>
  10. using namespace std;
  11.  
  12. #define ll long long
  13. #define nl '\n'
  14. #define sz(x) int(x.size())
  15. #define all(x) x.begin(),x.end()
  16. #define rall(s)  s.rbegin(), s.rend()
  17. #define getline(s) getline(cin>>ws,s)
  18. #define ceill(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  19. /*
  20. ███╗░░██╗███████╗░██████╗░███╗░░░███╗
  21. ████╗░██║██╔════╝██╔════╝░████╗░████║
  22. ██╔██╗██║█████╗░░██║░░██╗░██╔████╔██║
  23. ██║╚████║██╔══╝░░██║░░╚██╗██║╚██╔╝██║
  24. ██║░╚███║███████╗╚██████╔╝██║░╚═╝░██║
  25. ╚═╝░░╚══╝╚══════╝░╚═════╝░╚═╝░░░░░╚═╝
  26.  
  27. */
  28.  
  29. void Fast_IO(){
  30.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  31.     #ifndef ONLINE_JUDGE
  32.         freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  33.     #endif
  34. }
  35.  
  36.  
  37.  
  38.  
  39.  
  40. void solve(){
  41. ll n; cin>>n;
  42. multiset<ll,greater<ll>>neg;
  43. ll counter =0;
  44. ll sum =0;
  45. while(n--){
  46.     ll x; cin>>x;
  47.     if(x<0) neg.emplace(x);
  48.     else {
  49.         sum += x;
  50.         counter++;
  51.     }
  52. }
  53. for(auto &x:neg){
  54.     if(sum + x >= 0){
  55.         sum+=x;
  56.         counter++;
  57.     }else break;
  58. }
  59. cout<<counter;
  60.  
  61.  
  62. }
  63.  
  64. int main(){
  65.     Fast_IO();
  66. int t =1;
  67. //cin>>t;
  68. while(t--){
  69. solve();
  70. }
  71. return 0;
  72. }  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement