There are empty candy jars, numbered from 1 to , with infinite capacity. M operations are performed. Each operation is described by 3 integers and . Here, and are index of the jars, and is the number of candies to be added inside each jar whose index lies between and (both inclusive). Can you tell the average number of candies after operations?
The first line contains two integers N and M separated by a single space.
M lines follow. Each of the M lines contain three integers a, b and k separated by single space.
A single line containing the average number of candies across N jars, rounded down to the nearest integer.
Rounded down means finding the greatest integer which is less than or equal to given number. Eg, 13.65 and 13.23 is rounded down to 13, while 12.98 is rounded down to 12.
3 <= N <= 10000000
1 <= M <= 100000
1 <= a <= b <= N
0 <= k <= 1000000
1 4 100
2 3 50
balls initially in 4 jars 0,0,0,0
1st operation -> 100,100,100,100
average = 500/4=125
@line = split(" ",$line1);
$n = $line;
$m = $line;
if($n<3 or $n>10000000 or $m<1 or $m>100000)
$output = 0;
chomp($line2 = <STDIN>);
@op = split(" ",$line2);
if($op<1 or $op>$op or $op<1 or $op>$n or $op<0 or
$output = $output/$n;
$output = int $output;
Use int $string to round off to nearest interger, note 6.67 will return 6 and not 7.