my idea:

Split a client into 365 parts, each indicates the debt at the day.Then I read the input and add the debt between invoice and receipt.

e.g. client 1 has 5000 3 9

then I add 5000 from day[3] to day[8].

Then just to sum the total and sum the over-bounded risk, divide , output.

Code: Select all

```
#include<stdio.h>
typedef struct client
{
int upperbound;
int day[367];/*remember, these sould be interval*/
}client;
int main()
{
int i,j,k;
int casenum, clientnum, buynum, recnum;
int s,e;
int price;
long long total, out;
client c[100];
scanf("%d",&casenum);
for(;casenum > 0;casenum--)
{
scanf("%d",&clientnum);
for(i=0;i<clientnum;i++)
for(j=0;j<367;j++)
c[i].day[j] = 0;
total = out = 0;
for(i=0;i<clientnum;i++)
{
scanf("%d %d",&c[i].upperbound, &recnum);
for(j=0;j<recnum;j++)
{
scanf("%d %d %d",&price,&s,&e);
for(k=s;k<e;k++)
c[i].day[k] += price;
}
}
for(i=0;i<clientnum;i++)
for(j=0;j<367;j++)
{
total += c[i].day[j];
if(c[i].day[j] > c[i].upperbound)
out += (c[i].day[j] - c[i].upperbound);
}
printf("%.2f%%",100.0 * (double)((double)out / (double)total));
if(casenum > 1)
printf("\n\n");
}
return 0;
}
```