SHARE
TWEET

bleachifnoarena

a guest Nov 9th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <fstream>
  2. #include <vector>
  3. #include <queue>
  4.    
  5. using namespace std;
  6.    
  7. ifstream f("bleach.in");
  8. ofstream g("bleach.out");
  9.    
  10. priority_queue<int,vector<int>,greater<int>> pq;
  11. int n,k,s=0,minn=0,x;
  12.    
  13. int main()
  14. {
  15.     f>>n>>k;
  16.     k++;
  17.     for(int i=0;i<k;i++)
  18.     {
  19.         f>>x;
  20.         pq.push(x);
  21.     }
  22.     minn=pq.top();
  23.     s=minn;
  24.     for(int i=1;i<n;i++)
  25.     {
  26.         pq.pop();
  27.         f>>x;
  28.         pq.push(x);
  29.         if(pq.top()<=minn+s)
  30.             s+=pq.top();
  31.         else
  32.         {
  33.             s=pq.top();
  34.             minn=s;
  35.         }
  36.     }
  37.     g<<minn;
  38.     return 0;
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top