forked from NemrudDemir/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
49 lines (37 loc) · 1.42 KB
/
Solution.cs
File metadata and controls
49 lines (37 loc) · 1.42 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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution {
static int getMoneySpent(int[] keyboards, int[] drives, int b) {
var result = -1;
foreach(var keyboard in keyboards) { //TODO improve(?)
if(keyboard >= b)
continue;
foreach(var drive in drives) {
var total = keyboard + drive;
if(total <= b && total > result)
result = total;
}
}
return result;
}
static void Main(string[] args) {
TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);
string[] bnm = Console.ReadLine().Split(' ');
int b = Convert.ToInt32(bnm[0]);
int n = Convert.ToInt32(bnm[1]);
int m = Convert.ToInt32(bnm[2]);
int[] keyboards = Array.ConvertAll(Console.ReadLine().Split(' '), keyboardsTemp => Convert.ToInt32(keyboardsTemp))
;
int[] drives = Array.ConvertAll(Console.ReadLine().Split(' '), drivesTemp => Convert.ToInt32(drivesTemp))
;
/*
* The maximum amount of money she can spend on a keyboard and USB drive, or -1 if she can't purchase both items
*/
int moneySpent = getMoneySpent(keyboards, drives, b);
textWriter.WriteLine(moneySpent);
textWriter.Flush();
textWriter.Close();
}
}