WA #10 It's urgent that you help me
Posted by
basted 29 Jan 2008 00:20
What's wrong?
#include <stdio.h>
#include <stdlib.h>
int n,x,s;
typedef struct{
int t1,t2,t3;
}st;
st t[110];
int max(int a,int b){
if(a>b)return a;
else return b;
}
int cmp(const void *a,const void *b){
const st *c=(st *)a, *d=(st *)b;
return c->t1 - d->t1;
}
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d %d %d",&t[i].t1,&t[i].t2,&t[i].t3);
}
qsort(t,n,sizeof(st),cmp);
for(int i=0;i<n;i++){
t[i].t1=max(t[i].t1,x);
x=t[i].t1 + t[i].t2;
s+=max(0,x-t[i].t3);
}
printf("%d\n",s);
return 0;
}