Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
Observar que dice: "output one line per car, in the same order as the input" Imprimir la respueta de cada auto en el mismo orden de entrada
Input:
1
2 2 4
0 left
1 left
2 right
3 left
Ouput:
2
6
4
6
**/
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;
struct car{
int time,pos;
};
queue<car> I, D;
int c,n,t,m,aux,p,t2,s, sal[10005];//s => side 0 iz, 1 der
string si;
int main(){
scanf("%d",&c);
//cout<<I.front();
while(c--){
scanf("%d %d %d",&n,&t,&m);
int x=0;
int mx=m;
while(mx--){
scanf("%d",&aux);
cin>>si;
car ax;
ax.pos=x;
ax.time=aux;
if(si=="left")
I.push(ax);
else
D.push(ax);
x++;
}
t2=s=0;
while(!I.empty() || !D.empty()){
if(s){//der
if(D.size()>0 && (D.front().time<=I.front().time || I.size()==0 ||D.front().time<=t2) ){
t2=max(t2, D.front().time);
for(int i=0;i<n&&D.size()!=0&&D.front().time<=t2;i++){
sal[D.front().pos]=t2+t;
D.pop();
}
}
else if(I.front().time<D.front().time || D.empty()){
t2= max(I.front().time, t2);
}
s=(s+1)%2;
t2+=t;
}
else{//izq
if(I.size()>0 && (I.front().time<=D.front().time || D.size()==0 ||I.front().time<=t2) ){
// cout<<t2<<endl;
t2=max(t2, I.front().time);
for(int i=0;i<n&&I.size()!=0&&I.front().time<=t2;i++){
sal[I.front().pos]=t2+t;
I.pop();
}
}
else if(D.front().time<I.front().time || I.empty()){
t2= max(D.front().time, t2);
}
s=(s+1)%2;
t2+=t;
}
}
for(int i=0;i<m;i++){
printf("%d\n",sal[i]);
}
if(c>0)
printf("\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.