public void Solve() { int x, y; ReadMulti(out x, out y); Ll list = new Ll(); if (x <= y) { list.Add(y - x); } if (-x <= y) { list.Add(y + x + 1); } if (x <= -y) { list.Add(-y - x + 1); } if (-x <= -y) { list.Add(-y - (-x) + 2); } list.Min().WL(); return; }
public void Solve() { int N = NextInt(), K = NextInt(); var X = new Ll(); var Y = new Ll(); var list = new List <Tuple <long, long> >(); N.REP(i => { int xi = NextInt(), yi = NextInt(); X.Add(xi); Y.Add(yi); list.Add(new Tuple <long, long>(xi, yi)); }); X.Sort(); Y.Sort(); var min = long.MaxValue; for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { for (int k = 0; k < N; k++) { for (var l = k + 1; l < N; l++) { var left = X[i]; var right = X[j]; var top = Y[k]; var bottom = Y[l]; var count = list.Count(tuple => tuple.Item1 >= left && tuple.Item1 <= right && tuple.Item2 >= top && tuple.Item2 <= bottom); if (count >= K) { min = Min(min, Abs(right - left) * Abs(top - bottom)); } } } } } min.WL(); return; }
public void Solve() { //ABC 075 D int N = NextInt(), K = NextInt(); var X = new Ll(); var Y = new Ll(); var list = new List <Tuple <long, long> >(); N.REP(i => { long xi = NextLong(), yi = NextLong(); X.Add(xi); Y.Add(yi); list.Add(xi, yi); }); X.Sort(); Y.Sort(); var min = long.MaxValue; for (int i = 0; i < N; i++) { var lx = X[i]; for (int j = i + 1; j < N; j++) { var rx = X[j]; for (int k = 0; k < N; k++) { var ty = Y[k]; for (int l = k + 1; l < N; l++) { var by = Y[l]; if (list.Count(x => lx <= x.Item1 && x.Item1 <= rx && ty <= x.Item2 && x.Item2 <= by) < K) { continue; } min = Min(Abs(rx - lx) * Abs(by - ty), min); } } } } min.WL(); }
public void Solve() { int N = NextInt(), A = NextInt(), B = NextInt(); var h = new Ll(); N.REP(i => h.Add(NextLong())); Func <int, bool> predicate = (K) => { var cnt = K; foreach (var item in h.Select(x => x - B * K).Where(x => x > 0)) { var c = (int)Ceiling((double)item / (A - B)); if (cnt >= c) { cnt -= c; } else { return(false); } } return(true); }; var r = (int)h.Max() / B; var l = 0; while (l <= r) { var mid = (r + l) / 2; if (predicate(mid)) { r = mid - 1; } else { l = mid + 1; } } (predicate(r)?r:l).WL(); return; }
public void Solve() { int N = NextInt(), K = NextInt(); var xList = new Ll(); var yList = new Ll(); var list = new List <Vector2 <long> >(); N.REP(i => { var x = NextLong(); var y = NextLong(); xList.Add(x); yList.Add(y); list.Add(new Vector2 <long>(x, y)); }); xList = xList.OrderBy(_ => _).ToList(); yList = yList.OrderBy(_ => _).ToList(); var ans = (yList[N - 1] - yList[0]) * (xList[N - 1] - xList[0]); for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { for (int k = 0; k < N; k++) { for (int l = k + 1; l < N; l++) { long lx = xList[i], rx = xList[j], by = yList[k], uy = yList[l]; var cnt = list.Count(_ => lx <= _.X && _.X <= rx && by <= _.Y && _.Y <= uy); if (cnt >= K) { ans = Min(ans, (rx - lx) * (uy - by)); } } } } } ans.WL(); return; }
public void Solve() { var N = NextInt(); var cnt = 0L; var A = new Ll(); var B = new Ll(); N.REP(i => { A.Add(NextLong()); B.Add(NextLong()); }); for (var i = N - 1; i >= 0; i--) { var d = (long)Ceiling((double)(A[i] + cnt) / B[i]); var diff = d * B[i] - (A[i] + cnt); cnt += diff; } cnt.WL(); }
static void Main(string[] args) { string A, B, C, D, E, F, G, H; string Aa, Bb, Cc, Dd, Ee, Ff, Gg, Hh, Ii, Jj, Kk, Ll, Mm, Nn, Oo; String[] ArrStr = new String[7]; A = "Rizky Khapidsyah"; B = "Nama Saya : "; C = A.Insert(0, B); D = " itu siapa?"; E = A.Insert(16, D); F = "Ini Adalah: "; G = "Hari Rabu"; H = G.Replace("Rabu", "Jum'at"); ArrStr[0] = "Senin"; ArrStr[1] = "Selasa"; ArrStr[2] = "Rabu"; ArrStr[3] = "Kamis"; ArrStr[4] = "Jum'at"; ArrStr[5] = "Sabtu"; ArrStr[6] = "Minggu"; /* Saya Sengaja tidak menggunakan variabel array untuk bagian ini (Aa, Bb, Cc dst..), agar kebih mudah dipahami. * Namun lebih disarankan menggunakan array dan statement for jika bekerja di lingkungan komersil */ Aa = ", "; Bb = "."; Cc = Bb.Insert(0, ArrStr[6]); Dd = Cc.Insert(0, Aa); Ee = Dd.Insert(0, ArrStr[5]); Ff = Ee.Insert(0, Aa); Gg = Ff.Insert(0, ArrStr[4]); Hh = Gg.Insert(0, Aa); Ii = Hh.Insert(0, ArrStr[3]); Jj = Ii.Insert(0, Aa); Kk = Jj.Insert(0, ArrStr[2]); Ll = Kk.Insert(0, Aa); Mm = Ll.Insert(0, ArrStr[1]); Nn = Mm.Insert(0, Aa); Oo = Nn.Insert(0, ArrStr[0]); Console.WriteLine(A); Console.WriteLine(A.Length); Console.WriteLine(A.IndexOf('p')); Console.WriteLine(A[9]); Console.WriteLine(C); Console.WriteLine(E); Console.WriteLine(Oo); Console.WriteLine(F, G); Console.WriteLine(H); if (!H.Contains("Kamis")) { Console.WriteLine("Tidak Ditemukan Hari: Kamis"); } else { Console.WriteLine("Ditemukan Hari: Kamis"); } H = H.Remove(2); Console.WriteLine(H); Console.ReadLine(); }