Algorithm to increase the time limit of Apple split: 1.0s memory limit: 256.0MBThe problem description The children lined up in a row and the teacher divided the apples.
Children from left to right label 1. N. There are m teachers, each time the first teacher will give the first Li to the first RI, a total of ri-li+1 children each hair ci an apple.
Finally, the teacher wants to know how many apples each child has. Input format the first line of two integers n, M, indicating the number of children and the number of teachers.
Next M-line, three integers per line Li, Ri, Ci, meaning as the topic is expressed. The output format is a row of n, and the number I indicates is the fruit on the hand of the child. Sample Input 5 3
1 2 1
2 3 2
2 5 3 Sample Output 1 6 5 3 3 Data size and convention 40% data, N, M≤1 000.
100% of data, N, m≤100 000,1≤li≤ri≤n,0≤ci≤100. Run time-out to full decomposition.
1#include <stdio.h>2 intMain () {3 intn,m;4 intl,r,c;5scanf"%d%d",&n,&m);6 intapple[100005]={0};//record the number of apples per child7 for(intj=1; j<=m;j++){8scanf"%d%d%d",&l,&r,&c);9 for(inti=l;i<=r;i++){Tenapple[i]+=C; One } A } - for(intI=1; i<=n;i++){ -printf"%d", Apple[i]); the } - return 0; -}
C language · Split apples