-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathElectronics Shop - Hackerrank Solution
More file actions
62 lines (51 loc) · 1.37 KB
/
Copy pathElectronics Shop - Hackerrank Solution
File metadata and controls
62 lines (51 loc) · 1.37 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
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution {
static void Main(String[] args) {
string[] tokens_s = Console.ReadLine().Split();
int s = int.Parse(tokens_s[0]);
int n = int.Parse(tokens_s[1]);
int m = int.Parse(tokens_s[2]);
string[] key = Console.ReadLine().Split();
int[] keyb = Array.ConvertAll(key,int.Parse);
string[] drive = Console.ReadLine().Split();
int[] usb = Array.ConvertAll(drive,int.Parse);
int [] arr = new int[m*n];
int e=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
arr[e]= keyb [i]+ usb[j];
e++;
}
}
int [] brr = new int[m*n];
for(int q=0;q<m*n;q++)
{
brr[q] = s-arr[q];
}
int ch = 100000000,p=0;
for(int i=0;i<m*n;i++)
{
if(brr[i]>=0)
{
if(brr[i]<ch)
{
ch = brr[i];
p=i;
}
}
}
if(ch==100000000)
{
Console.WriteLine("-1");
}
if(ch != 100000000)
{
Console.WriteLine("{0}",arr[p]);
}
}
}