Last active
December 25, 2015 19:51
-
-
Save AndreyBespamyatnov/358450d1f8a7d6dfc613 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1) we will be create new array, lenght = max floor | |
2) we will add to index (if exist by number of floow) value of person time | |
3) read array from right to left | |
4) in cicle (current index of cicle as "floow") | |
4.1) if current vlue == 0, then incriminate result and continue | |
4.2) if it is firs floow, maybe we need to wite, add current value and continue | |
4.3) if curent value GREAT that result, then add value by formula (result = curent value - result) | |
4.4) otherwise/else, just incriminate result | |
that it) | |
code: | |
using System; | |
public class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string[] n_temp = Console.ReadLine().Split(' '); | |
int n = Convert.ToInt32(n_temp[0]); | |
int s = Convert.ToInt32(n_temp[1]); | |
int[][] a = new int[n][]; | |
for (int a_i = 0; a_i < n; a_i++) | |
{ | |
string[] a_temp = Console.ReadLine().Split(' '); | |
a[a_i] = Array.ConvertAll(a_temp, Int32.Parse); | |
} | |
int[] workArray = new int[s + 1]; | |
Array.Sort(a, (ints, ints1) => ints[0].CompareTo(ints1[0])); | |
for (int i = 0; i < a.Length; i++) | |
{ | |
workArray[a[i][0]] = Math.Max(workArray[a[i][0]], a[i][1]); | |
} | |
// Console.WriteLine(Math.Max(s, a.Max(ints => ints[0] + ints[1]))); hack, but need more memmory | |
int result = 0; | |
for (int floow = workArray.Length -1; floow >= 0; floow--) | |
{ | |
if (workArray[floow] == 0) | |
{ | |
result++; | |
continue; | |
} | |
if (floow == s) | |
{ | |
result += workArray[floow]; | |
} | |
else if (workArray[floow] > result) | |
{ | |
result += workArray[floow] - result; | |
} | |
else if (workArray[floow] == floow) | |
{ | |
continue; | |
} | |
else | |
{ | |
result++; | |
} | |
} | |
Console.WriteLine(result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment