Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <vector>
- #include <queue>
- using namespace std;
- ifstream f("bleach.in");
- ofstream g("bleach.out");
- priority_queue<int,vector<int>,greater<int>> pq;
- int n,k,s=0,minn=0,x;
- int main()
- {
- f>>n>>k;
- k++;
- for(int i=0;i<k;i++)
- {
- f>>x;
- pq.push(x);
- }
- minn=pq.top();
- s=minn;
- for(int i=1;i<n;i++)
- {
- pq.pop();
- f>>x;
- pq.push(x);
- if(pq.top()<=minn+s)
- s+=pq.top();
- else
- {
- s=pq.top();
- minn=s;
- }
- }
- g<<minn;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement