You are viewing a single comment's thread. Return to all comments →
import java.io.; import java.math.; import java.text.; import java.util.; import java.util.regex.*;
public class Solution {
// Complete the solve function below. static BigInteger solve(int n, int[][] operations) { long arr[]=new long[n]; BigInteger temp=new BigInteger("0"); BigInteger sum=new BigInteger("0"); for(int i=0;i<operations.length;i++) { long a=operations[i][0]-1; long b=operations[i][1]-1; long c=operations[i][2]; long num=b-a+1; temp=BigInteger.valueOf(num); temp=temp.multiply(BigInteger.valueOf(c)); sum=sum.add(temp); } /* for(int i=0;i<arr.length;i++) sum+=arr[i];*/ BigInteger avg=sum.divide(BigInteger.valueOf(n)); return avg; } private static final Scanner scanner = new Scanner(System.in); public static void main(String[] args) throws IOException { BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); String[] nm = scanner.nextLine().split(" "); int n = Integer.parseInt(nm[0]); int m = Integer.parseInt(nm[1]); int[][] operations = new int[m][3]; for (int operationsRowItr = 0; operationsRowItr < m; operationsRowItr++) { String[] operationsRowItems = scanner.nextLine().split(" "); scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); for (int operationsColumnItr = 0; operationsColumnItr < 3; operationsColumnItr++) { int operationsItem = Integer.parseInt(operationsRowItems[operationsColumnItr]); operations[operationsRowItr][operationsColumnItr] = operationsItem; } } BigInteger result = solve(n, operations); bufferedWriter.write(String.valueOf(result)); bufferedWriter.newLine(); bufferedWriter.close(); scanner.close(); }
} //Just changed return type to BigInteger and all test cases passed.
Filling Jars
You are viewing a single comment's thread. Return to all comments →
import java.io.; import java.math.; import java.text.; import java.util.; import java.util.regex.*;
public class Solution {
} //Just changed return type to BigInteger and all test cases passed.