#include<iostream> #include<cstdio> #include<cstring> #include<queue> #define db(a) cout << #a << " = " << a << endl; #define foreach(it,l) for (typeof(l.begin()) it = l.begin(); it != l.end(); it++) using namespace std; int main() { int c, l, m, val, cap = 0, cont = 0; char direccion[20]; scanf("%d", &c); for (int k = 0; k < c; k++) { queueleft, right; scanf("%d %d", &l, &m); l *= 100; for (int i = 0; i < m; i++) { scanf("%d %s", &val, direccion); if(strcmp(direccion,"left") == 0) left.push(val); else right.push(val); } cont = cap = 0; string ini = "left"; while (!left.empty() || !right.empty()) { if (ini == "left") { cap = 0; while (!left.empty() && cap + left.front() <= l) { //printf("left %d\n", time + t); cap += left.front(); left.pop(); } ini = "right"; cont++; } else { cap = 0; while (!right.empty() && cap + right.front() <= l) { //printf("right %d\n", time + t); cap += right.front(); right.pop(); } ini = "left"; cont++; } } printf("%d\n", cont); } return 0; }
martes, 25 de octubre de 2011
11034 - Ferry Loading IV, uva
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario