Sort by

recency

|

200 Discussions

|

  • + 0 comments

    !/bin/python3

    import math import os import random import re import sys

    def solve(n, operations): count = 0 for i in range(m): l = operations[i] a = l[0] b = l[1] k = l[2] count += (b-a+1)*k return count//n

    if name == 'main': fptr = open(os.environ['OUTPUT_PATH'], 'w')

    first_multiple_input = input().rstrip().split()
    
    n = int(first_multiple_input[0])
    
    m = int(first_multiple_input[1])
    
    operations = []
    
    for _ in range(m):
        operations.append(list(map(int, input().rstrip().split())))
    
    result = solve(n, operations)
    
    fptr.write(str(result) + '\n')
    
    fptr.close()
    
  • + 0 comments

    what is wrong with c++ solution why all the test cases are not passing

  • + 0 comments
    def solve(n, operations):
        count=0
        for operation in operations:
                count+=operation[2] *(operation[1]-operation[0]+1)
        return math.floor(count/n)
    
  • + 1 comment

    For C++ solution change the return type of solve function to long long and also type of result variable in main function from where solve is being called.

  • + 0 comments

    Java int array [ ] = new int[n]; for(List operation: operations){ int a = operation.get[0]-1; int b = operation.get[1]-1; int k = operation.get[2]; for(int i=a; i<=b; i++){ array[i]+= k; } }

                    int sum =0;
                                        for(int i=0 i<n; i++){
                    sum+= array[i];
    }
    return Math.round(sum/n);
    
    
    
    
    
    }