Skip to content

Instantly share code, notes, and snippets.

@GuruRAM
Last active March 8, 2019 16:56
Show Gist options
  • Select an option

  • Save GuruRAM/887a4bb002400da14e8bafeaf729c597 to your computer and use it in GitHub Desktop.

Select an option

Save GuruRAM/887a4bb002400da14e8bafeaf729c597 to your computer and use it in GitHub Desktop.
Array Manipulation
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System;
class Solution {
// Complete the arrayManipulation function below.
static long arrayManipulation(int n, int[][] queries)
{
var input = queries.SelectMany(query => new[] {
new InputItem
{
Border = query[0],
Type = 0,
Increment = query[2]
},
new InputItem
{
Border = query[1],
Type = 1,
Increment = -query[2]
}
}).OrderBy(i => i.Border).ThenBy(i => i.Type);
var current = 0L;
var max = 0L;
foreach(var element in input)
{
current += element.Increment;
max = Math.Max(max, current);
}
return max;
}
public class InputItem
{
public int Border;
public int Type;
public int Increment;
}
static void Main(string[] args) {
TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);
string[] nm = Console.ReadLine().Split(' ');
int n = Convert.ToInt32(nm[0]);
int m = Convert.ToInt32(nm[1]);
int[][] queries = new int[m][];
for (int i = 0; i < m; i++) {
queries[i] = Array.ConvertAll(Console.ReadLine().Split(' '), queriesTemp => Convert.ToInt32(queriesTemp));
}
long result = arrayManipulation(n, queries);
textWriter.WriteLine(result);
textWriter.Flush();
textWriter.Close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment