-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFillingJars.cs
More file actions
51 lines (40 loc) · 1.35 KB
/
FillingJars.cs
File metadata and controls
51 lines (40 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HackerrankSolution
{
public class FillingJars
{
static long solve(int n, int[][] operations)
{ long sum = 0;
for(long i=0; i<operations.Length; i++)
{
long a = operations[i][0];
long b = operations[i][1];
long k = operations[i][2];
sum += (b - a + 1) * k;
}
long res = sum / n;
return res;
}
public static void Execute()
{
TextWriter textWriter = new StreamWriter(Environment.CurrentDirectory + "\\output.txt", false);
string[] nm = Console.ReadLine().Split(' ');
int n = Convert.ToInt32(nm[0]);
int m = Convert.ToInt32(nm[1]);
int[][] operations = new int[m][];
for (int operationsRowItr = 0; operationsRowItr < m; operationsRowItr++)
{
operations[operationsRowItr] = Array.ConvertAll(Console.ReadLine().Split(' '), operationsTemp => Convert.ToInt32(operationsTemp));
}
long result = solve(n, operations);
textWriter.WriteLine(result);
textWriter.Flush();
textWriter.Close();
}
}
}