#include<iostream>
#include<cstdio>
using namespace std;
const int maxn=10000;
int a[15],b[15],c[15],d[15];
int n,sleep,awake,all[15];
int solve()
{
int t=1;
while(t<maxn)
{
sleep=0;
for(int i=0; i<n; i++)
if(d[i]==0) sleep++;
awake=n-sleep;
if(awake==n) return t;
for(int i=0; i<n; i++)
{
if(c[i]==a[i])
{
if(sleep<=awake)
{
d[i]=1;
c[i]=1;
}
else
{
c[i]++;
d[i]=0;
}
}
else if(c[i]==all[i])
{
d[i]=1;
c[i]=1;
}
else
c[i]++;
}
t++;
}
return -1;
}
int main()
{
int cas=1;
while(scanf("%d",&n)!=EOF&&n)
{
for(int i=0; i<n; i++)
{
scanf("%d%d%d",&a[i],&b[i],&c[i]);
if(c[i]<=a[i]) d[i]=1;
else d[i]=0;
all[i]=a[i]+b[i];
}
printf("Case %d: %d\n",cas++,solve());
}
return 0;
}
UVA 12108(p98)----Extraordinary Tired Students
最新推荐文章于 2019-07-19 16:10:25 发布