#include<iostream>using namespace std;int s,w,c,k,m;int heap[11000];int times, totaltime;void heapwork(int id){ int lkid=id<<1, rkid=(id<<1)+1, root=id; if(lkid<=k && heap[lkid]<heap[root]) root=lkid; if(rkid<=k && heap[rkid]<heap[root]) root=rkid; if(root!=id) { swap(heap[root], heap[id]); heapwork(root); }}int main(){ while(cin>>s) { cin>>w>>c>>k>>m; totaltime=0; times=9999/c+1; if(k>times) k=times; for(int i=1; i<=k; ++i) heap[i]=m*i+s; for(int i=1; i<=times; ++i) { if(totaltime< heap[1]) totaltime=heap[1]; totaltime+=w; heap[1]+=s+s+w; heapwork(1); } totaltime+=s; cout<<totaltime<<endl; } return 0;}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)