C language · Split apples

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.