PTA 1014 Waiting in Line
6400 단어 PTA 몇 년 못 가는 테스트 포인트.
#include
using namespace std;
struct que{
vector<int>pel;
vector<int>index;
}q[20];
int ans[1005],ask[1005];
int main(){
int n,m,k,qe;
cin>>n>>m>>k>>qe;
for(int i=1;i<=k;i++){
cin>>ask[i];
}
memset(ans,-1,sizeof(ans));
//ans
//
int consumer=1;
for(int i=1,j=0;i<=k;i++,j=(j+1)%n,consumer++){
if((q[j].pel.size()==m)&&(j==0))
break;
// cout<<q[j].pel.size()<if(q[j].index.size()==0){
ans[i]=0;
}else{
//
int tmpindex=q[j].index[q[j].index.size()-1];
ans[i]=ans[tmpindex]+ask[tmpindex];
// cout<q[j].pel.push_back(ask[i]);
q[j].index.push_back(i);
}
//
for(int i=1;i<=540;i++){
for(int j=0;j//
if(q[j].pel.size()==0)
continue;
q[j].pel[0]= q[j].pel[0]-1;
if(q[j].pel[0]==0){// ,
vector<int>::iterator it =q[j].pel.begin();
q[j].pel.erase(it);
it=q[j].index.begin();
int tmpindex = *it;
q[j].index.erase(it);
if(consumer<=k){//
if(q[j].index.size()==0){
ans[consumer]=ans[tmpindex]+ask[tmpindex];
}else{
//
int frontindex=q[j].index[q[j].index.size()-1];
ans[consumer]=ans[frontindex]+ask[frontindex];
}
q[j].pel.push_back(ask[consumer]);
q[j].index.push_back(consumer);
consumer++;
}else{
continue;
}
}
}
}
for(int i=0;iint qer;
cin>>qer;
if(ans[qer]==-1||ans[qer]>=540)// 5
cout<<"Sorry
";
else{
int hour=8+(ans[qer]+ask[qer])/60,mini=(ans[qer]+ask[qer])%60;
printf("%02d:%02d
",hour,mini);
}
}
return 0;
}