buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
using System; using System.Collections.Generic; using System.Linq; namespace Atcoder { class Program { static void Main(string[] args) { // var a = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); long x = int.Parse(Console.ReadLine()); long x500; long mod; long x5; long ans; if (x >= 500) { x500 = x / 500; mod = x % 500; x5 = mod / 5; ans = x500 * 1000 + x5 * 5; } else ans = 0; Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; namespace Atcoder { class Program { static void Main(string[] args) { // var a = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); long x = int.Parse(Console.ReadLine()); long x500; long mod; long x5; long ans; if (x >= 5) { x500 = x / 500; mod = x % 500; x5 = mod / 5; ans = x500 * 1000 + x5 * 5; } else ans = 0; Console.WriteLine(ans); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
8
109
2
using System; using System.Collections.Generic; using System.Numerics; using System.Linq; using static System.Math; class MainClass { public static void Main(string[] args) { var x = LnInt(); var a = (x % 500); var n500 = x / 500; var n5 = a / 5 * 5; Console.WriteLine(n500 + n5); } public static long Gcd(long a, long b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } } public static int Gcd(int a, int b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } } public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; } public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); } public static long[] LnLngs() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new long[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = long.Parse(vs[i]); return ins; } public static long LnLng() { var vs = Console.ReadLine().Trim(); return long.Parse(vs); } public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; } public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; } }
using System; using System.Collections.Generic; using System.Numerics; using System.Linq; using static System.Math; class MainClass { public static void Main(string[] args) { var x = LnLng(); var a = (x % 500); var n500 = x / 500 * 1000; var n5 = a / 5 * 5; Console.WriteLine(n500 + n5); } public static long Gcd(long a, long b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } } public static int Gcd(int a, int b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } } public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; } public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); } public static long[] LnLngs() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new long[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = long.Parse(vs[i]); return ins; } public static long LnLng() { var vs = Console.ReadLine().Trim(); return long.Parse(vs); } public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; } public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; } }
[["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
523
4
using System; namespace AtCoder { class MainClass { public static void Main(string[] args) { int input = int.Parse(Console.ReadLine()); int bigcoin = input % 500; input = input - 500 * bigcoin; int smallcoin = input % 5; Console.WriteLine(1000 * bigcoin + 5 * smallcoin); } } }
using System; namespace AtCoder { class MainClass { public static void Main(string[] args) { int input = int.Parse(Console.ReadLine()); int bigcoin = input / 500; input = input - 500 * bigcoin; int smallcoin = input / 5; Console.WriteLine(1000 * bigcoin + 5 * smallcoin); } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85]]
8
72
4
using System; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public static void Main(string[] args) { new B().test(); } } public class B { public void test() { // 普通の文字列取得 // 英語小文字のみ long input = CommonRead.ReadLong(); var fiveHundred = 500; // 5はそのまま long five = 5; long returnValue = 0; long returnAmari = 0; // 500は二倍にする returnValue = Convert.ToInt32(Math.Floor((decimal)input / fiveHundred)) * 1000; returnAmari = input - Convert.ToInt32(Math.Ceiling((decimal)input / fiveHundred)) * 500; returnValue += Convert.ToInt32(Math.Ceiling((decimal)returnAmari / five)) * 5; //出力 Console.WriteLine(returnValue); } } static class CommonRead { public static string ReadStr() { return Console.ReadLine(); } public static string[] ReadStrA() { return ReadStr().Split(' '); } public static List<string> ReadStrL() { return ReadStrA().ToList(); } public static int ReadInt() { return Convert.ToInt32(ReadStr()); } public static int[] ReadIntA() { return ReadStrA().Select(s => Convert.ToInt32(s)).ToArray(); } public static List<int> ReadIntL() { return ReadStrA().Select(s => Convert.ToInt32(s)).ToList(); } public static long ReadLong() { return Convert.ToInt64(ReadStr()); } public static long[] ReadLongA() { return ReadStrA().Select(s => Convert.ToInt64(s)).ToArray(); } public static List<long> ReadLongL() { return ReadStrA().Select(s => Convert.ToInt64(s)).ToList(); } public static decimal ReadDecimal() { return Convert.ToDecimal(ReadStr()); } public static decimal[] ReadDecimalA() { return ReadStrA().Select(s => Convert.ToDecimal(s)).ToArray(); } public static List<decimal> ReadDecimalL() { return ReadStrA().Select(s => Convert.ToDecimal(s)).ToList(); } public static double ReadDouble() { return Convert.ToDouble(ReadStr()); } public static double[] ReadDoubleA() { return ReadStrA().Select(s => Convert.ToDouble(s)).ToArray(); } public static List<double> ReadDoubleL() { return ReadStrA().Select(s => Convert.ToDouble(s)).ToList(); } }
using System; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public static void Main(string[] args) { new B().test(); } } public class B { public void test() { // 普通の文字列取得 // 英語小文字のみ long input = CommonRead.ReadLong(); var fiveHundred = 500; // 5はそのまま long five = 5; long returnValue = 0; long returnAmari = 0; // 500は二倍にする returnValue = Convert.ToInt32(Math.Floor((decimal)input / fiveHundred)) * 1000; returnAmari = input - Convert.ToInt32(Math.Floor((decimal)input / fiveHundred)) * 500; returnValue += Convert.ToInt32(Math.Floor((decimal)returnAmari / five)) * 5; //出力 Console.WriteLine(returnValue); } } static class CommonRead { public static string ReadStr() { return Console.ReadLine(); } public static string[] ReadStrA() { return ReadStr().Split(' '); } public static List<string> ReadStrL() { return ReadStrA().ToList(); } public static int ReadInt() { return Convert.ToInt32(ReadStr()); } public static int[] ReadIntA() { return ReadStrA().Select(s => Convert.ToInt32(s)).ToArray(); } public static List<int> ReadIntL() { return ReadStrA().Select(s => Convert.ToInt32(s)).ToList(); } public static long ReadLong() { return Convert.ToInt64(ReadStr()); } public static long[] ReadLongA() { return ReadStrA().Select(s => Convert.ToInt64(s)).ToArray(); } public static List<long> ReadLongL() { return ReadStrA().Select(s => Convert.ToInt64(s)).ToList(); } public static decimal ReadDecimal() { return Convert.ToDecimal(ReadStr()); } public static decimal[] ReadDecimalA() { return ReadStrA().Select(s => Convert.ToDecimal(s)).ToArray(); } public static List<decimal> ReadDecimalL() { return ReadStrA().Select(s => Convert.ToDecimal(s)).ToList(); } public static double ReadDouble() { return Convert.ToDouble(ReadStr()); } public static double[] ReadDoubleA() { return ReadStrA().Select(s => Convert.ToDouble(s)).ToArray(); } public static List<double> ReadDoubleL() { return ReadStrA().Select(s => Convert.ToDouble(s)).ToList(); } }
[["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22]]
8
550
4
using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { hoge(); // System.Console.ReadLine(); } public static void hoge() { var kane = System.Console.ReadLine().Split(' ').Select(long.Parse).ToArray()[0]; long big = kane / 500; kane = kane % 500; kane = kane % 100; long small = kane / 5; System.Console.WriteLine(big * 1000 + small * 5); } }
using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { hoge(); // System.Console.ReadLine(); } public static void hoge() { var kane = System.Console.ReadLine().Split(' ').Select(long.Parse).ToArray()[0]; long big = kane / 500; kane = kane % 500; long small = kane / 5; System.Console.WriteLine(big * 1000 + small * 5); } }
[["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
111
6
using System; using System.Collections.Generic; using System.IO.Pipes; namespace cswork { class Program { class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next(); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } public Program() {} static void Main(string[] args) { new Program().Omame(); } Scanner cin; const int MAXIN = 1024; bool[] used = new bool[MAXIN]; int[] perm = new int[MAXIN]; List<int[]> permList = new List<int[]>(); public void Permutation(int pos, int n, int length) { if (pos == n) { permList.Add((int[])perm.Clone()); } for (int i = 0; i < n; i++) { if (!used[i]) { perm[pos] = i; used[i] = true; Permutation(pos + 1, n, length); used[i] = false; } } } void Omame() { cin = new Scanner(); int K = cin.nextInt(); int N = cin.nextInt(); List<int> list = new List<int>(); for (int i = 0; i < N; i++) { list.Add(cin.nextInt()); } long ans = list[N - 1] - list[0]; for (int i = 1; i < N; i++) { long tmpAns = list[i] + K - list[i - 1]; ans = Math.Min(ans, tmpAns); } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.IO.Pipes; namespace cswork { class Program { class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next(); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } public Program() {} static void Main(string[] args) { new Program().Omame(); } Scanner cin; const int MAXIN = 1024; bool[] used = new bool[MAXIN]; int[] perm = new int[MAXIN]; List<int[]> permList = new List<int[]>(); public void Permutation(int pos, int n, int length) { if (pos == n) { permList.Add((int[])perm.Clone()); } for (int i = 0; i < n; i++) { if (!used[i]) { perm[pos] = i; used[i] = true; Permutation(pos + 1, n, length); used[i] = false; } } } void Omame() { cin = new Scanner(); int K = cin.nextInt(); int N = cin.nextInt(); List<int> list = new List<int>(); for (int i = 0; i < N; i++) { list.Add(cin.nextInt()); } long ans = list[N - 1] - list[0]; for (int i = 1; i < N; i++) { long tmpAns = list[i - 1] + K - list[i]; ans = Math.Min(ans, tmpAns); } Console.WriteLine(ans); } } }
[["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
499
4
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder.Contests.ABC160 { /// <summary> /// /// </summary> static class C { static void Main(string[] args) { var k = NextInt(); var n = NextInt(); var aas = ReadIntArray(); var zero = k - aas[n - 1] + aas[0]; for (int i = 1; i < n; i++) { aas[i] -= aas[i - 1]; } aas[0] = zero; Console.WriteLine(k - aas.Max()); } #region Console static int _index = 0; static string[] _buffer; static string Next() { if (_buffer == null || _index >= _buffer.Length) { _buffer = Console.ReadLine().Split(); _index = 0; } return _buffer[_index++]; } static int NextInt() { return int.Parse(Next()); } static long NextLong() { return long.Parse(Next()); } static int ReadInt() { return int.Parse(Console.ReadLine()); } static long ReadLong() { return long.Parse(Console.ReadLine()); } static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static int[] ReadIntArray(int n) { var a = new int[n]; for (int i = 0; i < n; i++) { a[i] = ReadInt(); } return a; } static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static long[] ReadLongArray(int n) { var a = new long[n]; for (int i = 0; i < n; i++) { a[i] = ReadLong(); } return a; } static List<T> ReadObjects<T>(int n, Func<int[], T> creator) { var l = new List<T>(n); for (int i = 0; i < n; i++) { var a = ReadIntArray(); l.Add(creator(a)); } return l; } static int[,] ReadMatrix(int n, int m) { var r = new int[n, m]; for (int i = 0; i < n; i++) { var a = ReadIntArray(); for (int j = 0; j < m; j++) { r[i, j] = a[j]; } } return r; } #endregion } }
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder.Contests.ABC160 { /// <summary> /// /// </summary> static class C { static void Main(string[] args) { var k = NextInt(); var n = NextInt(); var aas = ReadIntArray(); var zero = k - aas[n - 1] + aas[0]; for (int i = n - 1; i >= 1; i--) { aas[i] -= aas[i - 1]; } aas[0] = zero; Console.WriteLine(k - aas.Max()); } #region Console static int _index = 0; static string[] _buffer; static string Next() { if (_buffer == null || _index >= _buffer.Length) { _buffer = Console.ReadLine().Split(); _index = 0; } return _buffer[_index++]; } static int NextInt() { return int.Parse(Next()); } static long NextLong() { return long.Parse(Next()); } static int ReadInt() { return int.Parse(Console.ReadLine()); } static long ReadLong() { return long.Parse(Console.ReadLine()); } static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static int[] ReadIntArray(int n) { var a = new int[n]; for (int i = 0; i < n; i++) { a[i] = ReadInt(); } return a; } static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static long[] ReadLongArray(int n) { var a = new long[n]; for (int i = 0; i < n; i++) { a[i] = ReadLong(); } return a; } static List<T> ReadObjects<T>(int n, Func<int[], T> creator) { var l = new List<T>(n); for (int i = 0; i < n; i++) { var a = ReadIntArray(); l.Add(creator(a)); } return l; } static int[,] ReadMatrix(int n, int m) { var r = new int[n, m]; for (int i = 0; i < n; i++) { var a = ReadIntArray(); for (int j = 0; j < m; j++) { r[i, j] = a[j]; } } return r; } #endregion } }
[["+", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68]]
8
578
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder_solve { class Program { public const ulong mod = 1000000007; static void Main(string[] args) { var kn = Input3(); var a = Input3(); long[] d = new long[kn[1]]; long ans = 0; for (long i = 0; i < kn[1] - 1; i++) { d[i] = a[i + 1] - a[i]; } d[kn[1] - 1] = kn[0] - a[kn[1] - 1]; Array.Sort(d); ans = kn[0] - d[kn[1] - 1]; Console.WriteLine(ans); } static public long Input() { return long.Parse(Console.ReadLine()); } static public string[] Input2() { return Console.ReadLine().Split(); } static public long[] Input3() { string[] data = Console.ReadLine().Split(); long[] res = new long[data.LongLength]; for (long i = 0; i < data.LongLength; i++) { res[i] = long.Parse(data[i]); } return res; } public static long Choose(long n, long a) { long x = 1; long y = 1; for (long i = 0; i < a; i++) { x *= n - i; y *= i + 1; } return x / y; } public static long Gcd(long a, long b) { long x = Math.Max(a, b); long y = Math.Min(a, b); if (x % y == 0) return y; else return Gcd(y, x % y); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder_solve { class Program { public const ulong mod = 1000000007; static void Main(string[] args) { var kn = Input3(); var a = Input3(); long[] d = new long[kn[1]]; long ans = 0; for (long i = 0; i < kn[1] - 1; i++) { d[i] = a[i + 1] - a[i]; } d[kn[1] - 1] = kn[0] - a[kn[1] - 1] + a[0]; Array.Sort(d); ans = kn[0] - d[kn[1] - 1]; Console.WriteLine(ans); } static public long Input() { return long.Parse(Console.ReadLine()); } static public string[] Input2() { return Console.ReadLine().Split(); } static public long[] Input3() { string[] data = Console.ReadLine().Split(); long[] res = new long[data.LongLength]; for (long i = 0; i < data.LongLength; i++) { res[i] = long.Parse(data[i]); } return res; } public static long Choose(long n, long a) { long x = 1; long y = 1; for (long i = 0; i < a; i++) { x *= n - i; y *= i + 1; } return x / y; } public static long Gcd(long a, long b) { long x = Math.Max(a, b); long y = Math.Min(a, b); if (x % y == 0) return y; else return Gcd(y, x % y); } } }
[["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 16, 12, 204, 205, 22], ["+", 0, 11, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 11, 12, 16, 12, 204, 206, 207, 0, 73]]
8
410
5
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; using System.Numerics; namespace abc160 { class Program { static void Main(string[] args) { if (File.Exists("input.txt")) { Console.SetIn(new StreamReader("input.txt")); } solve_abc160C(); } public static void solve_abc160C() { int[] kn = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int k = kn[0]; int n = kn[1]; int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int max = 0; int prev = 0; for (int i = 0; i < n; i++) { max = Math.Max(max, Math.Abs(prev - a[i])); prev = a[i]; } max = Math.Max(max, k - a[n - 1] + a[0]); Console.WriteLine(max); } public static void solve_abc160B() { int x = Convert.ToInt32(Console.ReadLine()); int a = x / 500; int r = x % 500; int b = r / 5; Console.WriteLine(a * 1000 + b * 5); } public static void solve_abc160A() { string s = Console.ReadLine(); Console.WriteLine(s[2] == s[3] && s[4] == s[5] ? "Yes" : "No"); } } }
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; using System.Numerics; namespace abc160 { class Program { static void Main(string[] args) { if (File.Exists("input.txt")) { Console.SetIn(new StreamReader("input.txt")); } solve_abc160C(); } public static void solve_abc160C() { int[] kn = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int k = kn[0]; int n = kn[1]; int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int max = 0; int prev = 0; for (int i = 0; i < n; i++) { max = Math.Max(max, Math.Abs(prev - a[i])); prev = a[i]; } max = Math.Max(max, k - a[n - 1] + a[0]); Console.WriteLine(k - max); } public static void solve_abc160B() { int x = Convert.ToInt32(Console.ReadLine()); int a = x / 500; int r = x % 500; int b = r / 5; Console.WriteLine(a * 1000 + b * 5); } public static void solve_abc160A() { string s = Console.ReadLine(); Console.WriteLine(s[2] == s[3] && s[4] == s[5] ? "Yes" : "No"); } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33]]
8
341
2
using System; namespace AtCoder { class MainClass { public static void Main() { string[] input1 = Console.ReadLine().Split(' '); int K = int.Parse(input1[0]); int N = int.Parse(input1[1]); string[] input2 = Console.ReadLine().Split(' '); int[] points = new int[N]; for (int i = 1; i <= N; i++) { points[i - 1] = int.Parse(input2[i - 1]); } int longest = points[0]; for (int j = 0; j <= N - 1; j++) { int distance = points[j + 1] - points[j]; if (distance > longest) { longest = distance; } } int last = K - points[N - 1]; if (last > longest) { longest = last; } Console.WriteLine(K - longest); } } }
using System; namespace AtCoder { class MainClass { public static void Main() { string[] input1 = Console.ReadLine().Split(' '); int K = int.Parse(input1[0]); int N = int.Parse(input1[1]); string[] input2 = Console.ReadLine().Split(' '); int[] points = new int[N]; for (int i = 1; i <= N; i++) { points[i - 1] = int.Parse(input2[i - 1]); } int longest = points[0]; for (int j = 0; j <= N - 2; j++) { int distance = points[j + 1] - points[j]; if (distance > longest) { longest = distance; } } int last = K - points[N - 1] + points[0]; if (last > longest) { longest = last; } Console.WriteLine(K - longest); } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 0, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 200, 0, 212, 0, 16, 12, 204, 205, 22], ["+", 0, 212, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
8
213
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_Training { public class Program { static void Main(string[] args) { var kn = Console.ReadLine().Split(' '); var k = int.Parse(kn[0]); var n = int.Parse(kn[1]); var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var ans = k - a[n - 1] + a[0]; for (int i = 1; i < n; i++) { ans = Math.Max(ans, a[i] - a[i - 1]); } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_Training { public class Program { static void Main(string[] args) { var kn = Console.ReadLine().Split(' '); var k = int.Parse(kn[0]); var n = int.Parse(kn[1]); var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var diffamax = k - a[n - 1] + a[0]; for (int i = 1; i < n; i++) { diffamax = Math.Max(diffamax, a[i] - a[i - 1]); } Console.WriteLine(k - diffamax); } } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
177
10
using System; using System.Linq; class TSAL { static void Main(string[] args) { int tmp; string[] input = Console.ReadLine().Split(' '); int k = int.Parse(input[0]); int n = int.Parse(input[1]); int[] a = Console.ReadLine().Split(' ').Select((x) => int.Parse(x)).ToArray(); int maxD = a[0] + a[n - 1] - k; for (int i = 1; i < a.Length; i++) { tmp = a[i] - a[i - 1]; if (maxD < tmp) { maxD = tmp; } } Console.WriteLine(k - maxD); } }
using System; using System.Linq; class TSAL { static void Main(string[] args) { int tmp; string[] input = Console.ReadLine().Split(' '); int k = int.Parse(input[0]); int n = int.Parse(input[1]); int[] a = Console.ReadLine().Split(' ').Select((x) => int.Parse(x)).ToArray(); int maxD = a[0] - a[n - 1] + k; for (int i = 1; i < a.Length; i++) { tmp = a[i] - a[i - 1]; if (maxD < tmp) { maxD = tmp; } } Console.WriteLine(k - maxD); } }
[["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 72], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 33], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72]]
8
176
4
using System; using static System.Console; using System.Linq; using System.Collections.Generic; namespace Main { class Program { static void Main(string[] args) { string[] tmp = ReadLine().Split(' '); int K = int.Parse(tmp[0]); int N = int.Parse(tmp[1]); string[] tmp2 = ReadLine().Split(' '); List<int> A = new List<int>(); for (int i = 0; i < N; i++) { A.Add(int.Parse(tmp2[i])); } List<int> B = new List<int>(); for (int i = 0; i < N; i++) { B.Add(A[i + 1] - A[i]); } B.Add(K - A[N] + A[0]); Write(K - B.Max()); } } }
using System; using static System.Console; using System.Linq; using System.Collections.Generic; namespace Main { class Program { static void Main(string[] args) { string[] tmp = ReadLine().Split(' '); int K = int.Parse(tmp[0]); int N = int.Parse(tmp[1]); string[] tmp2 = ReadLine().Split(' '); List<int> A = new List<int>(); for (int i = 0; i < N; i++) { A.Add(int.Parse(tmp2[i])); } List<int> B = new List<int>(); for (int i = 0; i < N - 1; i++) { B.Add(A[i + 1] - A[i]); } B.Add(K - A[N - 1] + A[0]); Write(K - B.Max()); } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
218
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { // 湖の距離と家の数 var input = Console.ReadLine().Split(' '); var numArray = input.Select(x => int.Parse(x)).ToArray(); // 家のそれぞれの距離 var houseDistance = Console.ReadLine().Split(' '); var houseDistanceArray = houseDistance.Select(x => int.Parse(x)).ToArray(); var houseDistanceList = new List<int>(houseDistanceArray); // 家間の距離を求める var distanceList = new List<int>(); for (var i = 0; i < numArray[1]; i++) { if (i + 1 == numArray[1]) { distanceList.Add(numArray[0] - houseDistanceList[i]); } else { distanceList.Add(houseDistanceList[i + 1] - houseDistanceList[i]); } } // 並べ替え distanceList.Sort(); // 全部の家を回る最短距離を求める var result = 0; for (int i = 0; i < numArray[1] - 1; i++) { result += distanceList[i]; } Console.WriteLine(result); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { // 湖の距離と家の数 var input = Console.ReadLine().Split(' '); var numArray = input.Select(x => int.Parse(x)).ToArray(); // 家のそれぞれの距離 var houseDistance = Console.ReadLine().Split(' '); var houseDistanceArray = houseDistance.Select(x => int.Parse(x)).ToArray(); var houseDistanceList = new List<int>(houseDistanceArray); // 家間の距離を求める var distanceList = new List<int>(); for (var i = 0; i < numArray[1]; i++) { if (i + 1 == numArray[1]) { distanceList.Add(numArray[0] + houseDistanceList[0] - houseDistanceList[i]); } else { distanceList.Add(houseDistanceList[i + 1] - houseDistanceList[i]); } } // 並べ替え distanceList.Sort(); // 全部の家を回る最短距離を求める var result = 0; for (var i = 0; i < numArray[1] - 1; i++) { result += distanceList[i]; } Console.WriteLine(result); } }
[["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["+", 0, 28, 0, 16, 31, 16, 12, 204, 205, 22], ["+", 0, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 39, 216, 0, 217]]
8
257
7
using System; using System.Collections.Generic; using System.Linq; namespace AtCoderCs { class Program { static void Main() { var Arg = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var House = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var Result = Arg[0] - House[House.Length - 1] + House[1]; for (int i = 1; i < House.Length; i++) { if (House[i] - House[i - 1] > Result) Result = House[i] - House[i - 1]; } Console.WriteLine(Arg[0] - Result); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoderCs { class Program { static void Main() { var Arg = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var House = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var Result = Arg[0] - House[House.Length - 1] + House[0]; for (int i = 1; i < House.Length; i++) { if (House[i] - House[i - 1] > Result) Result = House[i] - House[i - 1]; } Console.WriteLine(Arg[0] - Result); } } }
[["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
8
176
2
using System; using System.IO; namespace abc160_1 { class Program { static void Main(string[] args) { Console.SetIn(new StreamReader(Console.OpenStandardInput(1000000))); var first = Console.ReadLine().Trim().Split(' '); var k = int.Parse(first[0]); var n = int.Parse(first[1]); var houses = Console.ReadLine().Trim().Split(' '); var tmp = 0; for (int i = 0; i < n; i++) { var c_len = int.Parse(houses[i]); var islast = i + 1 == n; var n_len = int.Parse(houses[islast ? 0 : i + 1]); if (islast) { n_len += 20; } if (tmp <= n_len - c_len) { tmp = n_len - c_len; } } Console.WriteLine(k - tmp); } } }
using System; using System.IO; namespace abc160_1 { class Program { static void Main(string[] args) { Console.SetIn(new StreamReader(Console.OpenStandardInput(1000000))); var first = Console.ReadLine().Trim().Split(' '); var k = int.Parse(first[0]); var n = int.Parse(first[1]); var houses = Console.ReadLine().Trim().Split(' '); var tmp = 0; for (int i = 0; i < n; i++) { var c_len = int.Parse(houses[i]); var islast = i + 1 == n; var n_len = int.Parse(houses[islast ? 0 : i + 1]); if (islast) { n_len += k; } if (tmp <= n_len - c_len) { tmp = n_len - c_len; } } Console.WriteLine(k - tmp); } } }
[["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22]]
8
206
2
using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var kn = Console.ReadLine().Split(' '); // 演習の長さ var k = long.Parse(kn[0]); // 家の数 var n = long.Parse(kn[1]); // 家の距離 var a = Console.ReadLine().Split(' '); var max = 0L; for (var i = 1; i < n; i++) { max = Math.Max(long.Parse(a[i]) - long.Parse(a[i - 1]), max); } max = Math.Max(long.Parse(a[0]) + k - long.Parse(a[n - 1]), max); Console.WriteLine(max); } } }
using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var kn = Console.ReadLine().Split(' '); // 演習の長さ var k = long.Parse(kn[0]); // 家の数 var n = long.Parse(kn[1]); // 家の距離 var a = Console.ReadLine().Split(' '); var max = 0L; for (var i = 1; i < n; i++) { max = Math.Max(long.Parse(a[i]) - long.Parse(a[i - 1]), max); } max = Math.Max(long.Parse(a[0]) + k - long.Parse(a[n - 1]), max); Console.WriteLine(k - max); } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33]]
8
175
2
using System; using static System.Console; using System.Linq; namespace AC { public class shiokara { static void Main(string[] args) { int[] kn = ReadLine().Split(' ').Select(int.Parse).ToArray(); int[] homedis = ReadLine().Split(' ').Select(int.Parse).ToArray(); int[] homedisspc = new int[kn[1]]; for (int i = 0; i < homedis.Length; i++) { if ((i + 1) == homedis.Length) homedisspc[i] = (kn[0] - homedis[i]) + homedis[0]; else homedisspc[i] = homedis[i + 1] - homedis[i]; } WriteLine(homedisspc.Sum() / 2); } } }
using System; using static System.Console; using System.Linq; namespace AC { public class shiokara { static void Main(string[] args) { int[] kn = ReadLine().Split(' ').Select(int.Parse).ToArray(); int[] homedis = ReadLine().Split(' ').Select(int.Parse).ToArray(); int[] homedisspc = new int[kn[1]]; for (int i = 0; i < homedis.Length; i++) { if ((i + 1) == homedis.Length) homedisspc[i] = (kn[0] - homedis[i]) + homedis[0]; else homedisspc[i] = homedis[i + 1] - homedis[i]; } WriteLine(homedisspc.Sum() - homedisspc.Max()); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 25]]
8
183
8
using System; using System.Collections.Generic; using static System.Math; using System.Linq; using System.Text; class DandA { static void Main(string[] args) { int[] kn = ReadLineIntArray(); int[] aArr = ReadLineIntArray(); int wk = 0; int rtn = 0; for (int i = 0; i < kn[1] - 1; i++) { if (rtn < (aArr[i + 1] - aArr[i])) { rtn = aArr[i + 1] - aArr[i]; } } if (rtn < (kn[0] - aArr[kn[1] - 1]) + aArr[0]) { rtn = (kn[0] - aArr[kn[1] - 1]) + aArr[0]; } Console.WriteLine(rtn); } static string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; static string[] salphabet = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" }; static string[] strAry = new string[] { "L", "R", "U", "D" }; static int[] intArray = new int[10]; static List<int> intList = new List<int>(); static Dictionary<int, long> myTable = new Dictionary<int, long>(); static HashSet<int>[] rtnArrAb = null; static HashSet<int>[] rtnArrCd = null; static long[,] Combi = new long[2001, 2001]; static long div = 1000000007; static int[] atest = new int[] { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 }; static private string ReadLineStr() { return Console.ReadLine(); } static private int ReadLineInt() { return int.Parse(Console.ReadLine()); } static private long ReadLineLong() { return long.Parse(Console.ReadLine()); } static private double ReadLineDouble() { return double.Parse(Console.ReadLine()); } static private decimal ReadLineDecimal() { return decimal.Parse(Console.ReadLine()); } static private string[] ReadLineStrArray() { return Console.ReadLine().Trim().Split(); } static private int[] ReadLineIntArray() { return Console.ReadLine() .Trim() .Split() .Select(a => int.Parse(a)) .ToArray(); } static private long[] ReadLineLongArray() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToArray(); } static private double[] ReadLineDoubleArray() { return Console.ReadLine() .Trim() .Split() .Select(a => double.Parse(a)) .ToArray(); } static private decimal[] ReadLineDecimalArray() { return Console.ReadLine() .Trim() .Split() .Select(a => decimal.Parse(a)) .ToArray(); } static private List<int> ReadLineIntList() { return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToList(); } static private List<long> ReadLineLongList() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToList(); } static private string[][] ReadMLineStrArray(int arg) { return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray(); } static private int[][] ReadMLineIntArray(int arg) { return new int [arg] .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); } static private bool IsPrime(int num) { if (num < 2) return false; if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; } return true; } static private string IntToNString(int x, int n) { var nstring = ""; var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; int r = 1; int q = x; while (q > 0) { r = q % n; nstring += numbers[r]; q = q / n; } return string.Join("", nstring.Reverse()); } static private long Gcd(long m, long n) { long temp; while (m % n != 0) { temp = n; n = m % n; m = temp; } return n; } static private long Combination(long n, long r) { if (n < r) { return 0; } if (n == r || r == 0) { return 1; } else if (Combi[n, r] == 0) { Combi[n, r] = (Combination(n - 1, r - 1) + Combination(n - 1, r)) % div; } return Combi[n, r]; } }
using System; using System.Collections.Generic; using static System.Math; using System.Linq; using System.Text; class DandA { static void Main(string[] args) { int[] kn = ReadLineIntArray(); int[] aArr = ReadLineIntArray(); int wk = 0; int rtn = 0; for (int i = 0; i < kn[1] - 1; i++) { if (rtn < (aArr[i + 1] - aArr[i])) { rtn = aArr[i + 1] - aArr[i]; } } if (rtn < (kn[0] - aArr[kn[1] - 1]) + aArr[0]) { rtn = (kn[0] - aArr[kn[1] - 1]) + aArr[0]; } Console.WriteLine(kn[0] - rtn); } static string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; static string[] salphabet = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" }; static string[] strAry = new string[] { "L", "R", "U", "D" }; static int[] intArray = new int[10]; static List<int> intList = new List<int>(); static Dictionary<int, long> myTable = new Dictionary<int, long>(); static HashSet<int>[] rtnArrAb = null; static HashSet<int>[] rtnArrCd = null; static long[,] Combi = new long[2001, 2001]; static long div = 1000000007; static int[] atest = new int[] { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 }; static private string ReadLineStr() { return Console.ReadLine(); } static private int ReadLineInt() { return int.Parse(Console.ReadLine()); } static private long ReadLineLong() { return long.Parse(Console.ReadLine()); } static private double ReadLineDouble() { return double.Parse(Console.ReadLine()); } static private decimal ReadLineDecimal() { return decimal.Parse(Console.ReadLine()); } static private string[] ReadLineStrArray() { return Console.ReadLine().Trim().Split(); } static private int[] ReadLineIntArray() { return Console.ReadLine() .Trim() .Split() .Select(a => int.Parse(a)) .ToArray(); } static private long[] ReadLineLongArray() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToArray(); } static private double[] ReadLineDoubleArray() { return Console.ReadLine() .Trim() .Split() .Select(a => double.Parse(a)) .ToArray(); } static private decimal[] ReadLineDecimalArray() { return Console.ReadLine() .Trim() .Split() .Select(a => decimal.Parse(a)) .ToArray(); } static private List<int> ReadLineIntList() { return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToList(); } static private List<long> ReadLineLongList() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToList(); } static private string[][] ReadMLineStrArray(int arg) { return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray(); } static private int[][] ReadMLineIntArray(int arg) { return new int [arg] .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); } static private bool IsPrime(int num) { if (num < 2) return false; if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; } return true; } static private string IntToNString(int x, int n) { var nstring = ""; var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; int r = 1; int q = x; while (q > 0) { r = q % n; nstring += numbers[r]; q = q / n; } return string.Join("", nstring.Reverse()); } static private long Gcd(long m, long n) { long temp; while (m % n != 0) { temp = n; n = m % n; m = temp; } return n; } static private long Combination(long n, long r) { if (n < r) { return 0; } if (n == r || r == 0) { return 1; } else if (Combi[n, r] == 0) { Combi[n, r] = (Combination(n - 1, r - 1) + Combination(n - 1, r)) % div; } return Combi[n, r]; } }
[["+", 3, 4, 0, 28, 0, 16, 31, 204, 205, 22], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33]]
8
1,251
5
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace C { class Program { static void Main(string[] args) { var kn = Console.ReadLine().Split(); var around = int.Parse(kn[0]); var time = int.Parse(kn[1]); var data = Console.ReadLine().Split(' '); var nums = new int[time]; var max = 0; for (int i = 0; i < time; i++) { nums[i] = int.Parse(data[i]); } for (int i = 0; i < time - 1; i++) { max = Math.Max(max, nums[i + 1] - nums[i]); } max = Math.Max(max, around - nums[time - 1] + nums[0]); Console.WriteLine(max); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace C { class Program { static void Main(string[] args) { var kn = Console.ReadLine().Split(); var around = int.Parse(kn[0]); var time = int.Parse(kn[1]); var data = Console.ReadLine().Split(' '); var nums = new int[time]; var max = 0; for (int i = 0; i < time; i++) { nums[i] = int.Parse(data[i]); } for (int i = 0; i < time - 1; i++) { max = Math.Max(max, nums[i + 1] - nums[i]); } max = Math.Max(max, around - nums[time - 1] + nums[0]); Console.WriteLine(around - max); Console.ReadKey(); } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33]]
8
221
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace competitive_programming { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int K = int.Parse(input[0]); int N = int.Parse(input[0]); int[] position = Console.ReadLine().Split(' ').Select(val => int.Parse(val)).ToArray(); int[] distance = new int[position.Length]; distance[0] = position[0] + K - position[position.Length - 1]; for (int i = 1; i < distance.Length - 1; i++) { distance[i] = position[i] - position[i - 1]; } Console.WriteLine(K - distance.Max()); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace competitive_programming { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int K = int.Parse(input[0]); int N = int.Parse(input[0]); int[] position = Console.ReadLine().Split(' ').Select(val => int.Parse(val)).ToArray(); int[] distance = new int[position.Length]; distance[0] = position[0] + K - position[position.Length - 1]; for (int i = 1; i < distance.Length; i++) { distance[i] = position[i] - position[i - 1]; // Console.WriteLine(distance[i]); } Console.WriteLine(K - distance.Max()); } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
201
2
using System; using System.Linq; using System.Collections.Generic; namespace c { class Program { static void Main(string[] args) { var _ = Console.ReadLine().Split(); var k = int.Parse(_[0]); var n = int.Parse(_[1]); var a = Console.ReadLine().Split().Select(i => int.Parse(i)).ToList(); a.Add(k); var diff = Enumerable.Range(0, n).Select(i => a[i + 1] - a[i]).ToList(); var distance = diff.Sum() - diff.Max(); Console.WriteLine(distance); } } }
using System; using System.Linq; using System.Collections.Generic; namespace c { class Program { static void Main(string[] args) { var _ = Console.ReadLine().Split(); var k = int.Parse(_[0]); var n = int.Parse(_[1]); var a = Console.ReadLine().Split().Select(i => int.Parse(i)).ToList(); a.Add(k + a[0]); var diff = Enumerable.Range(0, n).Select(i => a[i + 1] - a[i]).ToList(); var distance = diff.Sum() - diff.Max(); Console.WriteLine(distance); } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 16, 12, 204, 205, 22], ["+", 0, 28, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 16, 12, 204, 206, 207, 0, 73]]
8
164
5
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { var firstLine = Console.ReadLine() .Split(' ') .Select(value => int.Parse(value)) .ToList(); var k = firstLine[0]; var n = firstLine[1]; var aList = Console.ReadLine() .Split(' ') .Select(value => int.Parse(value)) .ToList(); var min = int.MaxValue; for (int i = 0; i < n - 1; i++) { if (i == 0) { min = Math.Min(min, aList[n - 1] - aList[0]); } else { min = Math.Min(min, aList[i + 1] + k - aList[i]); } } Console.WriteLine(min); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { var firstLine = Console.ReadLine() .Split(' ') .Select(value => int.Parse(value)) .ToList(); var k = firstLine[0]; var n = firstLine[1]; var aList = Console.ReadLine() .Split(' ') .Select(value => int.Parse(value)) .ToList(); var min = int.MaxValue; for (int i = 0; i < n; i++) { if (i == 0) { min = Math.Min(min, aList[n - 1] - aList[0]); } else { min = Math.Min(min, aList[i - 1] + k - aList[i]); } } Console.WriteLine(min); } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33]]
8
201
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int x = sc.NextInt(); int y = sc.NextInt(); int z = sc.NextInt(); string answer = z + " " + y + " " + x; Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int x = sc.NextInt(); int y = sc.NextInt(); int z = sc.NextInt(); string answer = z + " " + x + " " + y; Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["-", 0, 212, 0, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 212, 0, 16, 31, 16, 31, 16, 12, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22]]
8
385
4
using System; using System.Collections.Generic; using System.Text; namespace AtCorder1 { class AtCorder161A { static void Main() { string[] line = System.Console.ReadLine().Trim().Split(' '); var a = int.Parse(line[0]); var b = int.Parse(line[1]); var c = int.Parse(line[2]); var tmp = b; b = a; a = tmp; var tmp2 = a; a = c; c = tmp2; var d = a + ' ' + b + ' ' + c; Console.WriteLine(d); } } }
using System; using System.Collections.Generic; using System.Text; namespace AtCorder1 { class AtCorder161A { static void Main() { string[] line = System.Console.ReadLine().Trim().Split(' '); var a = int.Parse(line[0]); var b = int.Parse(line[1]); var c = int.Parse(line[2]); var tmp = b; b = a; a = tmp; var tmp2 = a; a = c; c = tmp2; var d = a + " " + b + " " + c; Console.WriteLine(d); } } }
[["-", 31, 16, 31, 16, 31, 16, 12, 252, 0, 104], ["+", 31, 16, 31, 16, 31, 16, 12, 5, 0, 62], ["-", 0, 212, 0, 16, 31, 16, 12, 252, 0, 104], ["+", 0, 212, 0, 16, 31, 16, 12, 5, 0, 62]]
8
143
8
using System; class Program { static void Main(string[] args) { // スペース区切りの整数の入力 string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int c = int.Parse(input[2]); //出力 Console.WriteLine(String.Format("{0}{1}{2}", c, a, b)); } }
using System; class Program { static void Main(string[] args) { // スペース区切りの整数の入力 string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int c = int.Parse(input[2]); //出力 Console.WriteLine(String.Format("{0} {1} {2}", c, a, b)); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
97
2
using System; using System.Collections.Generic; using System.Linq; using System.Collections; public class Coder { public static int[] ReadArray() { return Array.ConvertAll(Console.ReadLine().Split(' '), m => Convert.ToInt32(m)); } public static int ReadInt() { return Convert.ToInt32(Console.ReadLine()); } public static string ReadStr() { return Console.ReadLine(); } public static long ReadLong() { return Convert.ToInt64(Console.ReadLine()); } public static long[] ReadLongArray() { return Array.ConvertAll(Console.ReadLine().Split(' '), m => Convert.ToInt64(m)); } public static void Main() { int[] A = ReadArray(); Console.WriteLine($"{A[1]} {A[0]} {A[2]}"); } }
using System; using System.Collections.Generic; using System.Linq; using System.Collections; public class Coder { public static int[] ReadArray() { return Array.ConvertAll(Console.ReadLine().Split(' '), m => Convert.ToInt32(m)); } public static int ReadInt() { return Convert.ToInt32(Console.ReadLine()); } public static string ReadStr() { return Console.ReadLine(); } public static long ReadLong() { return Convert.ToInt64(Console.ReadLine()); } public static long[] ReadLongArray() { return Array.ConvertAll(Console.ReadLine().Split(' '), m => Convert.ToInt64(m)); } public static void Main() { int[] A = ReadArray(); Console.WriteLine($"{A[2]} {A[0]} {A[1]}"); } }
[["-", 0, 284, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 284, 0, 204, 206, 207, 0, 28, 0, 203]]
8
201
4
using System; using System.Linq; class Program { static void Main(string[] args) { var inputs = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); Console.WriteLine(inputs[2] + " " + inputs[1] + " " + inputs[0]); } }
using System; using System.Linq; class Program { static void Main(string[] args) { var inputs = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); Console.WriteLine(inputs[2] + " " + inputs[0] + " " + inputs[1]); } }
[["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
8
78
4
using System; namespace AtCoderMake._161 { class ABC161A { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); Console.WriteLine(input[2] + " " + input[0] + " "[1]); } } }
using System; namespace AtCoderMake._161 { class ABC161A { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); Console.WriteLine(input[2] + " " + input[0] + " " + input[1]); } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 16, 12, 204, 205, 22]]
8
68
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; class program { static public int mod = 1000000007; static void Main() { var nm = inta(); int n = nm[0], m = nm[1]; var a = inta(); Array.Sort(a); Array.Reverse(a); int sa = a.Sum(); int sam = (int)Ceiling((double)sa / (4 * m)); Write(sam < a[m - 1] ? "Yes" : "No"); } static int pow(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = double.Parse(read_str_array[countup_i]); } return return_double_array; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } static void WriteArray2(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } } static void WriteArray(int[] a, int b) { for (int i = 0; i < b; i++) { Write(" "); Write(a[i]); } WriteLine(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; class program { static public int mod = 1000000007; static void Main() { var nm = inta(); int n = nm[0], m = nm[1]; var a = inta(); Array.Sort(a); Array.Reverse(a); int sa = a.Sum(); int sam = (int)Ceiling((double)sa / (4 * m)); Write(sam <= a[m - 1] ? "Yes" : "No"); } static int pow(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = double.Parse(read_str_array[countup_i]); } return return_double_array; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } static void WriteArray2(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } } static void WriteArray(int[] a, int b) { for (int i = 0; i < b; i++) { Write(" "); Write(a[i]); } WriteLine(); } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 18], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 19]]
8
808
2
using System; using System.Linq; using System.Collections.Generic; using static System.Console; class Program { static void Main() { var input = ReadLine().Split(' ').Select(int.Parse).ToArray(); var n = input[0]; var m = input[1]; var input1 = ReadLine().Split(' ').Select(int.Parse).ToArray(); var b = input1.Sum() / (4 * m); var judge = input1.Where(a => a >= b).Count(); if (judge >= m) { Write("Yes"); } else { Write("No"); } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; class Program { static void Main() { var input = ReadLine().Split(' ').Select(int.Parse).ToArray(); var n = input[0]; var m = input[1]; var input1 = ReadLine().Split(' ').Select(int.Parse).ToArray(); double b = input1.Sum() / (4.0 * m); var judge = input1.Where(a => a >= b).Count(); if (judge >= m) { Write("Yes"); } else { Write("No"); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 212, 0, 16, 12, 23, 0, 16, 31, 203], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 31, 250]]
8
156
4
using System; using System.Collections.Generic; using System.Linq; class Progaram { static void Main(string[] args) { var l = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var n = l[0]; var m = l[1]; var line = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var sum = line.Sum(); line = line.Where(x => x > sum / (4 * m)).ToArray(); if (m <= line.Length) Console.WriteLine("Yes"); else Console.WriteLine("No"); } }
using System; using System.Collections.Generic; using System.Linq; class Progaram { static void Main(string[] args) { var l = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var n = l[0]; var m = l[1]; var line = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var sum = line.Sum(); line = line.Where(x => x * 4 * m >= sum).ToArray(); if (m <= line.Length) Console.WriteLine("Yes"); else Console.WriteLine("No"); } }
[["-", 3, 4, 0, 28, 0, 218, 8, 16, 17, 47], ["-", 0, 28, 0, 218, 8, 16, 12, 16, 31, 22], ["-", 0, 28, 0, 218, 8, 16, 12, 16, 17, 85], ["-", 0, 218, 8, 16, 12, 16, 12, 23, 0, 24], ["+", 0, 218, 8, 16, 31, 16, 31, 16, 17, 48], ["-", 0, 218, 8, 16, 12, 16, 12, 23, 0, 25], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 20], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 22]]
8
169
8
using System; using System.Linq; using System.Collections.Generic; namespace cs { class Program { static void Main(string[] args) { var pg = new Program(); pg.Execute(); } private void Execute() { var input = ReadLinesLongList; var ALists = ReadLinesLongList; var N = (int)input.ElementAt(0); var M = (double)input.ElementAt(1); var con = ALists.Sum() * (1 / (4 * M)); if (ALists.OrderByDescending(e => e).Take((int)M).All(e => e > con)) { OutputResult("Yes"); } else { OutputResult("No"); } } private void OutputResult<Type>(Type result) { Console.WriteLine(result); } static long ReadLineLong => long.Parse(Console.ReadLine()); static string ReadLineString => Console.ReadLine(); static IEnumerable<long> ReadLinesLongList => Console.ReadLine().Split(' ').Select(i => long.Parse(i)); static IEnumerable<string> ReadLinesStringList => Console.ReadLine().Split(' '); } }
using System; using System.Linq; using System.Collections.Generic; namespace cs { class Program { static void Main(string[] args) { var pg = new Program(); pg.Execute(); } private void Execute() { var input = ReadLinesLongList; var ALists = ReadLinesLongList; var N = (int)input.ElementAt(0); var M = (double)input.ElementAt(1); var con = ALists.Sum() * (1 / (4 * M)); if (ALists.OrderByDescending(e => e).Take((int)M).All(e => e >= con)) { OutputResult("Yes"); } else { OutputResult("No"); } } private void OutputResult<Type>(Type result) { Console.WriteLine(result); } static long ReadLineLong => long.Parse(Console.ReadLine()); static string ReadLineString => Console.ReadLine(); static IEnumerable<long> ReadLinesLongList => Console.ReadLine().Split(' ').Select(i => long.Parse(i)); static IEnumerable<string> ReadLinesStringList => Console.ReadLine().Split(' '); } }
[["-", 3, 4, 0, 28, 0, 218, 8, 16, 17, 47], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 20]]
8
253
2
using System; using System.Linq; using static System.Console; class Program { static void Main(string[] args) { var NM = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var (N, M) = (NM[0], NM[1]); var A = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var Asum = A.Sum(); var threshold = (double)Asum / (4 * M) + 0.00001; var count = A.Count(x => x >= threshold); var ans = (M <= count) ? "Yes" : "No"; WriteLine(ans); } }
using System; using System.Linq; using static System.Console; class Program { static void Main(string[] args) { var NM = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var (N, M) = (NM[0], NM[1]); var A = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var Asum = A.Sum(); var threshold = (double)Asum / (4 * M); var count = A.Count(x => x >= threshold); var ans = (M <= count) ? "Yes" : "No"; WriteLine(ans); } }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 250]]
8
169
2
using System; using System.Linq; namespace Sample { class Sample { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int N = int.Parse(str[0]); int M = int.Parse(str[1]); string[] str2 = Console.ReadLine().Split(' '); int[] tokuhyo = new int[N]; for (int i = 0; i < N; i++) { tokuhyo[i] = int.Parse(str2[i]); } int count = 0; for (int j = 0; j < N; j++) { if (tokuhyo[j] >= (double)(tokuhyo.Sum() / (4 * M))) { count++; } } if (count >= M) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Linq; namespace Sample { class Sample { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int N = int.Parse(str[0]); int M = int.Parse(str[1]); string[] str2 = Console.ReadLine().Split(' '); int[] tokuhyo = new int[N]; for (int i = 0; i < N; i++) { tokuhyo[i] = int.Parse(str2[i]); } int count = 0; for (int j = 0; j < N; j++) { if (tokuhyo[j] >= ((double)tokuhyo.Sum() / (4 * M))) { count++; } } if (count >= M) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["+", 15, 16, 12, 23, 0, 16, 31, 74, 0, 24], ["-", 0, 57, 15, 16, 12, 74, 51, 23, 0, 24]]
8
210
2
using System; using System.Collections.Generic; using System.Linq; namespace abc161_b { class Program { static void Main(string[] args) { string[] nm = Console.ReadLine().Split(" "); int n = int.Parse(nm[0]); int m = int.Parse(nm[1]); string[] ai = Console.ReadLine().Split(" "); List<int> aiList = new List<int>(); int sum = 0; foreach (string aiInt in ai) { aiList.Add(int.Parse(aiInt)); sum += int.Parse(aiInt); } int sortAiList = aiList.OrderByDescending(value => value).Skip(m - 1).First(); double warizan = sum / (4 * m); if (sortAiList > warizan) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Collections.Generic; using System.Linq; namespace abc161_b { class Program { static void Main(string[] args) { string[] nm = Console.ReadLine().Split(" "); int n = int.Parse(nm[0]); int m = int.Parse(nm[1]); string[] ai = Console.ReadLine().Split(" "); List<int> aiList = new List<int>(); double sum = 0; foreach (string aiInt in ai) { aiList.Add(int.Parse(aiInt)); sum += int.Parse(aiInt); } int sortAiList = aiList.OrderByDescending(value => value).Skip(m - 1).First(); double warizan = sum / (4 * m); if (sortAiList >= warizan) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
8
208
4
using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Text.RegularExpressions; using System.Threading; namespace ConsoleApp1 { class Program { static void Main(string[] args) { long[] iArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); long[] val = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); //種類 long N = iArray[0]; //個数 long M = iArray[1]; List<long> list = new List<long>(); for (long i = 0; i < N; i++) { //票数 list.Add(val[i]); } long sum = val.Sum(); List<long> vs = new List<long>(); for (int p = 0; p < N; p++) { //合計/(4*M)以上のものをリストに加える if (list[p] >= sum / (4 * M)) { vs.Add(list[p]); } } if (vs.Count() >= M) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } } //文字列の入力 // string s = Console.ReadLine(); //整数の入力 // long n = long.Parse(Console.ReadLine()); //文字列配列の入力 // string[] inputStrArray = Console.ReadLine().Split(' '); //整数配列の入力 // long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => // long.Parse(i)).ToArray(); // Console.WriteLine(); // Console.ReadKey();
using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Text.RegularExpressions; using System.Threading; namespace ConsoleApp1 { class Program { static void Main(string[] args) { long[] iArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); long[] val = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); //種類 long N = iArray[0]; //個数 long M = iArray[1]; List<long> list = new List<long>(); for (long i = 0; i < N; i++) { //票数 list.Add(val[i]); } long sum = val.Sum(); List<long> vs = new List<long>(); for (int p = 0; p < N; p++) { //合計/(4*M)以上のものをリストに加える if ((decimal)list[p] >= sum / (decimal)(4 * M)) { vs.Add(list[p]); } } if (vs.Count() >= M) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 74, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 74, 39, 199], ["+", 8, 196, 0, 57, 15, 16, 31, 74, 0, 25], ["+", 0, 57, 15, 16, 12, 16, 12, 74, 0, 24], ["+", 0, 57, 15, 16, 12, 16, 12, 74, 39, 199], ["+", 0, 57, 15, 16, 12, 16, 12, 74, 0, 25]]
8
300
6
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace atcoder { class Program { static void Main(string[] args) { var nm = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray(); var arrays = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray(); var total = arrays.Sum(x => x); var m = nm[1]; var lim = total / (4 * m); Console.WriteLine(arrays.Count(a => a >= lim) >= m ? "Yes" : "No"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace atcoder { class Program { static void Main(string[] args) { var nm = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray(); var arrays = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray(); double total = arrays.Sum(x => x); var m = nm[1]; var lim = total / (4 * m); Console.WriteLine(arrays.Count(a => a >= lim) >= m ? "Yes" : "No"); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
160
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { int[] arr = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray(); IEnumerable<int> arrTwo = Console.ReadLine().Split(' ').Select(v => int.Parse(v)); double line = arrTwo.Sum() / 4 / arr[1]; int count = arrTwo.Where(v => v >= line).Count(); Console.WriteLine(count >= arr[1] ? "Yes" : "No"); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { double[] arr = Console.ReadLine().Split(' ').Select(v => double.Parse(v)).ToArray(); IEnumerable<double> arrTwo = Console.ReadLine().Split(' ').Select(v => double.Parse(v)); double line = arrTwo.Sum() / 4 / arr[1]; double count = arrTwo.Where(v => v >= line).Count(); Console.WriteLine(count >= arr[1] ? "Yes" : "No"); } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["-", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
154
10
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc161_b { class Program { static void Main(string[] args) { string[] kazu = Console.ReadLine().Split(' '); int N = int.Parse(kazu[0]); int M = int.Parse(kazu[1]); string[] hyou = Console.ReadLine().Split(' '); int[] A = new int[N]; int sou = 0; for (int i = 0; i < N; i++) { A[i] = int.Parse(hyou[i]); sou += A[i]; } int count = 0; for (int i = 0; i < N; i++) { if (A[i] < sou / (4 * M)) { } else { count++; } } if (count >= M) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } Console.Read(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc161_b { class Program { static void Main(string[] args) { string[] kazu = Console.ReadLine().Split(' '); int N = int.Parse(kazu[0]); int M = int.Parse(kazu[1]); string[] hyou = Console.ReadLine().Split(' '); int[] A = new int[N]; double sou = 0; for (int i = 0; i < N; i++) { A[i] = int.Parse(hyou[i]); sou += A[i]; } int count = 0; for (int i = 0; i < N; i++) { if (A[i] < sou / (4 * M)) { } else { count++; } } if (count >= M) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } Console.Read(); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
241
2
using System; using System.Linq; public class Test { public static void Main() { var line1 = System.Console.ReadLine(); var line2 = System.Console.ReadLine(); string[] str1 = line1.Split(' '); //商品の総数 int n = int.Parse(str1[0]); //選択する人気商品数 int m = int.Parse(str1[1]); //得票数 string[] str2 = line2.Split(' '); int[] a = new int[n]; for (int i = 0; i < n; ++i) { a[i] = int.Parse(str2[i]); } // System.Console.WriteLine(a.Sum()); //人気商品数用変数 int pop = 0; for (int i = 0; i < n; ++i) { if (judge(a, i, m)) pop++; } if (pop >= m) { System.Console.WriteLine("Yes"); } else { System.Console.WriteLine("No"); } } public static Boolean judge(int[] num, int i, int m) { if (num[i] <= (num.Sum() / (4 * m))) { return false; } else { return true; } } }
using System; using System.Linq; public class Test { public static void Main() { var line1 = System.Console.ReadLine(); var line2 = System.Console.ReadLine(); string[] str1 = line1.Split(' '); //商品の総数 int n = int.Parse(str1[0]); //選択する人気商品数 int m = int.Parse(str1[1]); //得票数 string[] str2 = line2.Split(' '); int[] a = new int[n]; for (int i = 0; i < n; ++i) { a[i] = int.Parse(str2[i]); } // System.Console.WriteLine(a.Sum()); //人気商品数用変数 int pop = 0; for (int i = 0; i < n; ++i) { if (judge(a, i, m)) pop++; } if (pop >= m) { System.Console.WriteLine("Yes"); } else { System.Console.WriteLine("No"); } } public static Boolean judge(int[] num, int i, int m) { if (num[i] < ((double)num.Sum() / (4 * m))) { return false; } else { return true; } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 15, 16, 12, 23, 0, 16, 31, 74, 0, 24], ["+", 15, 16, 12, 23, 0, 16, 31, 74, 39, 199], ["+", 15, 16, 12, 23, 0, 16, 31, 74, 0, 25]]
8
262
5
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using static System.Console; namespace Paiza { public static class Program { public static void Main(string[] args) { var m = ReadLine().SplitToIntList()[1]; var data = ReadLine().SplitToIntList().OrderByDescending(a => a).ToList(); var min = (data.Sum() + m * 4) / (m * 4); data.Take(m).Last().Chain(a => a >= min ? "Yes" : "No").WriteLine(); } #region Utilities public static IEnumerable<IList<T>> Buffer<T>(this IEnumerable<T> source, int count) { return Buffer(source, count, count); } public static IEnumerable<IList<T>> Buffer<T>(this IEnumerable<T> source, int count, int skip) { if (source == null) throw new ArgumentNullException(nameof(source)); if (count < 1) throw new ArgumentOutOfRangeException(nameof(count)); if (skip < 1) throw new ArgumentOutOfRangeException(nameof(skip)); var queue = new Queue<List<T>>(); int step = skip; foreach (var item in source) { if (step == skip) { step = 0; queue.Enqueue(new List<T>(count)); } foreach (var list in queue) list.Add(item); while (queue.Count > 0 && queue.Peek().Count == count) yield return queue.Dequeue(); step++; } while (queue.Count > 0) yield return queue.Dequeue(); } public static IEnumerable<IList<T>> Buffer<T>(this IEnumerable<T> source, Func<T, bool> seperator, bool includeSeperator = false) { if (source == null) throw new ArgumentNullException(nameof(source)); if (seperator == null) throw new ArgumentNullException(nameof(source)); var list = new List<T>(); foreach (var item in source) { if (seperator(item)) { if (includeSeperator) list.Add(item); yield return list; list = new List<T>(); } else { list.Add(item); } } yield return list; } public static IEnumerable<T> Append<T>(this IEnumerable<T> source, params T[] items) { foreach (var i in source) yield return i; foreach (var i in items) yield return i; } public static IEnumerable<T> Prepend<T>(this IEnumerable<T> source, params T[] items) { foreach (var i in items) yield return i; foreach (var i in source) yield return i; } public static IEnumerable<IEnumerable<T>> Combination<T>(this IEnumerable<T> source, int count) { var stack = new Stack<List<T>[]>(); stack.Push(new[] { new List<T>(), source.ToList() }); while (stack.Count > 0) { var item = stack.Pop(); if (item[0].Count() == count) { yield return item[0]; } else { var list = item[1]; list.Select((a, i) => new[] { item[0].Concat(new[] { a }).ToList(), list.Skip(i + 1).ToList(), }) .TakeWhile(a => a[0].Count + a[1].Count >= count) .ForEach(a => stack.Push(a)); } } } public static IEnumerable<IEnumerable<T>> Permutation<T>(this IEnumerable<T> source, int count) { var stack = new Stack<IEnumerable<T>[]>(); stack.Push(new[] { Enumerable.Empty<T>(), source.ToList() }); while (stack.Count > 0) { var item = stack.Pop(); if (item[0].Count() == count) { yield return item[0]; } else { var list = item[1]; list.Select((a, i) => new[] { item[0].Concat(new[] { a }), list.Where((b, j) => j != i), }) .ForEach(a => stack.Push(a)); } } } public static IEnumerable<string> ReadAllLines() { return Repeat(ReadLine).TakeWhile(a => a != null); } public static List<int> SplitToIntList(this string source) { return source.Split().Select(a => int.Parse(a)).ToList(); } public static List<long> SplitToLongList(this string source) { return source.Split().Select(a => long.Parse(a)).ToList(); } public static List<double> SplitToDoubleList(this string source) { return source.Split().Select(a => double.Parse(a)).ToList(); } public static IEnumerable<T> Return<T>(params T[] source) { return source; } public static string JoinWithSpace<T>(this IEnumerable<T> source) { return string.Join(" ", source); } public static IEnumerable<T> Repeat<T>(this T source) { return Repeat(() => source); } public static IEnumerable<T> Repeat<T>(Func<T> selector) { while (true) yield return selector(); } public static IEnumerable<T> Recur<T>(this T source, Func<T, T> selector) { var p = source; while (true) { yield return p; p = selector(p); } } public static IEnumerable<T> Scan<T>(this IEnumerable<T> source, Func<T, T, T> selector) { return Scan(source, default(T), selector); } public static IEnumerable<T> Scan<T>(this IEnumerable<T> source, T seed, Func<T, T, T> selector) { var last = seed; foreach (var item in source) { last = selector(last, item); yield return last; } } public static void ForEach<T>(this IEnumerable<T> source, Action<T> unlessEmpty, Action ifEmpty = null) { using (var e = source.GetEnumerator()) { if (unlessEmpty != null && e.MoveNext()) { do unlessEmpty(e.Current); while (e.MoveNext()); } else { ifEmpty?.Invoke(); } } } public static void ForEach<T>(this IEnumerable<T> source, Action<T, int> unlessEmpty, Action ifEmpty = null) { using (var e = source.GetEnumerator()) { if (unlessEmpty != null && e.MoveNext()) { int i = 0; do { unlessEmpty(e.Current, i); i++; } while (e.MoveNext()); } else { ifEmpty?.Invoke(); } } } public static T WriteLine<T>(this T source) { Console.WriteLine(source); return source; } public static void WriteAllLines<T>(this IEnumerable<T> source) { foreach (var item in source) WriteLine(item); } public static TResult Chain<TSource, TResult>(this TSource source, Func<TSource, TResult> selector) { return selector(source); } public static T Chain<T>(this T source, Action<T> action) { action(source); return source; } public static IEnumerable<T> Do<T>(this IEnumerable<T> source, Action<T> action) { foreach (var a in source) { action(a); yield return a; } } #endregion #region Location struct Location { public Location(int x, int y) { X = x; Y = y; } public int X { get; private set; } public int Y { get; private set; } public override bool Equals(object obj) { if (!(obj is Location)) return false; var other = (Location)obj; return other != null && X == other.X && Y == other.Y; } public override int GetHashCode() { return X << 16 | Y | X >> 16; } public static bool operator ==(Location left, Location right) { return EqualityComparer<Location>.Default.Equals(left, right); } public static bool operator !=(Location left, Location right) { return !(left == right); } public static Location operator +(Location left, Location right) { return new Location(left.X + right.X, left.Y + right.Y); } public static Location operator -(Location left, Location right) { return new Location(left.X - right.X, left.Y - right.Y); } } #endregion #region D2 class D2<T> : IEnumerable<Location> { public D2(int width, int height, IEnumerable<T> items = null) { Width = width; Height = height; var size = Width * Height; Items = items?.ToArray() ?? new T[size]; if (Items.Length != size) throw new Exception(); } public int Width { get; private set; } public int Height { get; private set; } public T[] Items { get; private set; } public T this[int index] { get { return Items[index]; } set { Items[index] = value; } } public T this[int x, int y] { get { return Items[y * Width + x]; } set { Items[y * Width + x] = value; } } public T this[Location location] { get { return this[location.X, location.Y]; } set { this[location.X, location.Y] = value; } } public bool Contains(Location location) { return 0 <= location.X && 0 <= location.Y && location.X < Width && location.Y < Height; } public D2<T> Clone() { return new D2<T>(Width, Height, Items); } public IEnumerable<IEnumerable<Location>> EnumerateVertical() { return Enumerable.Range(0, Height).Select( y => Enumerable.Range(0, Width).Select(x => new Location(x, y))); } public IEnumerable<IEnumerable<Location>> EnumerateHorizontal() { return Enumerable.Range(0, Width).Select( x => Enumerable.Range(0, Height).Select(y => new Location(x, y))); } public IEnumerator<Location> GetEnumerator() { foreach (var item in EnumerateVertical().SelectMany(a => a)) { yield return item; } } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } #endregion #region Matrix class Matrix : D2<double> { public Matrix(int width, int height, IEnumerable<double> items = null) : base(width, height, items) {} public override bool Equals(object obj) { var other = obj as Matrix; return other != null && Width == other.Width && Height == other.Height && Items.Zip(other.Items, (a, b) => a == b).All(a => a); } public override int GetHashCode() { int hashCode = 1931280238; hashCode = hashCode * -1521134295 + Width.GetHashCode() + Height.GetHashCode() + Items.Select(a => a.GetHashCode()).Aggregate((a, b) => a ^ b); return hashCode; } public static bool operator ==(Matrix left, Matrix right) { return EqualityComparer<Matrix>.Default.Equals(left, right); } public static bool operator !=(Matrix left, Matrix right) { return !(left == right); } public static Matrix operator +(Matrix left, Matrix right) { if (left == null) throw new ArgumentNullException(nameof(left)); if (right == null) throw new ArgumentNullException(nameof(right)); if (left.Width != right.Width || left.Height != right.Height) throw new ArgumentException(nameof(right)); return new Matrix(left.Width, left.Height, left.Items.Zip(right.Items, (a, b) => a + b)); } public static Matrix operator -(Matrix left, Matrix right) { if (left == null) throw new ArgumentNullException(nameof(left)); if (right == null) throw new ArgumentNullException(nameof(right)); if (left.Width != right.Width || left.Height != right.Height) throw new ArgumentException(nameof(right)); return new Matrix(left.Width, left.Height, left.Items.Zip(right.Items, (a, b) => a - b)); } public static Matrix operator *(Matrix left, Matrix right) { if (left == null) throw new ArgumentNullException(nameof(left)); if (right == null) throw new ArgumentNullException(nameof(right)); if (left.Width != right.Height) throw new ArgumentException(nameof(right)); return new Matrix( right.Width, left.Height, left.EnumerateVertical().SelectMany( l => right.EnumerateHorizontal().Select( r => l.Zip(r, (a, b) => left[a] * right[b]).Sum()))); } public static Matrix operator +(Matrix left, double right) { if (left == null) throw new ArgumentNullException(nameof(left)); return new Matrix(left.Width, left.Height, left.Items.Select(a => a + right)); } public static Matrix operator -(Matrix left, double right) { if (left == null) throw new ArgumentNullException(nameof(left)); return new Matrix(left.Width, left.Height, left.Items.Select(a => a - right)); } public static Matrix operator *(Matrix left, double right) { if (left == null) throw new ArgumentNullException(nameof(left)); return new Matrix(left.Width, left.Height, left.Items.Select(a => a * right)); } public static Matrix operator /(Matrix left, double right) { if (left == null) throw new ArgumentNullException(nameof(left)); return new Matrix(left.Width, left.Height, left.Items.Select(a => a / right)); } public virtual string ToString(string format) { return EnumerateVertical() .Select(a => string.Join(" ", a.Select(b => this[b].ToString(format)))) .Chain(a => string.Join("\n", a)); } public override string ToString() { return ToString("0.00000"); } } class RotationMatrix : Matrix { public RotationMatrix(double radian) : base(2, 2, new[] { Math.Cos(radian), -Math.Sin(radian), Math.Sin(radian), Math.Cos(radian), }) {} public RotationMatrix(int degree) : this(Math.PI * degree / 180) {} } class RollMatrix : Matrix { public RollMatrix(double radian) : base(3, 3, new[] { Math.Cos(radian), -Math.Sin(radian), 0, Math.Sin(radian), Math.Cos(radian), 0, 0, 0, 1, }) {} public RollMatrix(int degree) : this(Math.PI * degree / 180) {} } class YawMatrix : Matrix { public YawMatrix(double radian) : base(3, 3, new[] { Math.Cos(radian), 0, -Math.Sin(radian), 0, 1, 0, Math.Sin(radian), 0, Math.Cos(radian), }) {} public YawMatrix(int degree) : this(Math.PI * degree / 180) {} } class PitchMatrix : Matrix { public PitchMatrix(double radian) : base(3, 3, new[] { 1, 0, 0, 0, Math.Cos(radian), -Math.Sin(radian), 0, Math.Sin(radian), Math.Cos(radian), }) {} public PitchMatrix(int degree) : this(Math.PI * degree / 180) {} } #endregion #region Prime class Prime { private static int mark = 2; private static readonly List<int> list = new List<int>(); private static readonly bool[] buffer = new bool[4096]; private Prime() {} public static IEnumerable<int> Get() { return list.Concat(GetNew()); } private static IEnumerable<int> GetNew() { while (true) { FillBuffer(); int l = list.Count; Enumerable.Range(0, buffer.Length) .Where(a => !buffer[a]) .ForEach(a => list.Add(mark + a)); mark += buffer.Length; for (int i = l; i < list.Count; i++) { yield return list[i]; } } } private static void FillBuffer() { Array.Clear(buffer, 0, buffer.Length); Enumerable.Range(0, list.Count).Select(a => list[a]).ForEach(a => { var o = mark % a; var n = o == 0 ? 0 : a - o; while (n < buffer.Length) { buffer[n] = true; n += a; } }); Enumerable.Range(0, buffer.Length) .Where(a => !buffer[a]) .Select(a => mark + a) .ForEach(a => (a * 2 - mark) .Recur(b => b + a) .TakeWhile(b => b < buffer.Length) .ForEach(b => buffer[b] = true)); } } #endregion } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using static System.Console; namespace Paiza { public static class Program { public static void Main(string[] args) { var m = ReadLine().SplitToIntList()[1]; var data = ReadLine().SplitToIntList().OrderByDescending(a => a).ToList(); var min = (data.Sum() + m * 4 - 1) / (m * 4); data.Take(m).Last().Chain(a => a >= min ? "Yes" : "No").WriteLine(); } #region Utilities public static IEnumerable<IList<T>> Buffer<T>(this IEnumerable<T> source, int count) { return Buffer(source, count, count); } public static IEnumerable<IList<T>> Buffer<T>(this IEnumerable<T> source, int count, int skip) { if (source == null) throw new ArgumentNullException(nameof(source)); if (count < 1) throw new ArgumentOutOfRangeException(nameof(count)); if (skip < 1) throw new ArgumentOutOfRangeException(nameof(skip)); var queue = new Queue<List<T>>(); int step = skip; foreach (var item in source) { if (step == skip) { step = 0; queue.Enqueue(new List<T>(count)); } foreach (var list in queue) list.Add(item); while (queue.Count > 0 && queue.Peek().Count == count) yield return queue.Dequeue(); step++; } while (queue.Count > 0) yield return queue.Dequeue(); } public static IEnumerable<IList<T>> Buffer<T>(this IEnumerable<T> source, Func<T, bool> seperator, bool includeSeperator = false) { if (source == null) throw new ArgumentNullException(nameof(source)); if (seperator == null) throw new ArgumentNullException(nameof(source)); var list = new List<T>(); foreach (var item in source) { if (seperator(item)) { if (includeSeperator) list.Add(item); yield return list; list = new List<T>(); } else { list.Add(item); } } yield return list; } public static IEnumerable<T> Append<T>(this IEnumerable<T> source, params T[] items) { foreach (var i in source) yield return i; foreach (var i in items) yield return i; } public static IEnumerable<T> Prepend<T>(this IEnumerable<T> source, params T[] items) { foreach (var i in items) yield return i; foreach (var i in source) yield return i; } public static IEnumerable<IEnumerable<T>> Combination<T>(this IEnumerable<T> source, int count) { var stack = new Stack<List<T>[]>(); stack.Push(new[] { new List<T>(), source.ToList() }); while (stack.Count > 0) { var item = stack.Pop(); if (item[0].Count() == count) { yield return item[0]; } else { var list = item[1]; list.Select((a, i) => new[] { item[0].Concat(new[] { a }).ToList(), list.Skip(i + 1).ToList(), }) .TakeWhile(a => a[0].Count + a[1].Count >= count) .ForEach(a => stack.Push(a)); } } } public static IEnumerable<IEnumerable<T>> Permutation<T>(this IEnumerable<T> source, int count) { var stack = new Stack<IEnumerable<T>[]>(); stack.Push(new[] { Enumerable.Empty<T>(), source.ToList() }); while (stack.Count > 0) { var item = stack.Pop(); if (item[0].Count() == count) { yield return item[0]; } else { var list = item[1]; list.Select((a, i) => new[] { item[0].Concat(new[] { a }), list.Where((b, j) => j != i), }) .ForEach(a => stack.Push(a)); } } } public static IEnumerable<string> ReadAllLines() { return Repeat(ReadLine).TakeWhile(a => a != null); } public static List<int> SplitToIntList(this string source) { return source.Split().Select(a => int.Parse(a)).ToList(); } public static List<long> SplitToLongList(this string source) { return source.Split().Select(a => long.Parse(a)).ToList(); } public static List<double> SplitToDoubleList(this string source) { return source.Split().Select(a => double.Parse(a)).ToList(); } public static IEnumerable<T> Return<T>(params T[] source) { return source; } public static string JoinWithSpace<T>(this IEnumerable<T> source) { return string.Join(" ", source); } public static IEnumerable<T> Repeat<T>(this T source) { return Repeat(() => source); } public static IEnumerable<T> Repeat<T>(Func<T> selector) { while (true) yield return selector(); } public static IEnumerable<T> Recur<T>(this T source, Func<T, T> selector) { var p = source; while (true) { yield return p; p = selector(p); } } public static IEnumerable<T> Scan<T>(this IEnumerable<T> source, Func<T, T, T> selector) { return Scan(source, default(T), selector); } public static IEnumerable<T> Scan<T>(this IEnumerable<T> source, T seed, Func<T, T, T> selector) { var last = seed; foreach (var item in source) { last = selector(last, item); yield return last; } } public static void ForEach<T>(this IEnumerable<T> source, Action<T> unlessEmpty, Action ifEmpty = null) { using (var e = source.GetEnumerator()) { if (unlessEmpty != null && e.MoveNext()) { do unlessEmpty(e.Current); while (e.MoveNext()); } else { ifEmpty?.Invoke(); } } } public static void ForEach<T>(this IEnumerable<T> source, Action<T, int> unlessEmpty, Action ifEmpty = null) { using (var e = source.GetEnumerator()) { if (unlessEmpty != null && e.MoveNext()) { int i = 0; do { unlessEmpty(e.Current, i); i++; } while (e.MoveNext()); } else { ifEmpty?.Invoke(); } } } public static T WriteLine<T>(this T source) { Console.WriteLine(source); return source; } public static void WriteAllLines<T>(this IEnumerable<T> source) { foreach (var item in source) WriteLine(item); } public static TResult Chain<TSource, TResult>(this TSource source, Func<TSource, TResult> selector) { return selector(source); } public static T Chain<T>(this T source, Action<T> action) { action(source); return source; } public static IEnumerable<T> Do<T>(this IEnumerable<T> source, Action<T> action) { foreach (var a in source) { action(a); yield return a; } } #endregion #region Location struct Location { public Location(int x, int y) { X = x; Y = y; } public int X { get; private set; } public int Y { get; private set; } public override bool Equals(object obj) { if (!(obj is Location)) return false; var other = (Location)obj; return other != null && X == other.X && Y == other.Y; } public override int GetHashCode() { return X << 16 | Y | X >> 16; } public static bool operator ==(Location left, Location right) { return EqualityComparer<Location>.Default.Equals(left, right); } public static bool operator !=(Location left, Location right) { return !(left == right); } public static Location operator +(Location left, Location right) { return new Location(left.X + right.X, left.Y + right.Y); } public static Location operator -(Location left, Location right) { return new Location(left.X - right.X, left.Y - right.Y); } } #endregion #region D2 class D2<T> : IEnumerable<Location> { public D2(int width, int height, IEnumerable<T> items = null) { Width = width; Height = height; var size = Width * Height; Items = items?.ToArray() ?? new T[size]; if (Items.Length != size) throw new Exception(); } public int Width { get; private set; } public int Height { get; private set; } public T[] Items { get; private set; } public T this[int index] { get { return Items[index]; } set { Items[index] = value; } } public T this[int x, int y] { get { return Items[y * Width + x]; } set { Items[y * Width + x] = value; } } public T this[Location location] { get { return this[location.X, location.Y]; } set { this[location.X, location.Y] = value; } } public bool Contains(Location location) { return 0 <= location.X && 0 <= location.Y && location.X < Width && location.Y < Height; } public D2<T> Clone() { return new D2<T>(Width, Height, Items); } public IEnumerable<IEnumerable<Location>> EnumerateVertical() { return Enumerable.Range(0, Height).Select( y => Enumerable.Range(0, Width).Select(x => new Location(x, y))); } public IEnumerable<IEnumerable<Location>> EnumerateHorizontal() { return Enumerable.Range(0, Width).Select( x => Enumerable.Range(0, Height).Select(y => new Location(x, y))); } public IEnumerator<Location> GetEnumerator() { foreach (var item in EnumerateVertical().SelectMany(a => a)) { yield return item; } } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } #endregion #region Matrix class Matrix : D2<double> { public Matrix(int width, int height, IEnumerable<double> items = null) : base(width, height, items) {} public override bool Equals(object obj) { var other = obj as Matrix; return other != null && Width == other.Width && Height == other.Height && Items.Zip(other.Items, (a, b) => a == b).All(a => a); } public override int GetHashCode() { int hashCode = 1931280238; hashCode = hashCode * -1521134295 + Width.GetHashCode() + Height.GetHashCode() + Items.Select(a => a.GetHashCode()).Aggregate((a, b) => a ^ b); return hashCode; } public static bool operator ==(Matrix left, Matrix right) { return EqualityComparer<Matrix>.Default.Equals(left, right); } public static bool operator !=(Matrix left, Matrix right) { return !(left == right); } public static Matrix operator +(Matrix left, Matrix right) { if (left == null) throw new ArgumentNullException(nameof(left)); if (right == null) throw new ArgumentNullException(nameof(right)); if (left.Width != right.Width || left.Height != right.Height) throw new ArgumentException(nameof(right)); return new Matrix(left.Width, left.Height, left.Items.Zip(right.Items, (a, b) => a + b)); } public static Matrix operator -(Matrix left, Matrix right) { if (left == null) throw new ArgumentNullException(nameof(left)); if (right == null) throw new ArgumentNullException(nameof(right)); if (left.Width != right.Width || left.Height != right.Height) throw new ArgumentException(nameof(right)); return new Matrix(left.Width, left.Height, left.Items.Zip(right.Items, (a, b) => a - b)); } public static Matrix operator *(Matrix left, Matrix right) { if (left == null) throw new ArgumentNullException(nameof(left)); if (right == null) throw new ArgumentNullException(nameof(right)); if (left.Width != right.Height) throw new ArgumentException(nameof(right)); return new Matrix( right.Width, left.Height, left.EnumerateVertical().SelectMany( l => right.EnumerateHorizontal().Select( r => l.Zip(r, (a, b) => left[a] * right[b]).Sum()))); } public static Matrix operator +(Matrix left, double right) { if (left == null) throw new ArgumentNullException(nameof(left)); return new Matrix(left.Width, left.Height, left.Items.Select(a => a + right)); } public static Matrix operator -(Matrix left, double right) { if (left == null) throw new ArgumentNullException(nameof(left)); return new Matrix(left.Width, left.Height, left.Items.Select(a => a - right)); } public static Matrix operator *(Matrix left, double right) { if (left == null) throw new ArgumentNullException(nameof(left)); return new Matrix(left.Width, left.Height, left.Items.Select(a => a * right)); } public static Matrix operator /(Matrix left, double right) { if (left == null) throw new ArgumentNullException(nameof(left)); return new Matrix(left.Width, left.Height, left.Items.Select(a => a / right)); } public virtual string ToString(string format) { return EnumerateVertical() .Select(a => string.Join(" ", a.Select(b => this[b].ToString(format)))) .Chain(a => string.Join("\n", a)); } public override string ToString() { return ToString("0.00000"); } } class RotationMatrix : Matrix { public RotationMatrix(double radian) : base(2, 2, new[] { Math.Cos(radian), -Math.Sin(radian), Math.Sin(radian), Math.Cos(radian), }) {} public RotationMatrix(int degree) : this(Math.PI * degree / 180) {} } class RollMatrix : Matrix { public RollMatrix(double radian) : base(3, 3, new[] { Math.Cos(radian), -Math.Sin(radian), 0, Math.Sin(radian), Math.Cos(radian), 0, 0, 0, 1, }) {} public RollMatrix(int degree) : this(Math.PI * degree / 180) {} } class YawMatrix : Matrix { public YawMatrix(double radian) : base(3, 3, new[] { Math.Cos(radian), 0, -Math.Sin(radian), 0, 1, 0, Math.Sin(radian), 0, Math.Cos(radian), }) {} public YawMatrix(int degree) : this(Math.PI * degree / 180) {} } class PitchMatrix : Matrix { public PitchMatrix(double radian) : base(3, 3, new[] { 1, 0, 0, 0, Math.Cos(radian), -Math.Sin(radian), 0, Math.Sin(radian), Math.Cos(radian), }) {} public PitchMatrix(int degree) : this(Math.PI * degree / 180) {} } #endregion #region Prime class Prime { private static int mark = 2; private static readonly List<int> list = new List<int>(); private static readonly bool[] buffer = new bool[4096]; private Prime() {} public static IEnumerable<int> Get() { return list.Concat(GetNew()); } private static IEnumerable<int> GetNew() { while (true) { FillBuffer(); int l = list.Count; Enumerable.Range(0, buffer.Length) .Where(a => !buffer[a]) .ForEach(a => list.Add(mark + a)); mark += buffer.Length; for (int i = l; i < list.Count; i++) { yield return list[i]; } } } private static void FillBuffer() { Array.Clear(buffer, 0, buffer.Length); Enumerable.Range(0, list.Count).Select(a => list[a]).ForEach(a => { var o = mark % a; var n = o == 0 ? 0 : a - o; while (n < buffer.Length) { buffer[n] = true; n += a; } }); Enumerable.Range(0, buffer.Length) .Where(a => !buffer[a]) .Select(a => mark + a) .ForEach(a => (a * 2 - mark) .Recur(b => b + a) .TakeWhile(b => b < buffer.Length) .ForEach(b => buffer[b] = true)); } } #endregion } }
[["+", 0, 212, 0, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 12, 203]]
8
3,887
2
using System; using System.Collections.Generic; using System.Linq; namespace abc161 { class Program { static void Main(string[] args) { var nm = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); var a = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); var border = (a.Sum()) / (4 * nm[1]); var select = a.OrderByDescending(o => o).Take(nm[1]); var num = select.Where(x => x >= border).Count(); var ans = num == nm[1] ? "Yes" : "No"; Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; namespace abc161 { class Program { static void Main(string[] args) { var nm = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); var a = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); var border = (float)(a.Sum()) / (float)(4 * nm[1]); var select = a.OrderByDescending(o => o).Take(nm[1]); var num = select.Where(x => x >= border).Count(); var ans = num == nm[1] ? "Yes" : "No"; Console.WriteLine(ans); } } }
[["+", 0, 200, 0, 212, 0, 16, 31, 74, 39, 199], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 0, 25], ["+", 0, 212, 0, 16, 31, 74, 51, 23, 0, 24], ["+", 0, 200, 0, 212, 0, 16, 12, 74, 0, 24], ["+", 0, 200, 0, 212, 0, 16, 12, 74, 39, 199], ["+", 0, 200, 0, 212, 0, 16, 12, 74, 0, 25]]
8
175
6
using System; using System.Linq; namespace hello_cs { class Program { static void Main(string[] args) { var blank = " "; var num = System.Console.ReadLine().Split(blank.ToCharArray()); var n = int.Parse(num[0]); var m = int.Parse(num[1]); var vote = Console.ReadLine() .Split(blank.ToCharArray()) .Select(x => int.Parse(x)) .ToArray(); var all = 0; foreach (var i in vote) { all += i; } var fav = vote.Where(x => x >= all / (4 * m)).ToArray(); Console.WriteLine(fav.Count() >= m ? "Yes" : "No"); } } }
using System; using System.Linq; namespace hello_cs { class Program { static void Main(string[] args) { var blank = " "; var num = System.Console.ReadLine().Split(blank.ToCharArray()); var n = int.Parse(num[0]); var m = int.Parse(num[1]); var vote = Console.ReadLine() .Split(blank.ToCharArray()) .Select(x => int.Parse(x)) .ToArray(); var all = 0; foreach (var i in vote) { all += i; } var fav = vote.Where(x => x >= (double)all / (double)(4 * m)).ToArray(); Console.WriteLine(fav.Count() >= m ? "Yes" : "No"); } } }
[["+", 0, 218, 8, 16, 12, 16, 31, 74, 0, 24], ["+", 0, 218, 8, 16, 12, 16, 31, 74, 39, 199], ["+", 0, 218, 8, 16, 12, 16, 31, 74, 0, 25], ["+", 0, 218, 8, 16, 12, 16, 12, 74, 0, 24], ["+", 0, 218, 8, 16, 12, 16, 12, 74, 39, 199], ["+", 0, 218, 8, 16, 12, 16, 12, 74, 0, 25]]
8
177
6
using System; using System.Collections.Generic; using System.Numerics; using System.Linq; using static System.Math; class MainClass { public static void Main(string[] args) { var _ = LnInts(); var N = _[0]; var M = _[1]; var As = LnInts(); var total = 0; foreach (var i in As) { total += i; } var count = 0; foreach (var i in As) { if (i >= total / (4 * M)) count++; } Console.WriteLine(count >= M ? "Yes" : "No"); } public static long Gcd(long a, long b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } } public static int Gcd(int a, int b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } } public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; } public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); } public static long[] LnLngs() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new long[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = long.Parse(vs[i]); return ins; } public static long LnLng() { var vs = Console.ReadLine().Trim(); return long.Parse(vs); } public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; } public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; } }
using System; using System.Collections.Generic; using System.Numerics; using System.Linq; using static System.Math; class MainClass { public static void Main(string[] args) { var _ = LnInts(); var N = _[0]; var M = _[1]; var As = LnInts(); var total = 0; foreach (var i in As) { total += i; } var count = 0; foreach (var i in As) { if (i >= total / (4f * M)) count++; } Console.WriteLine(count >= M ? "Yes" : "No"); } public static long Gcd(long a, long b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } } public static int Gcd(int a, int b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } } public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; } public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); } public static long[] LnLngs() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new long[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = long.Parse(vs[i]); return ins; } public static long LnLng() { var vs = Console.ReadLine().Trim(); return long.Parse(vs); } public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; } public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; } }
[["-", 15, 16, 12, 16, 12, 23, 0, 16, 31, 203], ["+", 15, 16, 12, 16, 12, 23, 0, 16, 31, 250]]
8
576
2
using System; using System.Collections.Generic; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]); string[] numbers = Console.ReadLine().Split(' '); int total = 0; List<int> number = new List<int>(); for (int i = 0; i < n; i++) { number.Add(int.Parse(numbers[i])); total += number[i]; } number.Sort((a, b) => b.CompareTo(a)); if (number[m - 1] >= total / 4 / m) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
using System; using System.Collections.Generic; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]); string[] numbers = Console.ReadLine().Split(' '); long total = 0; List<int> number = new List<int>(); for (int i = 0; i < n; i++) { number.Add(int.Parse(numbers[i])); total += number[i]; } number.Sort((a, b) => b.CompareTo(a)); if (number[m - 1] >= total / 4.0 / m) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 250]]
8
200
4
using System; using System.Collections.Generic; using System.Linq; namespace B { class Program { static void Main(string[] args) { // 入力 string[] tmp = Console.ReadLine().Split(' '); int N = int.Parse(tmp[0]); int M = int.Parse(tmp[1]); tmp = Console.ReadLine().Split(' '); List<int> A = new List<int>(); for (int i = 0; i < tmp.Length; i++) { A.Add(int.Parse(tmp[i])); } // 選べる人気商品の数の探索 int ans = 0; for (int i = 0; i < A.Count; i++) { if (A[i] >= A.Sum() / (4 * M)) ans++; } if (ans >= M) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Collections.Generic; using System.Linq; namespace B { class Program { static void Main(string[] args) { // 入力 string[] tmp = Console.ReadLine().Split(' '); int N = int.Parse(tmp[0]); int M = int.Parse(tmp[1]); tmp = Console.ReadLine().Split(' '); List<int> A = new List<int>(); for (int i = 0; i < tmp.Length; i++) { A.Add(int.Parse(tmp[i])); } // 選べる人気商品の数の探索 int ans = 0; for (int i = 0; i < A.Count; i++) { if (A[i] >= A.Sum() / (4.0 * M)) ans++; } if (ans >= M) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["-", 15, 16, 12, 16, 12, 23, 0, 16, 31, 203], ["+", 15, 16, 12, 16, 12, 23, 0, 16, 31, 250]]
8
216
2
using System; class Program { static void Main(string[] arg) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]); int[] input2 = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); double sum = 0; for (int i = 0; i < n; i++) { sum += (double)input2[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < n - i - 1; j++) { if (input2[j] < input2[j + 1]) { int his = input2[j]; input2[j] = input2[j + 1]; input2[j + 1] = his; } } } // Console.WriteLine(string.Join(", ",input2)); double min = (double)input2[m - 1]; double criteria = sum / (4 * (double)m); // Console.WriteLine("min is {0} and criteria is {1}",min, criteria); if (min > criteria) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
using System; class Program { static void Main(string[] arg) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]); int[] input2 = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); double sum = 0; for (int i = 0; i < n; i++) { sum += (double)input2[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < n - i - 1; j++) { if (input2[j] < input2[j + 1]) { int his = input2[j]; input2[j] = input2[j + 1]; input2[j + 1] = his; } } } // Console.WriteLine(string.Join(", ",input2)); double min = (double)input2[m - 1]; double criteria = sum / (4 * (double)m); // Console.WriteLine("min is {0} and criteria is {1}",min, criteria); if (min >= criteria) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
8
259
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { public static void Main() { string[] input = Console.ReadLine().Split(); int N = int.Parse(input[0]); int M = int.Parse(input[1]); input = Console.ReadLine().Split(); int[] A = new int[N]; for (int i = 0; i < N; i++) { A[i] = int.Parse(input[i]); } int num = 0; for (int i = 0; i < N; i++) { if (A[i] >= A.Sum() / 4 / M) { num++; } } if (num >= M) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { public static void Main() { string[] input = Console.ReadLine().Split(); int N = int.Parse(input[0]); int M = int.Parse(input[1]); input = Console.ReadLine().Split(); double[] A = new double[N]; for (int i = 0; i < N; i++) { A[i] = int.Parse(input[i]); } int num = 0; for (int i = 0; i < N; i++) { if (A[i] >= A.Sum() / 4 / M) { num++; } } if (num >= M) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199]]
8
199
4
using System; using System.Collections.Generic; namespace tst { class Program { public static void Main() { string[] In1 = Console.ReadLine().Split(' '); int n = int.Parse(In1[0]); int m = int.Parse(In1[1]); string[] In2 = Console.ReadLine().Split(' '); int[] A = new int[n]; int sum = 0; for (int i = 0; i < n; i++) { A[i] = int.Parse(In2[i]); sum += A[i]; } int border = sum / (4 * m); int cnt = 0; for (int i = 0; i < n; i++) { if (A[i] >= border) cnt++; } if (cnt >= m) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Collections.Generic; namespace tst { class Program { public static void Main() { string[] In1 = Console.ReadLine().Split(' '); int n = int.Parse(In1[0]); int m = int.Parse(In1[1]); string[] In2 = Console.ReadLine().Split(' '); int[] A = new int[n]; int sum = 0; for (int i = 0; i < n; i++) { A[i] = int.Parse(In2[i]); sum += A[i]; } double border = sum / (4.0 * m); int cnt = 0; for (int i = 0; i < n; i++) { if (A[i] >= border) cnt++; } if (cnt >= m) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 212, 0, 16, 12, 23, 0, 16, 31, 203], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 31, 250]]
8
215
4
class program { static void Main() { bool test = true; string[] line1 = System.Console.ReadLine().Split(' '); string[] line2 = System.Console.ReadLine().Split(' '); string hozon; for (int z = 0; z < int.Parse(line1[0]); z++) { int max = 0; int za = 0; for (int v = z; v < line2.Length; v++) { if (max <= int.Parse(line2[v])) { max = int.Parse(line2[v]); za = v; } } hozon = line2[z]; line2[z] = max.ToString(); line2[za] = hozon; } int soutoku = 0; for (int x = 0; x < int.Parse(line1[0]); x++) { soutoku = soutoku + int.Parse(line2[x]); } for (int y = 0; y < int.Parse(line1[1]); y++) { if (soutoku / (4 * int.Parse(line1[1])) <= int.Parse(line2[y])) { test = true; } else { test = false; break; } } if (test) { System.Console.WriteLine("Yes"); } else { System.Console.WriteLine("No"); } } }
class program { static void Main() { bool test = true; string[] line1 = System.Console.ReadLine().Split(' '); string[] line2 = System.Console.ReadLine().Split(' '); string hozon; for (int z = 0; z < int.Parse(line1[0]); z++) { int max = 0; int za = 0; for (int v = z; v < line2.Length; v++) { if (max <= int.Parse(line2[v])) { max = int.Parse(line2[v]); za = v; } } hozon = line2[z]; line2[z] = max.ToString(); line2[za] = hozon; } double soutoku = 0; for (int x = 0; x < int.Parse(line1[0]); x++) { soutoku = soutoku + int.Parse(line2[x]); } for (int y = 0; y < int.Parse(line1[1]); y++) { if (soutoku / (4.0 * double.Parse(line1[1])) <= double.Parse(line2[y])) { test = true; } else { test = false; break; } } if (test) { System.Console.WriteLine("Yes"); } else { System.Console.WriteLine("No"); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 15, 16, 31, 16, 12, 23, 0, 16, 31, 203], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 31, 250], ["-", 12, 23, 0, 16, 12, 213, 63, 214, 205, 199], ["+", 12, 23, 0, 16, 12, 213, 63, 214, 205, 199], ["-", 0, 57, 15, 16, 12, 213, 63, 214, 205, 199], ["+", 0, 57, 15, 16, 12, 213, 63, 214, 205, 199]]
8
309
8
using System; using System.Collections.Generic; public class Hello { public static void Main() { var input = Console.ReadLine().Split(' '); var product = Console.ReadLine().Split(' '); var answer = ""; List<int> voteList = new List<int>(); int total = 0; for (var i = 0; i < int.Parse(input[0]); i++) { total += int.Parse(product[i]); voteList.Add(int.Parse(product[i])); } voteList.Sort((a, b) => b - a); if (voteList[int.Parse(input[1]) - 1] >= total / 4 / int.Parse(input[1])) { answer = "Yes"; } else { answer = "No"; } Console.WriteLine(answer); } }
using System; using System.Collections.Generic; public class Hello { public static void Main() { var input = Console.ReadLine().Split(' '); var product = Console.ReadLine().Split(' '); var answer = ""; List<int> voteList = new List<int>(); int total = 0; for (var i = 0; i < int.Parse(input[0]); i++) { total += int.Parse(product[i]); voteList.Add(int.Parse(product[i])); } voteList.Sort((a, b) => b - a); if ((double)(voteList[int.Parse(input[1]) - 1]) >= total / 4.0 / int.Parse(input[1])) { answer = "Yes"; } else { answer = "No"; } Console.WriteLine(answer); } }
[["+", 8, 196, 0, 57, 15, 16, 31, 74, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 74, 39, 199], ["+", 8, 196, 0, 57, 15, 16, 31, 74, 0, 25], ["+", 0, 57, 15, 16, 31, 74, 51, 23, 0, 24], ["+", 0, 57, 15, 16, 31, 74, 51, 23, 0, 25], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 250]]
8
201
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderB { static void Main() { var sc = new Scanner(); int n = sc.NextInt(); int m = sc.NextInt(); int[] a = sc.IntArray(); a = a.OrderByDescending(i => i).ToArray(); int sum = a.Sum(); for (int i = 0; i < m; i++) { if (a[i] * 4m < sum) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderB { static void Main() { var sc = new Scanner(); int n = sc.NextInt(); int m = sc.NextInt(); int[] a = sc.IntArray(); a = a.OrderByDescending(i => i).ToArray(); int sum = a.Sum(); for (int i = 0; i < m; i++) { if (a[i] * 4 * m < sum) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 250], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22]]
8
436
4
using System; namespace abc161B { class MainClass { public static void Main(string[] args) { string[] str = Console.ReadLine().Split(); int N = int.Parse(str[0]); int M = int.Parse(str[1]); long[] a = new long[N]; str = Console.ReadLine().Split(); for (int i = 0; i < N; i++) { a[i] = long.Parse(str[i]); } int A = 0; long K = 0; for (int i = 0; i < N; i++) { K += a[i]; } for (int i = 0; i < N; i++) { if (a[i] >= K / (4 * M)) A += 1; } if (A >= M) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
using System; namespace abc161B { class MainClass { public static void Main(string[] args) { string[] str = Console.ReadLine().Split(); int N = int.Parse(str[0]); int M = int.Parse(str[1]); long[] a = new long[N]; str = Console.ReadLine().Split(); for (int i = 0; i < N; i++) { a[i] = long.Parse(str[i]); } int A = 0; long K = 0; for (int i = 0; i < N; i++) { K += a[i]; } for (int i = 0; i < N; i++) { if (a[i] * 4 * M >= K) A += 1; } if (A >= M) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 85], ["-", 0, 57, 15, 16, 12, 16, 12, 23, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 48], ["-", 0, 57, 15, 16, 12, 16, 12, 23, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22]]
8
211
8
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace CSharpSample01 { class Program { static void Main(string[] args) { var inputNum = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var N = inputNum[0]; var M = inputNum[1]; var inputNum2 = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); // 合計値 var total = inputNum2.Sum(); // 条件 // var rate = (total / (4 * M)); var overRateNum = inputNum2.Where(x => x * 4 * M > total).Count(); if (overRateNum >= M) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } public static long Gcd(long a, long b) { if (a < b) return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace CSharpSample01 { class Program { static void Main(string[] args) { var inputNum = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var N = inputNum[0]; var M = inputNum[1]; var inputNum2 = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); // 合計値 var total = inputNum2.Sum(); // 条件 // var rate = (total / (4 * M)); var overRateNum = inputNum2.Where(x => x * 4 * M >= total).Count(); if (overRateNum >= M) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } public static long Gcd(long a, long b) { if (a < b) return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } } }
[["-", 3, 4, 0, 28, 0, 218, 8, 16, 17, 47], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 20]]
8
225
2
using System; using System.Collections.Generic; using System.Linq; namespace A { class Program { public static void Main(string[] args) { var n = ReadLineIntSpilit(); var a = ReadLineIntSpilit(); var all = 0; for (int i = 0; i < a.Length; i++) { all += a[i]; } var result = "Yes"; //降順 a = a.OrderBy(x => -x).ToArray(); for (int i = 0; i < n[1]; i++) { if (a[i] < all / (4 * n[1])) { result = "No"; break; } } Console.WriteLine(result); ReadLine(); } //最大公約数 static int gcd(int a, int b) { if (a > b) { return gcd(b, a); } while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } //最小公倍数 static int lcm(int a, int b) => a * b / gcd(a, b); /// <summary> /// コンビネーション /// </summary> static int nCm(int n, int m) { if (m == 0) return 1; if (n == 0) return 0; return n * nCm(n - 1, m - 1) / m; } public static string ReadLine() => Console.ReadLine(); public static int ReadLineInt() => int.Parse(Console.ReadLine()); public static string[] ReadLineStringSplit(char a = ' ') => ReadLine().Split(a).ToArray(); public static int[] ReadLineIntSpilit(char a = ' ') => ReadLine().Split(a).Select(x => int.Parse(x)).ToArray(); public static long[] ReadLineLongSpilit(char a = ' ') => ReadLine().Split(a).Select(x => long.Parse(x)).ToArray(); static string[] GetAplhaLowerArray() => new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; static string[] GetAplhaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; } }
using System; using System.Collections.Generic; using System.Linq; namespace A { class Program { public static void Main(string[] args) { var n = ReadLineIntSpilit(); var a = ReadLineIntSpilit(); var all = 0; for (int i = 0; i < a.Length; i++) { all += a[i]; } var result = "Yes"; //降順 a = a.OrderBy(x => -x).ToArray(); for (int i = 0; i < n[1]; i++) { if (a[i] < (all * 1.0 / (4 * n[1]))) { result = "No"; break; } } Console.WriteLine(result); ReadLine(); } //最大公約数 static int gcd(int a, int b) { if (a > b) { return gcd(b, a); } while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } //最小公倍数 static int lcm(int a, int b) => a * b / gcd(a, b); /// <summary> /// コンビネーション /// </summary> static int nCm(int n, int m) { if (m == 0) return 1; if (n == 0) return 0; return n * nCm(n - 1, m - 1) / m; } public static string ReadLine() => Console.ReadLine(); public static int ReadLineInt() => int.Parse(Console.ReadLine()); public static string[] ReadLineStringSplit(char a = ' ') => ReadLine().Split(a).ToArray(); public static int[] ReadLineIntSpilit(char a = ' ') => ReadLine().Split(a).Select(x => int.Parse(x)).ToArray(); public static long[] ReadLineLongSpilit(char a = ' ') => ReadLine().Split(a).Select(x => long.Parse(x)).ToArray(); static string[] GetAplhaLowerArray() => new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; static string[] GetAplhaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; } }
[["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 17, 48], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 12, 250], ["+", 15, 16, 12, 23, 0, 16, 12, 23, 0, 25]]
8
663
4
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace ABC161 { public class Solve { public static void Main(string[] args) { new ABC_B(); } } public class ABC_A { public ABC_A() { var i = Ex.ReadIntArray(); Ex.Cw($"{i[2]} {i[0]} {i[1]}"); } } public class ABC_B { public ABC_B() { var l1 = Ex.ReadIntArray(); var arr = Ex.ReadIntArray(); // N 種類の商品 var n = l1[0]; // M個を選べる var m = l1[1]; // 総投票数の1/4M未満である var d = arr.Sum() / 4.0 / m; var c = arr.Count(v => d < v); Ex.Cw(m <= c); } public void Cw(bool b) { if (b) Ex.Cw("Yes"); else Ex.Cw("No"); } } public class ABC_C { public ABC_C() {} } public class ABC_D { public ABC_D() {} } public class ABC_E { public ABC_E() {} } public class ABC_F { public ABC_F() {} } public static class Ex { public static void Cw(object s) { Console.WriteLine(s); } public static void Cw(bool b) { if (b) Cw("Yes"); else Cw("No"); } public static string Read { get { return Console.ReadLine().Trim(); } } public static int ReadInt { get { return int.Parse(Read); } } public static long ReadLong { get { return long.Parse(Read); } } public static double ReadDouble { get { return double.Parse(Read); } } public static string[] ReadArray() { return Read.Split(' '); } public static int[] ReadIntArray() { return Read.Split(' ').Select(s => int.Parse(s)).ToArray(); } public static long[] ReadLongArray() { return Read.Split(' ').Select(s => long.Parse(s)).ToArray(); } public static string[] ReadArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public static int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public static long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace ABC161 { public class Solve { public static void Main(string[] args) { new ABC_B(); } } public class ABC_A { public ABC_A() { var i = Ex.ReadIntArray(); Ex.Cw($"{i[2]} {i[0]} {i[1]}"); } } public class ABC_B { public ABC_B() { var l1 = Ex.ReadIntArray(); var arr = Ex.ReadIntArray(); // N 種類の商品 var n = l1[0]; // M個を選べる var m = l1[1]; // 総投票数の1/4M未満である var d = arr.Sum() / 4.0 / m; var c = arr.Count(v => d <= v); Ex.Cw(m <= c); } public void Cw(bool b) { if (b) Ex.Cw("Yes"); else Ex.Cw("No"); } } public class ABC_C { public ABC_C() {} } public class ABC_D { public ABC_D() {} } public class ABC_E { public ABC_E() {} } public class ABC_F { public ABC_F() {} } public static class Ex { public static void Cw(object s) { Console.WriteLine(s); } public static void Cw(bool b) { if (b) Cw("Yes"); else Cw("No"); } public static string Read { get { return Console.ReadLine().Trim(); } } public static int ReadInt { get { return int.Parse(Read); } } public static long ReadLong { get { return long.Parse(Read); } } public static double ReadDouble { get { return double.Parse(Read); } } public static string[] ReadArray() { return Read.Split(' '); } public static int[] ReadIntArray() { return Read.Split(' ').Select(s => int.Parse(s)).ToArray(); } public static long[] ReadLongArray() { return Read.Split(' ').Select(s => long.Parse(s)).ToArray(); } public static string[] ReadArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public static int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public static long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
[["-", 3, 4, 0, 28, 0, 218, 8, 16, 17, 18], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 19]]
8
604
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); var numArray = input.Select(x => long.Parse(x)).ToArray(); var input2 = Console.ReadLine().Split(' '); var numArray2 = input2.Select(x => long.Parse(x)).ToArray(); long max = 0; for (int i = 0; i < numArray2.Count(); i++) { max += numArray2[i]; } var choose = max / (4 * numArray[1]); var choosed = numArray2.Where(x => x >= choose); if (choosed.Count() >= numArray[1]) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); var numArray = input.Select(x => long.Parse(x)).ToArray(); var input2 = Console.ReadLine().Split(' '); var numArray2 = input2.Select(x => long.Parse(x)).ToArray(); double max = 0; for (int i = 0; i < numArray2.Count(); i++) { max += numArray2[i]; } var choose = max / (4 * numArray[1]); var choosed = numArray2.Where(x => x >= choose); if (choosed.Count() >= numArray[1]) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
216
2
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace B_Popular_Vote { class Program { static void Main(string[] args) { string ans = "No"; int count = 0; string[] str = Console.ReadLine().Split(' '); int n = int.Parse(str[0]); int m = int.Parse(str[1]); string[] str2 = Console.ReadLine().Split(' '); int[] a = {}; a = new int[n]; for (int j = 0; j < n; j++) { a[j] = int.Parse(str2[j]); } double shor = a.Sum() / (4 * m); for (int i = 0; i < n; i++) { if (shor <= a[i]) { count++; if (count >= m) { ans = "Yes"; } } } Console.WriteLine(ans); } } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace B_Popular_Vote { class Program { static void Main(string[] args) { string ans = "No"; int count = 0; //入力++++++++++++++++++++++++++++++++++++++++++++++++ string[] str = Console.ReadLine().Split(' '); int n = int.Parse(str[0]); int m = int.Parse(str[1]); string[] str2 = Console.ReadLine().Split(' '); int[] a = {}; a = new int[n]; for (int j = 0; j < n; j++) { a[j] = int.Parse(str2[j]); } //++++++++++++++++++++++++++++++++++++++++++++++++++++ double shor = a.Sum() / (4.0 * (double)m); for (int i = 0; i < n; i++) { if (shor <= a[i]) { count++; if (count >= m) { ans = "Yes"; } } } Console.WriteLine(ans); } } }
[["-", 0, 212, 0, 16, 12, 23, 0, 16, 31, 203], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 31, 250], ["+", 0, 16, 12, 23, 0, 16, 12, 74, 0, 24], ["+", 0, 16, 12, 23, 0, 16, 12, 74, 39, 199], ["+", 0, 16, 12, 23, 0, 16, 12, 74, 0, 25]]
8
226
5
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace AtCorder { public static class Program { static public void Main(string[] args) { long[] input1 = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); long[] input2 = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); Array.Sort(input2); Array.Reverse(input2); Boolean flg = false; long total = 0; foreach (int num in input2) { total = num + total; } for (int i = 0; i < input1[1]; i++) { if (input2[i] >= total / (input1[1] * 4)) { flg = true; } else { flg = false; break; } } if (flg) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace AtCorder { public static class Program { static public void Main(string[] args) { long[] input1 = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); long[] input2 = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); Array.Sort(input2); Array.Reverse(input2); Boolean flg = false; decimal total = 0; foreach (long num in input2) { total = num + total; } for (int i = 0; i < input1[1]; i++) { if (input2[i] >= total / (input1[1] * 4)) { flg = true; } else { flg = false; break; } } if (flg) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 39, 199], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 39, 199]]
8
218
4
using System; using System.Linq; class Program { static void Main(string[] args) { string[] input1 = Console.ReadLine().Split(' '); string[] input2 = Console.ReadLine().Split(' '); int n = int.Parse(input1[0]); int m = int.Parse(input1[1]); int[] a = Array.ConvertAll(input2, int.Parse); int ans = 0, sum = a.Sum(); for (int i = 0; i < n; i++) { if (a[i] >= sum / (4 * m)) { ans++; } } if (ans >= m) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
using System; using System.Linq; class Program { static void Main(string[] args) { string[] input1 = Console.ReadLine().Split(' '); string[] input2 = Console.ReadLine().Split(' '); int n = int.Parse(input1[0]); int m = int.Parse(input1[1]); int[] a = Array.ConvertAll(input2, int.Parse); int ans = 0, sum = a.Sum(); for (int i = 0; i < n; i++) { if (a[i] >= sum / (4.0 * m)) { ans++; } } if (ans >= m) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
[["-", 15, 16, 12, 16, 12, 23, 0, 16, 31, 203], ["+", 15, 16, 12, 16, 12, 23, 0, 16, 31, 250]]
8
179
2
using System; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var nm = Console.ReadLine().Split(' '); // 商品の数 var n = long.Parse(nm[0]); // 人気商品の数 var m = long.Parse(nm[1]); // 得票数 var a = (from x in Console.ReadLine().Split(' ') select long.Parse(x)) .ToArray(); // 得票数 var sum = a.Sum() / (4 * m); var k = 0; foreach (var b in a) { if (b >= sum) k++; } Console.WriteLine(k >= m ? "Yes" : "No"); } } }
using System; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var nm = Console.ReadLine().Split(' '); // 商品の数 var n = long.Parse(nm[0]); // 人気商品の数 var m = long.Parse(nm[1]); // 得票数 var a = (from x in Console.ReadLine().Split(' ') select long.Parse(x)) .ToArray(); // 得票数 var sum = a.Sum() / (4m * m); var k = 0; foreach (var b in a) { if (b >= sum) k++; } Console.WriteLine(k >= m ? "Yes" : "No"); } } }
[["-", 0, 212, 0, 16, 12, 23, 0, 16, 31, 203], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 31, 250]]
8
160
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.AtCoder_Begginer_Contest_161 { class B { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int M = int.Parse(input[1]); string[] A = Console.ReadLine().Split(' '); int sum = 0; foreach (var a in A) { sum += int.Parse(a); } double limit = sum / (4 * M); int count = 0; foreach (var a in A) { if (limit <= int.Parse(a)) { count++; } } Console.WriteLine(M <= count ? "Yes" : "No"); // Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.AtCoder_Begginer_Contest_161 { class B { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int M = int.Parse(input[1]); string[] A = Console.ReadLine().Split(' '); int sum = 0; foreach (var a in A) { sum += int.Parse(a); } double limit = sum / (4.0 * M); int count = 0; foreach (var a in A) { if (limit <= int.Parse(a)) { count++; } } Console.WriteLine(M <= count ? "Yes" : "No"); // Console.ReadKey(); } } }
[["-", 0, 212, 0, 16, 12, 23, 0, 16, 31, 203], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 31, 250]]
8
192
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace B { class Program { static void Main(string[] args) { var info = Console.ReadLine().Split(' '); var vote = Console.ReadLine().Split(' '); var nums = new int[int.Parse(info[0])]; var sum = 0; var count = 0; for (int i = 0; i < int.Parse(info[0]); i++) { nums[i] = int.Parse(vote[i]); } foreach (int num in nums) { sum += num; } double check = sum / (4 * int.Parse(info[1])); foreach (int num in nums) { if (num >= check) { count++; } } if (count >= int.Parse(info[1])) Console.WriteLine("Yes"); else Console.WriteLine("No"); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace B { class Program { static void Main(string[] args) { var info = Console.ReadLine().Split(' '); var vote = Console.ReadLine().Split(' '); var nums = new int[int.Parse(info[0])]; double sum = 0; var count = 0; for (int i = 0; i < int.Parse(info[0]); i++) { nums[i] = int.Parse(vote[i]); } foreach (int num in nums) { sum += num; } double check = sum / (4 * int.Parse(info[1])); // Console.WriteLine(check); foreach (int num in nums) { if (num >= check) { count++; } } if (count >= int.Parse(info[1])) Console.WriteLine("Yes"); else Console.WriteLine("No"); Console.ReadKey(); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
235
2
using System; using System.Collections.Generic; namespace ABC161b { class Program { static void Main(string[] args) { var s = Console.ReadLine().Split(' '); int n = int.Parse(s[0]); int m = int.Parse(s[1]); var t = Console.ReadLine().Split(' '); int all = 0; List<int> list = new List<int>(); for (int i = 0; i < n; i++) { int a = int.Parse(t[i]); all += a; list.Add(a); } int count = 0; double th = all / (4 * m); foreach (var item in list) { if (item < th) { continue; } count++; if (count >= m) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); } } }
using System; using System.Collections.Generic; namespace ABC161b { class Program { static void Main(string[] args) { var s = Console.ReadLine().Split(' '); int n = int.Parse(s[0]); int m = int.Parse(s[1]); var t = Console.ReadLine().Split(' '); int all = 0; List<int> list = new List<int>(); for (int i = 0; i < n; i++) { int a = int.Parse(t[i]); all += a; list.Add(a); } int count = 0; double th = (double)all / (4 * m); foreach (var item in list) { if (item < th) { continue; } count++; if (count >= m) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); } } }
[["+", 0, 200, 0, 212, 0, 16, 31, 74, 0, 24], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 39, 199], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 0, 25]]
8
212
3
using System; using System.Collections.Generic; using static System.Math; using System.Linq; using System.Text; class DandA { static void Main(string[] args) { int[] nm = ReadLineIntArray(); int[] aArr = ReadLineIntArray(); int wari = aArr.Sum() / (nm[1] * 4); if (aArr.Sum() % (nm[1] * 4) != 0) { wari++; } Array.Sort(aArr); int rtn = 0; for (int i = nm[0] - 1; i >= (nm[1] - 1); i--) { rtn++; if (wari > aArr[i]) { break; } if (nm[1] == rtn) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); } static private int CountChar(string s, string c) { return s.Length - s.Replace(c, "").Length; } static string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; static string[] strAry = new string[] { "L", "R", "U", "D" }; static int[] intArray = new int[10]; static List<int> intList = new List<int>(); static Dictionary<string, int> myTable = new Dictionary<string, int>(); static HashSet<int>[] rtnArrAb = null; static HashSet<int>[] rtnArrCd = null; static long[,] C = new long[2001, 2001]; static long div = 1000000007; static private string ReadLineStr() { return Console.ReadLine(); } static private int ReadLineInt() { return int.Parse(Console.ReadLine()); } static private long ReadLineLong() { return long.Parse(Console.ReadLine()); } static private double ReadLineDouble() { return double.Parse(Console.ReadLine()); } static private string[] ReadLineStrArray() { return Console.ReadLine().Trim().Split(); } static private int[] ReadLineIntArray() { return Console.ReadLine() .Trim() .Split() .Select(a => int.Parse(a)) .ToArray(); } static private long[] ReadLineLongArray() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToArray(); } static private double[] ReadLineDoubleArray() { return Console.ReadLine() .Trim() .Split() .Select(a => double.Parse(a)) .ToArray(); } static private decimal[] ReadLineDecimalArray() { return Console.ReadLine() .Trim() .Split() .Select(a => decimal.Parse(a)) .ToArray(); } static private List<int> ReadLineIntList() { return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToList(); } static private List<long> ReadLineLongList() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToList(); } static private string[][] ReadMLineStrArray(int arg) { return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray(); } static private int[][] ReadMLineIntArray(int arg) { return new int [arg] .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); } static private bool IsPrime(int num) { if (num < 2) return false; if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; } return true; } static private string IntToNString(int x, int n) { var nstring = ""; var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; int r = 1; int q = x; while (q > 0) { r = q % n; nstring += numbers[r]; q = q / n; } return string.Join("", nstring.Reverse()); } static private long Gcd(long m, long n) { long temp; while (m % n != 0) { temp = n; n = m % n; m = temp; } return n; } static private long Combination(long n, long r) { if (n < r) { return 0; } if (n == r || r == 0) { return 1; } else if (C[n, r] == 0) { C[n, r] = (Combination(n - 1, r - 1) + Combination(n - 1, r)) % div; } return C[n, r]; } }
using System; using System.Collections.Generic; using static System.Math; using System.Linq; using System.Text; class DandA { static void Main(string[] args) { int[] nm = ReadLineIntArray(); int[] aArr = ReadLineIntArray(); int wari = aArr.Sum() / (nm[1] * 4); if (aArr.Sum() % (nm[1] * 4) != 0) { wari++; } Array.Sort(aArr); int rtn = 0; for (int i = nm[0] - 1; i >= (nm[0] - nm[1]); i--) { rtn++; if (wari > aArr[i]) { break; } if (nm[1] == rtn) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); } static private int CountChar(string s, string c) { return s.Length - s.Replace(c, "").Length; } static string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; static string[] strAry = new string[] { "L", "R", "U", "D" }; static int[] intArray = new int[10]; static List<int> intList = new List<int>(); static Dictionary<string, int> myTable = new Dictionary<string, int>(); static HashSet<int>[] rtnArrAb = null; static HashSet<int>[] rtnArrCd = null; static long[,] C = new long[2001, 2001]; static long div = 1000000007; static private string ReadLineStr() { return Console.ReadLine(); } static private int ReadLineInt() { return int.Parse(Console.ReadLine()); } static private long ReadLineLong() { return long.Parse(Console.ReadLine()); } static private double ReadLineDouble() { return double.Parse(Console.ReadLine()); } static private string[] ReadLineStrArray() { return Console.ReadLine().Trim().Split(); } static private int[] ReadLineIntArray() { return Console.ReadLine() .Trim() .Split() .Select(a => int.Parse(a)) .ToArray(); } static private long[] ReadLineLongArray() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToArray(); } static private double[] ReadLineDoubleArray() { return Console.ReadLine() .Trim() .Split() .Select(a => double.Parse(a)) .ToArray(); } static private decimal[] ReadLineDecimalArray() { return Console.ReadLine() .Trim() .Split() .Select(a => decimal.Parse(a)) .ToArray(); } static private List<int> ReadLineIntList() { return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToList(); } static private List<long> ReadLineLongList() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToList(); } static private string[][] ReadMLineStrArray(int arg) { return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray(); } static private int[][] ReadMLineIntArray(int arg) { return new int [arg] .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); } static private bool IsPrime(int num) { if (num < 2) return false; if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; } return true; } static private string IntToNString(int x, int n) { var nstring = ""; var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; int r = 1; int q = x; while (q > 0) { r = q % n; nstring += numbers[r]; q = q / n; } return string.Join("", nstring.Reverse()); } static private long Gcd(long m, long n) { long temp; while (m % n != 0) { temp = n; n = m % n; m = temp; } return n; } static private long Combination(long n, long r) { if (n < r) { return 0; } if (n == r || r == 0) { return 1; } else if (C[n, r] == 0) { C[n, r] = (Combination(n - 1, r - 1) + Combination(n - 1, r)) % div; } return C[n, r]; } }
[["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 23, 0, 16, 12, 204, 205, 22], ["+", 12, 23, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 23, 0, 16, 12, 204, 206, 207, 0, 73]]
8
1,142
5
using System; using System.Collections.Generic; using System.Linq; namespace PaizaTest { class Program { static void Main(string[] args) { var NM = Console.ReadLine().Split().Select(int.Parse).ToList(); var As = Console.ReadLine().Split().Select(int.Parse).ToList(); var sumA = As.Sum(); var borderVoteCount = sumA / (4 * NM[1]); // sumA / (4 * M) >= Aiの場合のみ選べる var selectableCount = As.Count(x => x >= borderVoteCount); Console.WriteLine(selectableCount >= NM[1] ? "Yes" : "No"); } } }
using System; using System.Collections.Generic; using System.Linq; namespace PaizaTest { class Program { static void Main(string[] args) { var NM = Console.ReadLine().Split().Select(int.Parse).ToList(); var As = Console.ReadLine().Split().Select(int.Parse).ToList(); var sumA = As.Sum(); var borderVoteCount = sumA / (4.0 * NM[1]); // sumA / (4 * M) >= Aiの場合のみ選べる var selectableCount = As.Count(x => x >= borderVoteCount); Console.WriteLine(selectableCount >= NM[1] ? "Yes" : "No"); } } }
[["-", 0, 212, 0, 16, 12, 23, 0, 16, 31, 203], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 31, 250]]
8
140
2
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; public class Program { public static void Main() { int[] nm = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int n = nm[0]; int m = nm[1]; int[] a_array = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); Array.Sort(a_array); Array.Reverse(a_array); int sumA = 0; foreach (int a in a_array) { sumA += a; } if (a_array[m - 1] >= sumA / (4 * m)) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; public class Program { public static void Main() { int[] nm = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int n = nm[0]; int m = nm[1]; int[] a_array = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); Array.Sort(a_array); Array.Reverse(a_array); int sumA = 0; foreach (int a in a_array) { sumA += a; } if (a_array[m - 1] * (4 * m) >= sumA) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 85], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22]]
8
206
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace practice001 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); string[] input2 = Console.ReadLine().Split(' '); int allGoods = int.Parse(input[0]); int choiceGoods = int.Parse(input[1]); int min = 4 * choiceGoods; int[] voteNum = new int[allGoods]; for (int i = 0; i < allGoods; i++) { voteNum[i] = int.Parse(input2[i]); } int allVoteNum = 0; for (int i = 0; i < allGoods; i++) { allVoteNum = allVoteNum + voteNum[i]; } int count = 0; for (int i = 0; i < allGoods; i++) { if (allVoteNum / voteNum[i] <= min) { count += 1; } } if (count >= choiceGoods) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace practice001 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); string[] input2 = Console.ReadLine().Split(' '); int allGoods = int.Parse(input[0]); int choiceGoods = int.Parse(input[1]); int min = 4 * choiceGoods; int[] voteNum = new int[allGoods]; for (int i = 0; i < allGoods; i++) { voteNum[i] = int.Parse(input2[i]); } int allVoteNum = 0; for (int i = 0; i < allGoods; i++) { allVoteNum = allVoteNum + voteNum[i]; } int count = 0; for (int i = 0; i < allGoods; i++) { if (allVoteNum <= min * voteNum[i]) { count += 1; } } if (count >= choiceGoods) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 85], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 48], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22]]
8
254
6
using System; using System.Linq; class Program { static void Main(string[] args) { // input string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]); string[] input2 = Console.ReadLine().Split(' '); var a = new int[n]; for (int i = 0; i < n; i++) { a[i] = int.Parse(input2[i]); } var touhyouSuu = a.Sum(x => x); var ninkiTouhyouSuu = (decimal)(touhyouSuu / (4 * m)); Array.Sort(a); Array.Reverse(a); for (int i = 0; i < m; i++) { if (a[i] < ninkiTouhyouSuu) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); } }
using System; using System.Linq; class Program { static void Main(string[] args) { // input string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); decimal m = int.Parse(input[1]); string[] input2 = Console.ReadLine().Split(' '); var a = new int[n]; for (int i = 0; i < n; i++) { a[i] = int.Parse(input2[i]); } decimal touhyouSuu = a.Sum(x => x); var ninkiTouhyouSuu = (decimal)(touhyouSuu / (4 * m)); Array.Sort(a); Array.Reverse(a); for (int i = 0; i < m; i++) { if (a[i] < ninkiTouhyouSuu) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217]]
8
215
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace q2 { class Program { static void Main(string[] args) { var values1 = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray(); var values2 = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray(); var N = values1[0]; var M = values1[1]; var cnt = 0; var total = 0; foreach (var v in values2) { total += v; } foreach (var v in values2) { if (v >= (total / (4 * M))) { cnt += 1; } } var result = cnt >= M; Console.WriteLine(result ? "Yes" : "No"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace q2 { class Program { static void Main(string[] args) { var values1 = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray(); var values2 = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray(); var N = values1[0]; var M = values1[1]; var cnt = 0; var total = 0; foreach (var v in values2) { total += v; } foreach (var v in values2) { if ((v * (4 * M)) >= total) { cnt += 1; } } var result = cnt >= M; Console.WriteLine(result ? "Yes" : "No"); } } }
[["-", 0, 210, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 0, 57, 15, 16, 12, 23, 0, 16, 31, 22], ["-", 0, 57, 15, 16, 12, 23, 0, 16, 17, 85], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 17, 48], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 12, 22]]
8
200
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp5 { class Program { static void Main(string[] args) { String S = Console.ReadLine(); String[] line = S.Split(' '); long N = long.Parse(line[0]); long M = long.Parse(line[1]); long[] A = new long[N]; long count = 0; S = Console.ReadLine(); line = S.Split(' '); for (long i = 0; i < N; i++) { A[i] = long.Parse(line[i]); } long sum = A.Sum(); for (long i = 0; i < N; i++) { if (A[i] >= sum / (4 * M)) { count++; } } if (count >= M) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp5 { class Program { static void Main(string[] args) { String S = Console.ReadLine(); String[] line = S.Split(' '); long N = long.Parse(line[0]); long M = long.Parse(line[1]); long[] A = new long[N]; long count = 0; S = Console.ReadLine(); line = S.Split(' '); for (long i = 0; i < N; i++) { A[i] = long.Parse(line[i]); } long sum = A.Sum(); for (long i = 0; i < N; i++) { if (A[i] >= sum / (4.0 * M)) { count++; } } if (count >= M) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["-", 15, 16, 12, 16, 12, 23, 0, 16, 31, 203], ["+", 15, 16, 12, 16, 12, 23, 0, 16, 31, 250]]
8
235
2
using System; using System.Collections.Generic; using System.Linq; using System.IO; static class Program { static int[] ReadInts(this TextReader reader) => reader.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); static IEnumerable<int[]> ReadInts(this TextReader reader, int count) { for (long i = 0; i < count; ++i) yield return reader.ReadInts(); } static IEnumerable<long[]> ReadLongs(this TextReader reader, long count) { for (long i = 0; i < count; ++i) yield return reader.ReadLine() .Split(' ') .Select(s => long.Parse(s)) .ToArray(); } public static void Main(string[] args) { var m = Console.In.ReadInts()[1]; var a = Console.In.ReadInts(); var sum = a.Sum(); var t = sum / (4 * m); var last = a.OrderByDescending(x => x).Skip(m - 1).First(); Console.WriteLine(last >= t ? "Yes" : "No"); } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; static class Program { static int[] ReadInts(this TextReader reader) => reader.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); static IEnumerable<int[]> ReadInts(this TextReader reader, int count) { for (long i = 0; i < count; ++i) yield return reader.ReadInts(); } static IEnumerable<long[]> ReadLongs(this TextReader reader, long count) { for (long i = 0; i < count; ++i) yield return reader.ReadLine() .Split(' ') .Select(s => long.Parse(s)) .ToArray(); } public static void Main(string[] args) { var m = Console.In.ReadInts()[1]; var a = Console.In.ReadInts(); var sum = a.Sum(); var t = sum / (4.0 * m); var last = a.OrderByDescending(x => x).Skip(m - 1).First(); Console.WriteLine(last >= t ? "Yes" : "No"); } }
[["-", 0, 212, 0, 16, 12, 23, 0, 16, 31, 203], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 31, 250]]
8
265
2
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var inp = Console.ReadLine().Split(' '); var inp2 = Console.ReadLine().Split(' '); var inp2i = new List<int>(); for (int i = 0; i < int.Parse(inp[0]); i++) { inp2i.Add(int.Parse(inp2[i])); } inp2i.Sort(); float inp2iNum = inp2i.Sum(); for (int i = 0; i < int.Parse(inp[1]); i++) { if (inp2i[i] < inp2iNum / (4 * int.Parse(inp[1]))) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var inp = Console.ReadLine().Split(' '); var inp2 = Console.ReadLine().Split(' '); var inp2i = new List<int>(); for (int i = 0; i < int.Parse(inp[0]); i++) { inp2i.Add(int.Parse(inp2[i])); } inp2i.Sort(); inp2i.Reverse(); float inp2iNum = inp2i.Sum(); for (int i = 0; i < int.Parse(inp[1]); i++) { if (inp2i[i] < inp2iNum / (4 * int.Parse(inp[1]))) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
196
6
using System; class SS { static void Main() { var lines = Console.ReadLine().Split(' '); int M = int.Parse(lines[0]); int N = int.Parse(lines[1]); lines = Console.ReadLine().Split(' '); int[] goods = new int[M]; int AmountGoods = 0; for (int i = 0; i < M; i++) { goods[i] = int.Parse(lines[i]); AmountGoods += goods[i]; } AmountGoods = AmountGoods / (4 * N); for (int i = 0; i < M; i++) { if (goods[i] >= AmountGoods) N--; if (N <= 0) break; } if (N <= 0) Console.WriteLine("Yes"); else Console.WriteLine("No"); } }
using System; class SS { static void Main() { var lines = Console.ReadLine().Split(' '); int M = int.Parse(lines[0]); int N = int.Parse(lines[1]); lines = Console.ReadLine().Split(' '); int[] goods = new int[M]; float AmountGoods = 0; for (int i = 0; i < M; i++) { goods[i] = int.Parse(lines[i]); AmountGoods += goods[i]; } AmountGoods = (float)AmountGoods / (4 * N); // Console.WriteLine(AmountGoods); for (int i = 0; i < M; i++) { if (goods[i] >= AmountGoods) N--; if (N <= 0) break; } if (N <= 0) Console.WriteLine("Yes"); else Console.WriteLine("No"); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 1, 0, 11, 12, 16, 31, 74, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 31, 74, 39, 199], ["+", 0, 1, 0, 11, 12, 16, 31, 74, 0, 25]]
8
196
5
using System; using System.Collections.Generic; using System.Linq; class Ho { static void Main() { var zennbu = Console.ReadLine().Split(); var N = int.Parse(zennbu[0]); var M = int.Parse(zennbu[1]); var syurui = new List<int>(); var a = Console.ReadLine().Split(); foreach (var n in a) { syurui.Add(int.Parse(n)); } int goukei = syurui.Sum(); int ikeru = 0; var ookii = syurui.OrderByDescending(x => x).ToList(); for (var i = 0; i < M; i++) { if (ookii[i] * 4 >= (goukei / M)) { } else { ikeru = 1; Console.WriteLine("No"); return; } } if (ikeru == 0) { Console.WriteLine("Yes"); } } }
using System; using System.Collections.Generic; using System.Linq; class Ho { static void Main() { var zennbu = Console.ReadLine().Split(); var N = int.Parse(zennbu[0]); var M = int.Parse(zennbu[1]); var syurui = new List<int>(); var a = Console.ReadLine().Split(); foreach (var n in a) { syurui.Add(int.Parse(n)); } int goukei = syurui.Sum(); int ikeru = 0; var ookii = syurui.OrderByDescending(x => x).ToList(); for (var i = 0; i < M; i++) { if (ookii[i] * 4 * M >= goukei) { } else { ikeru = 1; Console.WriteLine("No"); return; } } if (ikeru == 0) { Console.WriteLine("Yes"); } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["-", 0, 57, 15, 16, 12, 23, 0, 16, 17, 85], ["-", 0, 57, 15, 16, 12, 23, 0, 16, 12, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25]]
8
208
6
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; namespace AtCoderWorkspace { public class Solver { public void Solve() { var cin = new Scanner(); var n = cin.nextInt(); var m = cin.nextInt(); var a = cin.ArrayLong(n); var sum = a.Sum(); decimal d = a.Sum() * (decimal)(1 / (4.0 * m)); Array.Sort(a); Array.Reverse(a); var count = 0l; for (int i = 0; i < n; i++) { if (a[i] < d && count <= m) { Console.WriteLine("No"); return; } count++; } Console.WriteLine("Yes"); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public int[] DPArrayInt(int N, int ex) { int[] Array = new int[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextInt(); } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public long[] DPArrayLong(int N, int ex) { long[] Array = new long[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextLong(); } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Program { static void Main(string[] s) => new Solver().Solve(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; namespace AtCoderWorkspace { public class Solver { public void Solve() { var cin = new Scanner(); var n = cin.nextInt(); var m = cin.nextInt(); var a = cin.ArrayLong(n); var sum = a.Sum(); decimal d = a.Sum() * (decimal)(1 / (4.0 * m)); Array.Sort(a); Array.Reverse(a); var count = 0l; for (int i = 0; i < n; i++) { if (a[i] < d && count < m) { Console.WriteLine("No"); return; } count++; } Console.WriteLine("Yes"); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public int[] DPArrayInt(int N, int ex) { int[] Array = new int[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextInt(); } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public long[] DPArrayLong(int N, int ex) { long[] Array = new long[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextLong(); } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Program { static void Main(string[] s) => new Solver().Solve(); } }
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18]]
8
671
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Abc161B { public static void Main() { var nm = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int n = nm[0]; int m = nm[1]; var a = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var sum = a.Sum(); double threshold = sum / (4 * m); if (a.Count(i => i >= threshold) >= m) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Abc161B { public static void Main() { var nm = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int n = nm[0]; int m = nm[1]; var a = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var sum = a.Sum(); double threshold = sum / (double)(4 * m); if (a.Count(i => i >= threshold) >= m) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
[["+", 0, 200, 0, 212, 0, 16, 12, 74, 39, 199], ["+", 0, 200, 0, 212, 0, 16, 12, 74, 0, 25], ["+", 0, 212, 0, 16, 12, 74, 51, 23, 0, 24]]
8
177
3
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; using System.Numerics; namespace abc161 { class Program { static void Main(string[] args) { if (File.Exists("input.txt")) { Console.SetIn(new StreamReader("input.txt")); } solve_abc161B(); } public static void solve_abc161B() { int[] nm = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int n = nm[0]; int m = nm[1]; int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int sum = 0; for (int i = 0; i < n; i++) { sum += a[i]; } int cnt = 0; for (int i = 0; i < n; i++) { if (a[i] >= sum / (4 * m)) { cnt++; } } Console.WriteLine(cnt >= m ? "Yes" : "No"); } public static void solve_abc161A() { int[] xyz = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); Console.WriteLine("{0} {1} {2}", xyz[2], xyz[0], xyz[1]); } } }
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; using System.Numerics; namespace abc161 { class Program { static void Main(string[] args) { if (File.Exists("input.txt")) { Console.SetIn(new StreamReader("input.txt")); } solve_abc161B(); } public static void solve_abc161B() { int[] nm = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int n = nm[0]; int m = nm[1]; int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int sum = 0; for (int i = 0; i < n; i++) { sum += a[i]; } int cnt = 0; for (int i = 0; i < n; i++) { if (a[i] >= (double)sum / (4 * m)) { cnt++; } } Console.WriteLine(cnt >= m ? "Yes" : "No"); } public static void solve_abc161A() { int[] xyz = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); Console.WriteLine("{0} {1} {2}", xyz[2], xyz[0], xyz[1]); } } }
[["+", 0, 57, 15, 16, 12, 16, 31, 74, 0, 24], ["+", 0, 57, 15, 16, 12, 16, 31, 74, 39, 199], ["+", 0, 57, 15, 16, 12, 16, 31, 74, 0, 25]]
8
293
3
using System; using System.Linq; namespace _161abc { class Program { static void Main(string[] args) { int[] read = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int[] A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int sum = A.Sum(); int count = 0; for (int i = 0; i < read[0]; i++) { if (A[i] >= sum * 1 / (4 * read[1])) { count++; } } if (count >= read[1]) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Linq; namespace _161abc { class Program { static void Main(string[] args) { double[] read = Array.ConvertAll(Console.ReadLine().Split(), double.Parse); double[] A = Array.ConvertAll(Console.ReadLine().Split(), double.Parse); double sum = A.Sum(); double count = 0; for (int i = 0; i < read[0]; i++) { if (A[i] >= sum * 1 / (4 * read[1])) { count++; } } if (count >= read[1]) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
165
12
using System; using static System.Console; using System.Linq; namespace AC { public class shiokara { static void Main(string[] args) { int[] n = ReadLine().Split(' ').Select(int.Parse).ToArray(); int[] a = ReadLine().Split(' ').Select(int.Parse).ToArray(); float can = a.Sum() / (n[1] * 4); int[] anser = a.Where(o => o >= can).ToArray(); if (anser.Length >= n[1]) WriteLine("Yes"); else WriteLine("No"); } } }
using System; using static System.Console; using System.Linq; namespace AC { public class shiokara { static void Main(string[] args) { float[] n = ReadLine().Split(' ').Select(float.Parse).ToArray(); float[] a = ReadLine().Split(' ').Select(float.Parse).ToArray(); float can = a.Sum() / (n[1] * 4); float[] anser = a.Where(o => o >= can).ToArray(); if (anser.Length >= n[1]) WriteLine("Yes"); else WriteLine("No"); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199]]
8
152
10
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { var NM = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var an = Console.ReadLine() .Split(' ') .Select(s => int.Parse(s)) .OrderByDescending(i => i) .ToArray(); var sum = an.Sum(); Console.WriteLine((sum) < an[NM[1] - 1] * (4 * NM[1]) ? "Yes" : "No"); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { var NM = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var an = Console.ReadLine() .Split(' ') .Select(s => int.Parse(s)) .OrderByDescending(i => i) .ToArray(); var sum = an.Sum(); Console.WriteLine((sum) <= an[NM[1] - 1] * (4 * NM[1]) ? "Yes" : "No"); } } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 18], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 19]]
8
177
2
using System; using System.Collections.Generic; using System.Windows; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { public class Program { static void Main(string[] args) { var r1 = ReadSplit(); var n = r1[0].ToInt(); var m = r1[1].ToInt(); var r2 = ReadSplit(); var l = new List<int>(); for (int i = 0; i < n; i++) { var a = r2[i].ToInt(); l.Add(a); } var sum = l.Sum(); var count = 0; for (int i = 0; i < n; i++) { if (l[i] < sum / (4 * m)) { continue; } count++; } var ans = "Yes"; if (m > count) ans = "No"; WriteRead(ans); } public static string Read() { return Console.ReadLine(); } public static string[] ReadSplit() { return Console.ReadLine().Split(' '); } public static void WriteRead(object str) { Console.WriteLine(str); Read(); } public static void Write(object str) { Console.WriteLine(str); } } } public static class Extentions { public static int ToInt(this object obj) { return int.Parse(obj.ToString()); } public static decimal ToDecimal(this object obj) { return decimal.Parse(obj.ToString()); } public static double ToDouble(this object obj) { return double.Parse(obj.ToString()); } public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct { T2 value; if (d.TryGetValue(key, out value)) { return value; } return new T2(); } }
using System; using System.Collections.Generic; using System.Windows; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { public class Program { static void Main(string[] args) { var r1 = ReadSplit(); var n = r1[0].ToInt(); var m = r1[1].ToInt(); var r2 = ReadSplit(); var l = new List<int>(); for (int i = 0; i < n; i++) { var a = r2[i].ToInt(); l.Add(a); } var sum = l.Sum(); var count = 0; for (int i = 0; i < n; i++) { if (l[i] < (decimal)sum / (decimal)(4 * m)) { continue; } count++; } var ans = "Yes"; if (m > count) ans = "No"; WriteRead(ans); } public static string Read() { return Console.ReadLine(); } public static string[] ReadSplit() { return Console.ReadLine().Split(' '); } public static void WriteRead(object str) { Console.WriteLine(str); Read(); } public static void Write(object str) { Console.WriteLine(str); } } } public static class Extentions { public static int ToInt(this object obj) { return int.Parse(obj.ToString()); } public static decimal ToDecimal(this object obj) { return decimal.Parse(obj.ToString()); } public static double ToDouble(this object obj) { return double.Parse(obj.ToString()); } public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct { T2 value; if (d.TryGetValue(key, out value)) { return value; } return new T2(); } }
[["+", 0, 57, 15, 16, 12, 16, 31, 74, 0, 24], ["+", 0, 57, 15, 16, 12, 16, 31, 74, 39, 199], ["+", 0, 57, 15, 16, 12, 16, 31, 74, 0, 25], ["+", 0, 57, 15, 16, 12, 16, 12, 74, 0, 24], ["+", 0, 57, 15, 16, 12, 16, 12, 74, 39, 199], ["+", 0, 57, 15, 16, 12, 16, 12, 74, 0, 25]]
8
418
6
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace AtCoder.B { internal static class CR { public static string GetText() { return Console.ReadLine(); } public static List<string> GetTexts() { return Console.ReadLine().Split(' ').ToList(); } public static long GetLong() { return long.Parse(Console.ReadLine()); } public static List<long> GetLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); } } public class Program { public static long N { get; private set; } public static long M { get; private set; } public static List<long> A { get; private set; } public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var inputs = CR.GetLongs(); N = inputs[0]; M = inputs[1]; A = CR.GetLongs(); var border = A.Sum() / (4 * M); var vote = A.Count(x => x >= border); return vote < M ? "No" : "Yes"; } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace AtCoder.B { internal static class CR { public static string GetText() { return Console.ReadLine(); } public static List<string> GetTexts() { return Console.ReadLine().Split(' ').ToList(); } public static long GetLong() { return long.Parse(Console.ReadLine()); } public static List<long> GetLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); } } public class Program { public static long N { get; private set; } public static long M { get; private set; } public static List<long> A { get; private set; } public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var inputs = CR.GetLongs(); N = inputs[0]; M = inputs[1]; A = CR.GetLongs(); var border = (double)A.Sum() / (4 * M); var vote = A.Count(x => x >= border); return vote < M ? "No" : "Yes"; } } }
[["+", 0, 200, 0, 212, 0, 16, 31, 74, 0, 24], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 39, 199], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 0, 25]]
8
288
3
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace MyProject { class Program { static void Main(string[] args) { #if Local var sw = new Stopwatch(); sw.Start(); Console.SetIn(new StreamReader("input.in")); #endif var solver = new Solver(); solver.Solve(); #if Local Console.WriteLine($"{sw.ElapsedMilliseconds}ms"); #endif } } class Solver { public void Solve() { var items = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray(); var N = items[0]; var M = items[1]; var A = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray(); var total = A.Sum(); var ableCount = A.Count(elem => elem >= total / (4 * M)); var answer = M <= ableCount ? "Yes" : "No"; Console.WriteLine(answer); } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace MyProject { class Program { static void Main(string[] args) { #if Local var sw = new Stopwatch(); sw.Start(); Console.SetIn(new StreamReader("input.in")); #endif var solver = new Solver(); solver.Solve(); #if Local Console.WriteLine($"{sw.ElapsedMilliseconds}ms"); #endif } } class Solver { public void Solve() { var items = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray(); var N = items[0]; var M = items[1]; var A = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray(); var total = A.Sum(); var ableCount = A.Count(elem => elem * 4 * M >= total); var answer = M <= ableCount ? "Yes" : "No"; Console.WriteLine(answer); } } }
[["-", 3, 4, 0, 28, 0, 218, 8, 16, 17, 20], ["-", 0, 28, 0, 218, 8, 16, 12, 16, 31, 22], ["-", 0, 28, 0, 218, 8, 16, 12, 16, 17, 85], ["-", 0, 218, 8, 16, 12, 16, 12, 23, 0, 24], ["+", 0, 218, 8, 16, 31, 16, 31, 16, 17, 48], ["-", 0, 218, 8, 16, 12, 16, 12, 23, 0, 25], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 20], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 22]]
8
245
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class220 { static void Main() { var NM = Console.ReadLine().Split().Select(int.Parse).ToArray(); var A = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = NM[0], M = NM[1]; int S = A.Sum(); int count = 0; for (int i = 0; i < N; i++) { if (A[i] >= S / (4 * M)) { count++; } } Console.WriteLine(count >= M ? "Yes" : "No"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class220 { static void Main() { var NM = Console.ReadLine().Split().Select(int.Parse).ToArray(); var A = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = NM[0], M = NM[1]; int S = A.Sum(); int count = 0; for (int i = 0; i < N; i++) { if (A[i] >= (double)S / (4 * M)) { count++; } } Console.WriteLine(count >= M ? "Yes" : "No"); } } }
[["+", 0, 57, 15, 16, 12, 16, 31, 74, 0, 24], ["+", 0, 57, 15, 16, 12, 16, 31, 74, 39, 199], ["+", 0, 57, 15, 16, 12, 16, 31, 74, 0, 25]]
8
172
3
using System; using System.Collections.Generic; using System.Collections; using System.Linq; namespace Atcoder_0404 { class Program { static void Main(string[] args) { var NM = GetInput_int(); int _contentCount = NM[0]; int _goodCount = NM[1]; List<int> _points = new List<int>(GetInput_int()); float _limit = _points.Sum() / (float)(_goodCount * 4); _points.Sort(); if (_points[_contentCount - _goodCount] > _limit) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } #region input static string[] GetInput_string() { var input = Console.ReadLine().Split(' '); return input; } static int[] GetInput_int() { var input = GetInput_string(); var result = new int[input.Length]; for (int i = 0; i < result.Length; i++) { result[i] = int.Parse(input[i]); } return result; } static long[] GetInput_long() { var input = GetInput_string(); var result = new long[input.Length]; for (int i = 0; i < result.Length; i++) { result[i] = long.Parse(input[i]); } return result; } #endregion #region sonota static void Swap_array<T>(T[] target, int a, int b) { T temp = target[a]; target[a] = target[b]; target[b] = temp; } static void Swap_list<T>(List<T> target, int a, int b) { T temp = target[a]; target[a] = target[b]; target[b] = temp; } #endregion } }
using System; using System.Collections.Generic; using System.Collections; using System.Linq; namespace Atcoder_0404 { class Program { static void Main(string[] args) { var NM = GetInput_int(); int _contentCount = NM[0]; int _goodCount = NM[1]; List<int> _points = new List<int>(GetInput_int()); float _limit = _points.Sum() / (float)(_goodCount * 4); _points.Sort(); if (_points[_contentCount - _goodCount] >= _limit) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } #region input static string[] GetInput_string() { var input = Console.ReadLine().Split(' '); return input; } static int[] GetInput_int() { var input = GetInput_string(); var result = new int[input.Length]; for (int i = 0; i < result.Length; i++) { result[i] = int.Parse(input[i]); } return result; } static long[] GetInput_long() { var input = GetInput_string(); var result = new long[input.Length]; for (int i = 0; i < result.Length; i++) { result[i] = long.Parse(input[i]); } return result; } #endregion #region sonota static void Swap_array<T>(T[] target, int a, int b) { T temp = target[a]; target[a] = target[b]; target[b] = temp; } static void Swap_list<T>(List<T> target, int a, int b) { T temp = target[a]; target[a] = target[b]; target[b] = temp; } #endregion } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
8
392
2
using System; using System.Collections.Generic; using System.Linq; namespace AtCoderCs { class Program { static void Main() { var Arg = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var M = Arg[1]; var Ranking = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); Array.Sort(Ranking); Array.Reverse(Ranking); var SumVote = Ranking.Sum(); Console.WriteLine((Ranking[M - 1] < (SumVote / (4 * M)) ? "No" : "Yes")); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoderCs { class Program { static void Main() { var Arg = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var M = Arg[1]; var Ranking = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); Array.Sort(Ranking); Array.Reverse(Ranking); var SumVote = Ranking.Sum(); Console.WriteLine((Ranking[M - 1] * (4 * M) < SumVote ? "No" : "Yes")); } } }
[["-", 0, 28, 0, 23, 0, 41, 15, 16, 17, 18], ["-", 0, 23, 0, 41, 15, 16, 12, 23, 0, 24], ["-", 0, 41, 15, 16, 12, 23, 0, 16, 31, 22], ["-", 0, 41, 15, 16, 12, 23, 0, 16, 17, 85], ["+", 0, 23, 0, 41, 15, 16, 31, 16, 17, 48], ["-", 0, 23, 0, 41, 15, 16, 12, 23, 0, 25], ["+", 0, 28, 0, 23, 0, 41, 15, 16, 17, 18], ["+", 0, 28, 0, 23, 0, 41, 15, 16, 12, 22]]
8
157
8
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace competitive_programming { class Program { static void Main(string[] args) { var main = new Program(); main.solve(); } void solve() { int[] nm = Console.ReadLine().Split(' ').Select(val => int.Parse(val)).ToArray(); int n = nm[0]; int m = nm[1]; int[] As = Console.ReadLine().Split(' ').Select(val => int.Parse(val)).ToArray(); int sum = As.Sum(); int count = 0; for (int i = 0; i < As.Length; i++) { if (As[i] >= (double)(sum / (4 * m))) count++; } Console.WriteLine(count >= m ? "Yes" : "No"); } } struct Vector2 { public Vector2(long x, long y) { this.x = x; this.y = y; } public long x; public long y; } struct Vector3 { public int x; public int y; public int z; } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace competitive_programming { class Program { static void Main(string[] args) { var main = new Program(); main.solve(); } void solve() { int[] nm = Console.ReadLine().Split(' ').Select(val => int.Parse(val)).ToArray(); int n = nm[0]; int m = nm[1]; int[] As = Console.ReadLine().Split(' ').Select(val => int.Parse(val)).ToArray(); int sum = As.Sum(); int count = 0; for (int i = 0; i < As.Length; i++) { if (As[i] >= ((double)sum / (double)(4 * m))) count++; } Console.WriteLine(count >= m ? "Yes" : "No"); } } struct Vector2 { public Vector2(long x, long y) { this.x = x; this.y = y; } public long x; public long y; } struct Vector3 { public int x; public int y; public int z; } }
[["+", 15, 16, 12, 23, 0, 16, 31, 74, 0, 24], ["-", 0, 57, 15, 16, 12, 74, 51, 23, 0, 24], ["+", 15, 16, 12, 23, 0, 16, 12, 74, 0, 24], ["+", 15, 16, 12, 23, 0, 16, 12, 74, 39, 199], ["+", 15, 16, 12, 23, 0, 16, 12, 74, 0, 25]]
8
266
5
using System; using System.Linq; namespace ABC161 { class B { static void Main(string[] args) { var a = Console.ReadLine().Split().Select(double.Parse).ToArray(); var n = a[0]; var m = a[1]; var A = Console.ReadLine().Split().Select(double.Parse).ToArray(); double sum = A.Sum(); double count = 0; for (int i = 0; i < n; i++) { if (sum * (1 / (4 * m)) < A[i]) count++; } if (m <= count) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
using System; using System.Linq; namespace ABC161 { class B { static void Main(string[] args) { var a = Console.ReadLine().Split().Select(double.Parse).ToArray(); var n = a[0]; var m = a[1]; var A = Console.ReadLine().Split().Select(double.Parse).ToArray(); double sum = A.Sum(); double count = 0; for (int i = 0; i < n; i++) { if (sum * (1 / (4 * m)) <= A[i]) count++; } if (m <= count) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19]]
8
168
2
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Numerics; using System.Runtime.CompilerServices; using System.Security.Cryptography; using System.Text; using static System.Math; using static Solve.Methods; using static Solve.Input; using static Solve.Output; using pii = Solve.Pair<int, int>; using pll = Solve.Pair<long, long>; using pli = Solve.Pair<long, int>; using pil = Solve.Pair<int, long>; using pss = Solve.Pair<string, string>; using psi = Solve.Pair<string, int>; using lint = System.Collections.Generic.List<int>; using llong = System.Collections.Generic.List<long>; using lstr = System.Collections.Generic.List<string>; using llint = System.Collections.Generic.List<System.Collections.Generic.List<int>>; using llstr = System.Collections.Generic.List<System.Collections.Generic.List<long>>; using lllong = System.Collections.Generic.List<System.Collections.Generic.List<string>>; using lii = System.Collections.Generic.List<Solve.Pair<int, int>>; using lll = System.Collections.Generic.List<Solve.Pair<long, long>>; using lli = System.Collections.Generic.List<Solve.Pair<long, int>>; using lil = System.Collections.Generic.List<Solve.Pair<int, long>>; using ll = System.Int64; namespace Solve { public class Solver { public void Main() { int N = ReadInt; int M = ReadInt; int[] A = IntArray(N); var sum = A.Sum(); int cnt = 0; foreach (var a in A) { if (a >= sum / (4 * M)) cnt++; } PrintBool(cnt >= M); } // ReSharper disable UnusedMember.Local private const int MOD = (int) 1e9 + 7, INF = 1000000010; private const long LINF = 1000000000000000100; } // ライブラリ置き場ここから // ライブラリ置き場ここまで #region Templete #if !LOCAL namespace Library { } #endif public static class Methods { public static readonly int[] dx = {-1, 0, 0, 1}; public static readonly int[] dy = {0, 1, -1, 0}; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Assert(bool b, string message = null) { if (!b) throw new Exception(message ?? "Assert failed."); } /* public static Comparison<T> greater<T>() where T : IComparable<T> => (a, b) => b.CompareTo(a); */ public static string JoinSpace<T>(this IEnumerable<T> source) => source.Join(" "); public static string JoinEndline<T>(this IEnumerable<T> source) => source.Join("\n"); public static string Join<T>(this IEnumerable<T> source, string s) => string.Join(s, source); public static string Join<T>(this IEnumerable<T> source, char c) => string.Join(c.ToString(), source); /// <summary> /// <see cref="Pair{T1, T2}"/> クラスのインスタンスを作成します。 /// </summary> /// <typeparam name="T1">firstの型</typeparam> /// <typeparam name="T2">secondの型</typeparam> /// <param name="first">firstの値</param> /// <param name="second">secondの値</param> /// <returns>作成した<see cref="Pair{T1, T2}"/> クラスのインスタンス</returns> public static Pair<T1, T2> make_pair<T1, T2>(T1 first, T2 second) where T1 : IComparable<T1> where T2 : IComparable<T2> => new Pair<T1, T2>(first, second); /// <summary>aとbをスワップします。</summary> public static void Swap<T>(ref T a, ref T b) where T : struct { var tmp = b; b = a; a = tmp; } /// <summary>aとbの最大公約数を求めます。</summary> /// <returns>aとbの最大公約数</returns> public static long Gcd(long a, long b) { while (true) { if (a < b) Swap(ref a, ref b); if (a % b == 0) return b; var x = a; a = b; b = x % b; } } /// <summary>aとbの最小公倍数を求めます。</summary> /// <returns>aとbの最小公倍数</returns> public static long Lcm(long a, long b) => a / Gcd(a, b) * b; /// <summary> /// 指定した数値が素数であるかを判定します。 /// </summary> /// <remarks>計算量 (sqrt(value)) </remarks> /// <param name="value">判定する数値</param> /// <returns>value が素数であるか</returns> public static bool IsPrime(long value) { if (value <= 1) return false; for (long i = 2; i * i <= value; i++) if (value % i == 0) return false; return true; } /// <summary> /// <see cref="a"/> ^ <see cref="b"/> (mod <see cref="p"/>) を求める /// </summary> /// <returns><see cref="a"/> ^ <see cref="b"/> (mod <see cref="p"/>) の値</returns> public static long PowMod(long a, long b, long p) { long res = 1; while (b > 0) { if (b % 2 != 0) res = res * a % p; a = a * a % p; b >>= 1; } return res; } /// <summary> /// mod pにおけるaの逆元を求めます。 /// </summary> /// <param name="a"></param> /// <param name="p">法</param> /// <returns></returns> public static long ModInv(long a, long p) => PowMod(a, p - 2, p); public static int DivCeil(int left, int right) => left / right + (left % right == 0 ? 0 : 1); public static long DivCeil(long left, long right) => left / right + (left % right == 0L ? 0L : 1L); /// <summary> /// src の順列を求めます。 /// </summary> /// <typeparam name="T">型</typeparam> /// <param name="src">順列を求める配列</param> /// <returns>src の順列</returns> public static IEnumerable<T[]> Permutations<T>(IEnumerable<T> src) { var ret = new List<T[]>(); Search(ret, new Stack<T>(), src.ToArray()); return ret; } private static void Search<T>(ICollection<T[]> perms, Stack<T> stack, T[] a) { int N = a.Length; if (N == 0) perms.Add(stack.Reverse().ToArray()); else { var b = new T[N - 1]; Array.Copy(a, 1, b, 0, N - 1); for (int i = 0; i < a.Length; ++i) { stack.Push(a[i]); Search(perms, stack, b); if (i < b.Length) b[i] = a[i]; stack.Pop(); } } } /// <summary> /// 指定した条件を満たす最小の数値を返します。 /// </summary> /// <param name="low">検索する数値の最小値</param> /// <param name="high">検索する数値の最大値</param> /// <param name="expression">条件</param> /// <returns>条件を満たす最小の数値</returns> public static long BinarySearch(long low, long high, Func<long, bool> expression) { while (low < high) { long middle = (high - low) / 2 + low; if (!expression(middle)) high = middle; else low = middle + 1; } return high; } /// <summary> /// 指定した値以上の先頭のインデクスを返します。 /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値以上の先頭のインデクス</returns> public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } /// <summary> /// 指定した値以上の先頭のインデクスを返します。 /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="value">検索する値</param> /// <returns>指定した値以上の先頭のインデクス</returns> public static int LowerBound<T>(T[] arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default); } /// <summary> /// 指定した値より大きい先頭のインデクスを返します。 /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値より大きい先頭のインデクス</returns> public static int UpperBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } /// <summary> /// 指定した値より大きい先頭のインデクスを返します。 /// </summary>Z /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="value">検索する値</param> /// <returns>指定した値より大きい先頭のインデクス</returns> public static int UpperBound<T>(T[] arr, T value) { return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static IEnumerable<TResult> SelectNotNull<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> func) => source.Where(val => val != null).Select(func); public static IEnumerable<TSource> WhereNotNull<TSource>(this IEnumerable<TSource> source) => source.Where(val => val != null); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] ArrayOf<T>(params T[] arr) => arr; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<T> ListOf<T>(params T[] arr) => new List<T>(arr); public static IEnumerable<TResult> Repeat<TResult>(TResult value) { while (true) yield return value; // ReSharper disable once IteratorNeverReturns } public static IEnumerable<TResult> Repeat<TResult>(TResult value, int count) => Enumerable.Repeat(value, count); [SuppressMessage("ReSharper", "PossibleMultipleEnumeration")] public static IEnumerable<TResult> Repeat<TResult>(this IEnumerable<TResult> source, int count) { if (source == null) throw new ArgumentNullException(nameof(source)); if (count < 0) throw new ArgumentOutOfRangeException(nameof(count)); for (int i = 0; i < count; i++) foreach (var v in source) yield return v; } [SuppressMessage("ReSharper", "PossibleMultipleEnumeration")] public static IEnumerable<TResult> Repeat<TResult>(this IEnumerable<TResult> source) { if (source == null) throw new ArgumentNullException(nameof(source)); while (true) foreach (var v in source) yield return v; } /// <summary> /// 文字の配列を文字列に変換します。 /// </summary> /// <param name="source">文字の配列</param> /// <returns>変換した文字列</returns> public static string AsString(this IEnumerable<char> source) => new string(source.ToArray()); /// <summary> /// <see cref="source"/> の累積和を返します。 /// </summary> /// <returns><see cref="source"/> の累積和</returns> public static IEnumerable<long> CumSum(this IEnumerable<long> source) { long sum = 0; foreach (var item in source) yield return sum += item; } /// <summary> /// <see cref="source"/> の累積和を返します。 /// </summary> /// <returns><see cref="source"/> の累積和</returns> public static IEnumerable<int> CumSum(this IEnumerable<int> source) { int sum = 0; foreach (var item in source) yield return sum += item; } /// <summary> /// <see cref="value"/>が l以上 r未満の範囲に含まれているかを返します。 /// </summary> /// <typeparam name="T">要素の型</typeparam> /// <param name="value">判定する値</param> /// <param name="l">下限の値 (含まれる)</param> /// <param name="r">上限の値 (含まれない)</param> /// <returns><see cref="value"/> が指定した範囲に含まれているか</returns> public static bool IsIn<T>(this T value, T l, T r) where T : IComparable<T> { if (l.CompareTo(r) > 0) throw new ArgumentException(); return l.CompareTo(value) <= 0 && value.CompareTo(r) < 0; } /// <summary> /// <see cref="start"/> 以上 <see cref="end"/> 未満の値を <see cref="step"/> ずつ増やした結果を列挙します。 /// </summary> /// <param name="start">値の下限 (含まれる)</param> /// <param name="end">値の上限 (含まれない)</param> /// <param name="step">1要素ごとに増やす値</param> /// <returns>範囲の結果</returns> public static IEnumerable<int> Range(int start, int end, int step = 1) { for (var i = start; i < end; i += step) yield return i; } /// <summary> /// 0 以上 <see cref="end"/> 未満の値を 1 ずつ増やした結果を列挙します。 /// </summary> /// <param name="end">値の上限 (含まれない)</param> /// <returns>範囲の結果</returns> public static IEnumerable<int> Range(int end) => Range(0, end); /// <summary> /// <see cref="start"/> 以上 <see cref="end"/> 未満の値を <see cref="step"/> ずつ増やした結果を逆順に列挙します。 /// </summary> /// <param name="start">値の下限 (含まれる)</param> /// <param name="end">値の上限 (含まれない)</param> /// <param name="step">1要素ごとに増やす値</param> /// <returns>範囲の結果</returns> public static IEnumerable<int> RangeReverse(int start, int end, int step = 1) { for (var i = end - 1; i >= start; i -= step) yield return i; } /// <summary> /// 0 以上 <see cref="end"/> 未満の値を 1 ずつ増やした結果を逆順に列挙します。 /// </summary> /// <param name="end">値の上限 (含まれない)</param> /// <returns>範囲の結果</returns> public static IEnumerable<int> RangeReverse(int end) => RangeReverse(0, end); /// <summary> /// 指定した配列をコピーして昇順ソートします。(非破壊的) /// </summary> /// <typeparam name="T">ソートする配列の型</typeparam> /// <param name="arr">ソートする配列</param> /// <returns>ソートされた配列</returns> public static T[] Sort<T>(this T[] arr) { var array = new T[arr.Length]; arr.CopyTo(array, 0); Array.Sort(array); return array; } /// <summary> /// 指定した配列をコピーして降順ソートします。(非破壊的) /// </summary> /// <typeparam name="T">ソートする配列の型</typeparam> /// <param name="arr">ソートする配列</param> /// <returns>ソートされた配列</returns> public static T[] SortDescending<T>(this T[] arr) { var array = new T[arr.Length]; arr.CopyTo(array, 0); Array.Sort(array); Array.Reverse(array); return array; } public static double Log2(double x) => Log(x, 2); public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } public static T Min<T>(params T[] col) => col.Min(); public static T Max<T>(params T[] col) => col.Max(); /// <summary> /// 要素数 (a, b) の、defaultValue で満たされたジャグ配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[][] JaggedArray2D<T>(int a, int b, T defaultValue = default(T)) { var ret = new T[a][]; for (int i = 0; i < a; i++) { ret[i] = Enumerable.Repeat(defaultValue, b).ToArray(); } return ret; } /// <summary> /// 要素数 (a, b) の,defaultValue で満たされた二次元配列を作成します。 /// </summary> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <typeparam name="T">配列の型</typeparam> public static T[,] Array2D<T>(int a, int b, T defaultValue = default(T)) { var ret = new T[a, b]; for (int i = 0; i < a; i++) for (int j = 0; j < b; j++) ret[i, j] = defaultValue; return ret; } /// <summary> /// ジャグ配列を2次元配列に変換します。配列の各要素の長さがすべて同じである必要があります。 /// </summary> /// <param name="array">ジャグ配列</param> /// <typeparam name="T">二次元配列</typeparam> public static T[,] To2DArray<T>(this T[][] array) { if (!array.Any()) return new T[0, 0]; int len = array[0].Length; if (array.Any(x => x.Length != len)) throw new ArgumentException("array の各要素の長さが異なります。", nameof(array)); var ret = new T[array.Length, len]; for (int i = 0; i < array.Length; i++) { for (int j = 0; j < len; j++) { ret[i, j] = array[i][j]; } } return ret; } // public static vector<T> ToVector<T>(this IEnumerable<T> source) => new vector<T>(source); } public static class Input { private const char _separator = ' '; private static readonly Queue<string> _input = new Queue<string>(); private static readonly StreamReader sr = #if FILE new StreamReader("in.txt"); #else new StreamReader(Console.OpenStandardInput()); #endif public static string ReadLine => sr.ReadLine(); public static string ReadStr => Read; public static string Read { get { if (_input.Count != 0) return _input.Dequeue(); // ReSharper disable once PossibleNullReferenceException var tmp = sr.ReadLine().Split(_separator); foreach (var val in tmp) { _input.Enqueue(val); } return _input.Dequeue(); } } public static int ReadInt => int.Parse(Read); public static long ReadLong => long.Parse(Read); public static double ReadDouble => double.Parse(Read); public static string[] StrArray() => ReadLine.Split(' '); public static int[] IntArray() => ReadLine.Split(' ').Select(int.Parse).ToArray(); public static long[] LongArray() => ReadLine.Split(' ').Select(long.Parse).ToArray(); public static string[] StrArray(int n) { var ret = new string[n]; for (long i = 0; i < n; ++i) ret[i] = Read; return ret; } public static int[] IntArray(int n, int offset = 0, bool sorted = false) { var ret = StrArray(n).Select(x => int.Parse(x) + offset).ToArray(); if (sorted) Array.Sort(ret); return ret; } public static long[] LongArray(int n, long offset = 0, bool sorted = false) { var ret = StrArray(n).Select(x => long.Parse(x) + offset).ToArray(); if (sorted) Array.Sort(ret); return ret; } public static string[,] Str2DArray(int n, int m) { var ret = new string[n, m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) ret[i, j] = ReadStr; return ret; } public static int[,] Int2DArray(int n, int m, int offset = 0) { var ret = new int[n, m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) ret[i, j] = ReadInt + offset; return ret; } public static long[,] Long2DArray(int n, int m, long offset = 0) { var ret = new long[n, m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) ret[i, j] = ReadLong + offset; return ret; } public static Tuple<string[], string[]> StrArrays2(int n) { var ret1 = new string[n]; var ret2 = new string[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadStr; ret2[i] = ReadStr; } return Tuple.Create(ret1, ret2); } public static Tuple<int[], int[]> IntArrays2(int n, int offset1 = 0, int offset2 = 0) { var ret1 = new int[n]; var ret2 = new int[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadInt + offset1; ret2[i] = ReadInt + offset2; } return Tuple.Create(ret1, ret2); } public static Tuple<long[], long[]> LongArrays2(int n, long offset1 = 0, long offset2 = 0) { var ret1 = new long[n]; var ret2 = new long[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadLong + offset1; ret2[i] = ReadLong + offset2; } return Tuple.Create(ret1, ret2); } public static Tuple<string[], string[], string[]> StrArrays3(int n) { var ret1 = new string[n]; var ret2 = new string[n]; var ret3 = new string[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadStr; ret2[i] = ReadStr; } return Tuple.Create(ret1, ret2, ret3); } public static Tuple<int[], int[], int[]> IntArrays3(int n, int offset1 = 0, int offset2 = 0, int offset3 = 0) { var ret1 = new int[n]; var ret2 = new int[n]; var ret3 = new int[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadInt + offset1; ret2[i] = ReadInt + offset2; ret3[i] = ReadInt + offset3; } return Tuple.Create(ret1, ret2, ret3); } public static Tuple<long[], long[], long[]> LongArrays3(int n, long offset1 = 0, long offset2 = 0, long offset3 = 0) { var ret1 = new long[n]; var ret2 = new long[n]; var ret3 = new long[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadLong + offset1; ret2[i] = ReadLong + offset2; ret3[i] = ReadLong + offset3; } return Tuple.Create(ret1, ret2, ret3); } private static bool TypeEquals<T, U>() => typeof(T) == typeof(U); private static T ChangeType<T, U>(U a) => (T) System.Convert.ChangeType(a, typeof(T)); private static T Convert<T>(string s) => TypeEquals<T, int>() ? ChangeType<T, int>(int.Parse(s)) : TypeEquals<T, long>() ? ChangeType<T, long>(long.Parse(s)) : TypeEquals<T, double>() ? ChangeType<T, double>(double.Parse(s)) : TypeEquals<T, char>() ? ChangeType<T, char>(s[0]) : ChangeType<T, string>(s); public static bool In<T>(out T a) { try { a = Convert<T>(Read); return true; } catch { a = default(T); return false; } } public static bool In<T, U>(out T a, out U b) { try { var ar = StrArray(2); a = Convert<T>(ar[0]); b = Convert<U>(ar[1]); return true; } catch { a = default(T); b = default(U); return false; } } public static bool In<T, U, V>(out T a, out U b, out V c) { try { var ar = StrArray(3); a = Convert<T>(ar[0]); b = Convert<U>(ar[1]); c = Convert<V>(ar[2]); return true; } catch { a = default(T); b = default(U); c = default(V); return false; } } public static bool In<T, U, V, W>(out T a, out U b, out V c, out W d) { try { var ar = StrArray(4); a = Convert<T>(ar[0]); b = Convert<U>(ar[1]); c = Convert<V>(ar[2]); d = Convert<W>(ar[3]); return true; } catch { a = default(T); b = default(U); c = default(V); d = default(W); return false; } } public static bool In<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { try { var ar = StrArray(5); a = Convert<T>(ar[0]); b = Convert<U>(ar[1]); c = Convert<V>(ar[2]); d = Convert<W>(ar[3]); e = Convert<X>(ar[4]); return true; } catch { a = default(T); b = default(U); c = default(V); d = default(W); e = default(X); return false; } } } public static class Output { public static void print<T>(T t) => Console.WriteLine(t); public static void print(params object[] o) => Console.WriteLine(o.Join(" ")); public static void PrintBool(bool val, string yes = "Yes", string no = "No") => Console.WriteLine(val ? yes : no); public static void PrintYn(bool val) => PrintBool(val); public static void PrintYN(bool val) => PrintBool(val, "YES", "NO"); public static void PrintPossible(bool val) => PrintBool(val, "Possible", "Impossible"); public static void PrintYay(bool val) => PrintBool(val, "Yay!", ":("); public static void PrintDebug(params object[] args) => Console.Error.WriteLine(string.Join(" ", args)); /// <summary> /// setter で設定された値を標準出力に出力します。 /// </summary> public static object cout { set { Console.WriteLine(value); } } /// <summary> /// Local環境のみ,setter で設定された値を標準出力に出力します。 /// </summary> public static object dout { set { #if LOCAL Console.WriteLine(value); #endif } } /// <summary> /// setter で設定された値を標準エラー出力に出力します。 /// </summary> public static object cerr { set { Console.Error.WriteLine(value); } } public const string endl = "\n"; } public class Program { public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false}; Console.SetOut(sw); new Solver().Main(); Console.Out.Flush(); } } [DebuggerDisplay("({first}, {second})")] public class Pair<T1, T2> : IComparable<Pair<T1, T2>>, IEquatable<Pair<T1, T2>> where T1 : IComparable<T1> where T2 : IComparable<T2> { public Pair(T1 first, T2 second) { this.first = first; this.second = second; } public T1 first; public T2 second; public int CompareTo(Pair<T1, T2> other) { if (ReferenceEquals(this, other)) return 0; if (ReferenceEquals(null, other)) return 1; var firstComparison = first.CompareTo(other.first); return firstComparison != 0 ? firstComparison : second.CompareTo(other.second); } public override string ToString() => $"({first}, {second})"; public bool Equals(Pair<T1, T2> other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return EqualityComparer<T1>.Default.Equals(first, other.first) && EqualityComparer<T2>.Default.Equals(second, other.second); } public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; return obj.GetType() == GetType() && Equals((Pair<T1, T2>) obj); } public override int GetHashCode() { unchecked { return (EqualityComparer<T1>.Default.GetHashCode(first) * 397) ^ EqualityComparer<T2>.Default.GetHashCode(second); } } } #endregion }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Numerics; using System.Runtime.CompilerServices; using System.Security.Cryptography; using System.Text; using static System.Math; using static Solve.Methods; using static Solve.Input; using static Solve.Output; using pii = Solve.Pair<int, int>; using pll = Solve.Pair<long, long>; using pli = Solve.Pair<long, int>; using pil = Solve.Pair<int, long>; using pss = Solve.Pair<string, string>; using psi = Solve.Pair<string, int>; using lint = System.Collections.Generic.List<int>; using llong = System.Collections.Generic.List<long>; using lstr = System.Collections.Generic.List<string>; using llint = System.Collections.Generic.List<System.Collections.Generic.List<int>>; using llstr = System.Collections.Generic.List<System.Collections.Generic.List<long>>; using lllong = System.Collections.Generic.List<System.Collections.Generic.List<string>>; using lii = System.Collections.Generic.List<Solve.Pair<int, int>>; using lll = System.Collections.Generic.List<Solve.Pair<long, long>>; using lli = System.Collections.Generic.List<Solve.Pair<long, int>>; using lil = System.Collections.Generic.List<Solve.Pair<int, long>>; using ll = System.Int64; namespace Solve { public class Solver { public void Main() { int N = ReadInt; int M = ReadInt; int[] A = IntArray(N); var sum = A.Sum(); int cnt = 0; foreach (var a in A) { if (a >= sum / (4d * M)) cnt++; } PrintBool(cnt >= M); } // ReSharper disable UnusedMember.Local private const int MOD = (int) 1e9 + 7, INF = 1000000010; private const long LINF = 1000000000000000100; } // ライブラリ置き場ここから // ライブラリ置き場ここまで #region Templete #if !LOCAL namespace Library { } #endif public static class Methods { public static readonly int[] dx = {-1, 0, 0, 1}; public static readonly int[] dy = {0, 1, -1, 0}; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Assert(bool b, string message = null) { if (!b) throw new Exception(message ?? "Assert failed."); } /* public static Comparison<T> greater<T>() where T : IComparable<T> => (a, b) => b.CompareTo(a); */ public static string JoinSpace<T>(this IEnumerable<T> source) => source.Join(" "); public static string JoinEndline<T>(this IEnumerable<T> source) => source.Join("\n"); public static string Join<T>(this IEnumerable<T> source, string s) => string.Join(s, source); public static string Join<T>(this IEnumerable<T> source, char c) => string.Join(c.ToString(), source); /// <summary> /// <see cref="Pair{T1, T2}"/> クラスのインスタンスを作成します。 /// </summary> /// <typeparam name="T1">firstの型</typeparam> /// <typeparam name="T2">secondの型</typeparam> /// <param name="first">firstの値</param> /// <param name="second">secondの値</param> /// <returns>作成した<see cref="Pair{T1, T2}"/> クラスのインスタンス</returns> public static Pair<T1, T2> make_pair<T1, T2>(T1 first, T2 second) where T1 : IComparable<T1> where T2 : IComparable<T2> => new Pair<T1, T2>(first, second); /// <summary>aとbをスワップします。</summary> public static void Swap<T>(ref T a, ref T b) where T : struct { var tmp = b; b = a; a = tmp; } /// <summary>aとbの最大公約数を求めます。</summary> /// <returns>aとbの最大公約数</returns> public static long Gcd(long a, long b) { while (true) { if (a < b) Swap(ref a, ref b); if (a % b == 0) return b; var x = a; a = b; b = x % b; } } /// <summary>aとbの最小公倍数を求めます。</summary> /// <returns>aとbの最小公倍数</returns> public static long Lcm(long a, long b) => a / Gcd(a, b) * b; /// <summary> /// 指定した数値が素数であるかを判定します。 /// </summary> /// <remarks>計算量 (sqrt(value)) </remarks> /// <param name="value">判定する数値</param> /// <returns>value が素数であるか</returns> public static bool IsPrime(long value) { if (value <= 1) return false; for (long i = 2; i * i <= value; i++) if (value % i == 0) return false; return true; } /// <summary> /// <see cref="a"/> ^ <see cref="b"/> (mod <see cref="p"/>) を求める /// </summary> /// <returns><see cref="a"/> ^ <see cref="b"/> (mod <see cref="p"/>) の値</returns> public static long PowMod(long a, long b, long p) { long res = 1; while (b > 0) { if (b % 2 != 0) res = res * a % p; a = a * a % p; b >>= 1; } return res; } /// <summary> /// mod pにおけるaの逆元を求めます。 /// </summary> /// <param name="a"></param> /// <param name="p">法</param> /// <returns></returns> public static long ModInv(long a, long p) => PowMod(a, p - 2, p); public static int DivCeil(int left, int right) => left / right + (left % right == 0 ? 0 : 1); public static long DivCeil(long left, long right) => left / right + (left % right == 0L ? 0L : 1L); /// <summary> /// src の順列を求めます。 /// </summary> /// <typeparam name="T">型</typeparam> /// <param name="src">順列を求める配列</param> /// <returns>src の順列</returns> public static IEnumerable<T[]> Permutations<T>(IEnumerable<T> src) { var ret = new List<T[]>(); Search(ret, new Stack<T>(), src.ToArray()); return ret; } private static void Search<T>(ICollection<T[]> perms, Stack<T> stack, T[] a) { int N = a.Length; if (N == 0) perms.Add(stack.Reverse().ToArray()); else { var b = new T[N - 1]; Array.Copy(a, 1, b, 0, N - 1); for (int i = 0; i < a.Length; ++i) { stack.Push(a[i]); Search(perms, stack, b); if (i < b.Length) b[i] = a[i]; stack.Pop(); } } } /// <summary> /// 指定した条件を満たす最小の数値を返します。 /// </summary> /// <param name="low">検索する数値の最小値</param> /// <param name="high">検索する数値の最大値</param> /// <param name="expression">条件</param> /// <returns>条件を満たす最小の数値</returns> public static long BinarySearch(long low, long high, Func<long, bool> expression) { while (low < high) { long middle = (high - low) / 2 + low; if (!expression(middle)) high = middle; else low = middle + 1; } return high; } /// <summary> /// 指定した値以上の先頭のインデクスを返します。 /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値以上の先頭のインデクス</returns> public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } /// <summary> /// 指定した値以上の先頭のインデクスを返します。 /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="value">検索する値</param> /// <returns>指定した値以上の先頭のインデクス</returns> public static int LowerBound<T>(T[] arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default); } /// <summary> /// 指定した値より大きい先頭のインデクスを返します。 /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値より大きい先頭のインデクス</returns> public static int UpperBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } /// <summary> /// 指定した値より大きい先頭のインデクスを返します。 /// </summary>Z /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="value">検索する値</param> /// <returns>指定した値より大きい先頭のインデクス</returns> public static int UpperBound<T>(T[] arr, T value) { return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static IEnumerable<TResult> SelectNotNull<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> func) => source.Where(val => val != null).Select(func); public static IEnumerable<TSource> WhereNotNull<TSource>(this IEnumerable<TSource> source) => source.Where(val => val != null); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] ArrayOf<T>(params T[] arr) => arr; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static List<T> ListOf<T>(params T[] arr) => new List<T>(arr); public static IEnumerable<TResult> Repeat<TResult>(TResult value) { while (true) yield return value; // ReSharper disable once IteratorNeverReturns } public static IEnumerable<TResult> Repeat<TResult>(TResult value, int count) => Enumerable.Repeat(value, count); [SuppressMessage("ReSharper", "PossibleMultipleEnumeration")] public static IEnumerable<TResult> Repeat<TResult>(this IEnumerable<TResult> source, int count) { if (source == null) throw new ArgumentNullException(nameof(source)); if (count < 0) throw new ArgumentOutOfRangeException(nameof(count)); for (int i = 0; i < count; i++) foreach (var v in source) yield return v; } [SuppressMessage("ReSharper", "PossibleMultipleEnumeration")] public static IEnumerable<TResult> Repeat<TResult>(this IEnumerable<TResult> source) { if (source == null) throw new ArgumentNullException(nameof(source)); while (true) foreach (var v in source) yield return v; } /// <summary> /// 文字の配列を文字列に変換します。 /// </summary> /// <param name="source">文字の配列</param> /// <returns>変換した文字列</returns> public static string AsString(this IEnumerable<char> source) => new string(source.ToArray()); /// <summary> /// <see cref="source"/> の累積和を返します。 /// </summary> /// <returns><see cref="source"/> の累積和</returns> public static IEnumerable<long> CumSum(this IEnumerable<long> source) { long sum = 0; foreach (var item in source) yield return sum += item; } /// <summary> /// <see cref="source"/> の累積和を返します。 /// </summary> /// <returns><see cref="source"/> の累積和</returns> public static IEnumerable<int> CumSum(this IEnumerable<int> source) { int sum = 0; foreach (var item in source) yield return sum += item; } /// <summary> /// <see cref="value"/>が l以上 r未満の範囲に含まれているかを返します。 /// </summary> /// <typeparam name="T">要素の型</typeparam> /// <param name="value">判定する値</param> /// <param name="l">下限の値 (含まれる)</param> /// <param name="r">上限の値 (含まれない)</param> /// <returns><see cref="value"/> が指定した範囲に含まれているか</returns> public static bool IsIn<T>(this T value, T l, T r) where T : IComparable<T> { if (l.CompareTo(r) > 0) throw new ArgumentException(); return l.CompareTo(value) <= 0 && value.CompareTo(r) < 0; } /// <summary> /// <see cref="start"/> 以上 <see cref="end"/> 未満の値を <see cref="step"/> ずつ増やした結果を列挙します。 /// </summary> /// <param name="start">値の下限 (含まれる)</param> /// <param name="end">値の上限 (含まれない)</param> /// <param name="step">1要素ごとに増やす値</param> /// <returns>範囲の結果</returns> public static IEnumerable<int> Range(int start, int end, int step = 1) { for (var i = start; i < end; i += step) yield return i; } /// <summary> /// 0 以上 <see cref="end"/> 未満の値を 1 ずつ増やした結果を列挙します。 /// </summary> /// <param name="end">値の上限 (含まれない)</param> /// <returns>範囲の結果</returns> public static IEnumerable<int> Range(int end) => Range(0, end); /// <summary> /// <see cref="start"/> 以上 <see cref="end"/> 未満の値を <see cref="step"/> ずつ増やした結果を逆順に列挙します。 /// </summary> /// <param name="start">値の下限 (含まれる)</param> /// <param name="end">値の上限 (含まれない)</param> /// <param name="step">1要素ごとに増やす値</param> /// <returns>範囲の結果</returns> public static IEnumerable<int> RangeReverse(int start, int end, int step = 1) { for (var i = end - 1; i >= start; i -= step) yield return i; } /// <summary> /// 0 以上 <see cref="end"/> 未満の値を 1 ずつ増やした結果を逆順に列挙します。 /// </summary> /// <param name="end">値の上限 (含まれない)</param> /// <returns>範囲の結果</returns> public static IEnumerable<int> RangeReverse(int end) => RangeReverse(0, end); /// <summary> /// 指定した配列をコピーして昇順ソートします。(非破壊的) /// </summary> /// <typeparam name="T">ソートする配列の型</typeparam> /// <param name="arr">ソートする配列</param> /// <returns>ソートされた配列</returns> public static T[] Sort<T>(this T[] arr) { var array = new T[arr.Length]; arr.CopyTo(array, 0); Array.Sort(array); return array; } /// <summary> /// 指定した配列をコピーして降順ソートします。(非破壊的) /// </summary> /// <typeparam name="T">ソートする配列の型</typeparam> /// <param name="arr">ソートする配列</param> /// <returns>ソートされた配列</returns> public static T[] SortDescending<T>(this T[] arr) { var array = new T[arr.Length]; arr.CopyTo(array, 0); Array.Sort(array); Array.Reverse(array); return array; } public static double Log2(double x) => Log(x, 2); public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } public static T Min<T>(params T[] col) => col.Min(); public static T Max<T>(params T[] col) => col.Max(); /// <summary> /// 要素数 (a, b) の、defaultValue で満たされたジャグ配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[][] JaggedArray2D<T>(int a, int b, T defaultValue = default(T)) { var ret = new T[a][]; for (int i = 0; i < a; i++) { ret[i] = Enumerable.Repeat(defaultValue, b).ToArray(); } return ret; } /// <summary> /// 要素数 (a, b) の,defaultValue で満たされた二次元配列を作成します。 /// </summary> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <typeparam name="T">配列の型</typeparam> public static T[,] Array2D<T>(int a, int b, T defaultValue = default(T)) { var ret = new T[a, b]; for (int i = 0; i < a; i++) for (int j = 0; j < b; j++) ret[i, j] = defaultValue; return ret; } /// <summary> /// ジャグ配列を2次元配列に変換します。配列の各要素の長さがすべて同じである必要があります。 /// </summary> /// <param name="array">ジャグ配列</param> /// <typeparam name="T">二次元配列</typeparam> public static T[,] To2DArray<T>(this T[][] array) { if (!array.Any()) return new T[0, 0]; int len = array[0].Length; if (array.Any(x => x.Length != len)) throw new ArgumentException("array の各要素の長さが異なります。", nameof(array)); var ret = new T[array.Length, len]; for (int i = 0; i < array.Length; i++) { for (int j = 0; j < len; j++) { ret[i, j] = array[i][j]; } } return ret; } // public static vector<T> ToVector<T>(this IEnumerable<T> source) => new vector<T>(source); } public static class Input { private const char _separator = ' '; private static readonly Queue<string> _input = new Queue<string>(); private static readonly StreamReader sr = #if FILE new StreamReader("in.txt"); #else new StreamReader(Console.OpenStandardInput()); #endif public static string ReadLine => sr.ReadLine(); public static string ReadStr => Read; public static string Read { get { if (_input.Count != 0) return _input.Dequeue(); // ReSharper disable once PossibleNullReferenceException var tmp = sr.ReadLine().Split(_separator); foreach (var val in tmp) { _input.Enqueue(val); } return _input.Dequeue(); } } public static int ReadInt => int.Parse(Read); public static long ReadLong => long.Parse(Read); public static double ReadDouble => double.Parse(Read); public static string[] StrArray() => ReadLine.Split(' '); public static int[] IntArray() => ReadLine.Split(' ').Select(int.Parse).ToArray(); public static long[] LongArray() => ReadLine.Split(' ').Select(long.Parse).ToArray(); public static string[] StrArray(int n) { var ret = new string[n]; for (long i = 0; i < n; ++i) ret[i] = Read; return ret; } public static int[] IntArray(int n, int offset = 0, bool sorted = false) { var ret = StrArray(n).Select(x => int.Parse(x) + offset).ToArray(); if (sorted) Array.Sort(ret); return ret; } public static long[] LongArray(int n, long offset = 0, bool sorted = false) { var ret = StrArray(n).Select(x => long.Parse(x) + offset).ToArray(); if (sorted) Array.Sort(ret); return ret; } public static string[,] Str2DArray(int n, int m) { var ret = new string[n, m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) ret[i, j] = ReadStr; return ret; } public static int[,] Int2DArray(int n, int m, int offset = 0) { var ret = new int[n, m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) ret[i, j] = ReadInt + offset; return ret; } public static long[,] Long2DArray(int n, int m, long offset = 0) { var ret = new long[n, m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) ret[i, j] = ReadLong + offset; return ret; } public static Tuple<string[], string[]> StrArrays2(int n) { var ret1 = new string[n]; var ret2 = new string[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadStr; ret2[i] = ReadStr; } return Tuple.Create(ret1, ret2); } public static Tuple<int[], int[]> IntArrays2(int n, int offset1 = 0, int offset2 = 0) { var ret1 = new int[n]; var ret2 = new int[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadInt + offset1; ret2[i] = ReadInt + offset2; } return Tuple.Create(ret1, ret2); } public static Tuple<long[], long[]> LongArrays2(int n, long offset1 = 0, long offset2 = 0) { var ret1 = new long[n]; var ret2 = new long[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadLong + offset1; ret2[i] = ReadLong + offset2; } return Tuple.Create(ret1, ret2); } public static Tuple<string[], string[], string[]> StrArrays3(int n) { var ret1 = new string[n]; var ret2 = new string[n]; var ret3 = new string[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadStr; ret2[i] = ReadStr; } return Tuple.Create(ret1, ret2, ret3); } public static Tuple<int[], int[], int[]> IntArrays3(int n, int offset1 = 0, int offset2 = 0, int offset3 = 0) { var ret1 = new int[n]; var ret2 = new int[n]; var ret3 = new int[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadInt + offset1; ret2[i] = ReadInt + offset2; ret3[i] = ReadInt + offset3; } return Tuple.Create(ret1, ret2, ret3); } public static Tuple<long[], long[], long[]> LongArrays3(int n, long offset1 = 0, long offset2 = 0, long offset3 = 0) { var ret1 = new long[n]; var ret2 = new long[n]; var ret3 = new long[n]; for (int i = 0; i < n; i++) { ret1[i] = ReadLong + offset1; ret2[i] = ReadLong + offset2; ret3[i] = ReadLong + offset3; } return Tuple.Create(ret1, ret2, ret3); } private static bool TypeEquals<T, U>() => typeof(T) == typeof(U); private static T ChangeType<T, U>(U a) => (T) System.Convert.ChangeType(a, typeof(T)); private static T Convert<T>(string s) => TypeEquals<T, int>() ? ChangeType<T, int>(int.Parse(s)) : TypeEquals<T, long>() ? ChangeType<T, long>(long.Parse(s)) : TypeEquals<T, double>() ? ChangeType<T, double>(double.Parse(s)) : TypeEquals<T, char>() ? ChangeType<T, char>(s[0]) : ChangeType<T, string>(s); public static bool In<T>(out T a) { try { a = Convert<T>(Read); return true; } catch { a = default(T); return false; } } public static bool In<T, U>(out T a, out U b) { try { var ar = StrArray(2); a = Convert<T>(ar[0]); b = Convert<U>(ar[1]); return true; } catch { a = default(T); b = default(U); return false; } } public static bool In<T, U, V>(out T a, out U b, out V c) { try { var ar = StrArray(3); a = Convert<T>(ar[0]); b = Convert<U>(ar[1]); c = Convert<V>(ar[2]); return true; } catch { a = default(T); b = default(U); c = default(V); return false; } } public static bool In<T, U, V, W>(out T a, out U b, out V c, out W d) { try { var ar = StrArray(4); a = Convert<T>(ar[0]); b = Convert<U>(ar[1]); c = Convert<V>(ar[2]); d = Convert<W>(ar[3]); return true; } catch { a = default(T); b = default(U); c = default(V); d = default(W); return false; } } public static bool In<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { try { var ar = StrArray(5); a = Convert<T>(ar[0]); b = Convert<U>(ar[1]); c = Convert<V>(ar[2]); d = Convert<W>(ar[3]); e = Convert<X>(ar[4]); return true; } catch { a = default(T); b = default(U); c = default(V); d = default(W); e = default(X); return false; } } } public static class Output { public static void print<T>(T t) => Console.WriteLine(t); public static void print(params object[] o) => Console.WriteLine(o.Join(" ")); public static void PrintBool(bool val, string yes = "Yes", string no = "No") => Console.WriteLine(val ? yes : no); public static void PrintYn(bool val) => PrintBool(val); public static void PrintYN(bool val) => PrintBool(val, "YES", "NO"); public static void PrintPossible(bool val) => PrintBool(val, "Possible", "Impossible"); public static void PrintYay(bool val) => PrintBool(val, "Yay!", ":("); public static void PrintDebug(params object[] args) => Console.Error.WriteLine(string.Join(" ", args)); /// <summary> /// setter で設定された値を標準出力に出力します。 /// </summary> public static object cout { set { Console.WriteLine(value); } } /// <summary> /// Local環境のみ,setter で設定された値を標準出力に出力します。 /// </summary> public static object dout { set { #if LOCAL Console.WriteLine(value); #endif } } /// <summary> /// setter で設定された値を標準エラー出力に出力します。 /// </summary> public static object cerr { set { Console.Error.WriteLine(value); } } public const string endl = "\n"; } public class Program { public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false}; Console.SetOut(sw); new Solver().Main(); Console.Out.Flush(); } } [DebuggerDisplay("({first}, {second})")] public class Pair<T1, T2> : IComparable<Pair<T1, T2>>, IEquatable<Pair<T1, T2>> where T1 : IComparable<T1> where T2 : IComparable<T2> { public Pair(T1 first, T2 second) { this.first = first; this.second = second; } public T1 first; public T2 second; public int CompareTo(Pair<T1, T2> other) { if (ReferenceEquals(this, other)) return 0; if (ReferenceEquals(null, other)) return 1; var firstComparison = first.CompareTo(other.first); return firstComparison != 0 ? firstComparison : second.CompareTo(other.second); } public override string ToString() => $"({first}, {second})"; public bool Equals(Pair<T1, T2> other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return EqualityComparer<T1>.Default.Equals(first, other.first) && EqualityComparer<T2>.Default.Equals(second, other.second); } public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; return obj.GetType() == GetType() && Equals((Pair<T1, T2>) obj); } public override int GetHashCode() { unchecked { return (EqualityComparer<T1>.Default.GetHashCode(first) * 397) ^ EqualityComparer<T2>.Default.GetHashCode(second); } } } #endregion }
[["-", 15, 16, 12, 16, 12, 23, 0, 16, 31, 203], ["+", 15, 16, 12, 16, 12, 23, 0, 16, 31, 250]]
8
5,475
2
using System; using System.Linq; public class Program { public static void Main() { var inputs = Console.ReadLine().Split(' ').Select(long.Parse).ToList(); var n = inputs[0]; var k = inputs[1]; var remainder = Math.Abs(n) % k; var answer = Math.Min(remainder, Math.Abs(remainder - n)); Console.WriteLine(answer); } }
using System; using System.Linq; public class Program { public static void Main() { var inputs = Console.ReadLine().Split(' ').Select(long.Parse).ToList(); var n = inputs[0]; var k = inputs[1]; var remainder = Math.Abs(n) % k; var answer = Math.Min(remainder, Math.Abs(remainder - k)); Console.WriteLine(answer); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
102
2
using System; class ABCMuriTurai { static void Main() { decimal[] Ar = Array.ConvertAll(Console.ReadLine().Split(' '), decimal.Parse); decimal N = Ar[0]; decimal K = Ar[1]; Console.WriteLine(Math.Min(N % K, N - (N % K))); } }
using System; class ABCMuriTurai { static void Main() { decimal[] Ar = Array.ConvertAll(Console.ReadLine().Split(' '), decimal.Parse); decimal N = Ar[0]; decimal K = Ar[1]; Console.WriteLine(Math.Min(N % K, K - (N % K))); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22]]
8
79
2
using System; using System.Collections.Generic; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); long n = long.Parse(input[0]); long k = long.Parse(input[1]); long res = n; if (k < n) { res = n % k; res = Math.Min(res, Math.Abs(res - k)); } Console.WriteLine(res); } } }
using System; using System.Collections.Generic; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); long n = long.Parse(input[0]); long k = long.Parse(input[1]); long res = n; if (k < n) { res = n % k; } res = Math.Min(res, Math.Abs(res - k)); Console.WriteLine(res); } } }
[["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
117
2
using System; using System.Collections.Generic; namespace AtCorder1 { class atcoder { static void Main(string[] args) { string[] all = Console.ReadLine().Split(' '); long N = int.Parse(all[0]); long K = int.Parse(all[1]); long mod = N % K; long mod2 = K - mod; if (mod < mod2) { Console.WriteLine(mod); ; } else { Console.WriteLine(mod2); } } } }
using System; using System.Collections.Generic; namespace AtCorder1 { class atcoder { static void Main(string[] args) { string[] all = Console.ReadLine().Split(' '); long N = long.Parse(all[0]); long K = long.Parse(all[1]); long mod = N % K; long mod2 = K - mod; if (mod < mod2) { Console.WriteLine(mod); ; } else { Console.WriteLine(mod2); } } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
113
4
using System; class Program { public static void Main() { var input = Console.ReadLine().Split(); long n = int.Parse(input[0]); long k = int.Parse(input[1]); long m = n % k; long ans = Math.Min(m, Math.Abs(m - k)); Console.WriteLine(ans); } }
using System; class Program { public static void Main() { var input = Console.ReadLine().Split(); long n = long.Parse(input[0]); long k = long.Parse(input[1]); long m = n % k; long ans = Math.Min(m, Math.Abs(m - k)); Console.WriteLine(ans); } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
87
4
using System; using System.Collections.Generic; namespace atcoder { class Program { static void Main(string[] args) { string[] In = Console.ReadLine().Split(' '); int n = int.Parse(In[0]); int k = int.Parse(In[1]); long bef = n % k; long af = k - bef; if (bef < af) Console.WriteLine(bef); else Console.WriteLine(af); } } }
using System; using System.Collections.Generic; namespace atcoder { class Program { static void Main(string[] args) { string[] In = Console.ReadLine().Split(' '); long n = long.Parse(In[0]); long k = long.Parse(In[1]); long bef = n % k; long af = k - bef; if (bef < af) Console.WriteLine(bef); else Console.WriteLine(af); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
108
8
using System; using System.Collections.Generic; public class Hello { public static void Main() { var input = Console.ReadLine().Split(' '); long n = long.Parse(input[0]); long k = long.Parse(input[1]); long abs = 0; long margin = 0; margin = n % k; abs = Math.Abs(n - k); long result = (abs >= margin) ? margin : abs; Console.WriteLine(result); } }
using System; using System.Collections.Generic; public class Hello { public static void Main() { var input = Console.ReadLine().Split(' '); long n = long.Parse(input[0]); long k = long.Parse(input[1]); long abs = 0; long margin = 0; margin = n % k; abs = Math.Abs(margin - k); long result = (abs >= margin) ? margin : abs; Console.WriteLine(result); } }
[["-", 12, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 31, 22]]
8
112
2
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using static System.Console; class Program { static void Main(string[] args) { // 整数の入力 // int a = int.Parse(Console.ReadLine()); // スペース区切りの整数の入力 string[] NMK = Console.ReadLine().Split(' '); double N = double.Parse(NMK[0]); double K = double.Parse(NMK[1]); // N > K の時、N%KとKにする if (N > K) { N = N % K; } // N <= K の時、最小値 = MIN(N, K-N) double A = Math.Min(N, K - N); // 文字列の入力 // string s = Console.ReadLine(); //出力 // Console.WriteLine((a+b+c) + " " + s); Console.WriteLine(A); } }
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using static System.Console; class Program { static void Main(string[] args) { // 整数の入力 // int a = int.Parse(Console.ReadLine()); // スペース区切りの整数の入力 string[] NMK = Console.ReadLine().Split(' '); long N = long.Parse(NMK[0]); long K = long.Parse(NMK[1]); // N > K の時、N%KとKにする if (N > K) { N = N % K; } // N <= K の時、最小値 = MIN(N, K-N) long A = Math.Min(N, K - N); // 文字列の入力 // string s = Console.ReadLine(); //出力 // Console.WriteLine((a+b+c) + " " + s); Console.WriteLine(A); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
131
10
/*******************************************c# * 20.04.16 AtCoder Beginner Contest 159. E - Dividing Chocolate * * *********************************************/ /********************************************* 問題文 縦 H マス、横 W マスのグリッドに区切られたチョコレートがあります。 上から i 行目、左から j 列目にあるマス (i,j) のチョコレートは、 Si,j が 0 のとき普通のチョコレートであり、1 のときホワイトチョコレートです。 このチョコレートに対して、マスの境界に沿った直線によってグリッド全体の端から 端まで割る操作を何度か行い、いくつかのブロックに分割します。 分割後のどのブロックにもホワイトチョコレートのマスが K マス以下しか含まれない ようにするためには、最小で操作を何回行う必要があるか求めてください。 ::editorial:: もし「縦方向にしか割れない」という条件があれば、左端から順に貪欲にとることで問題を解くこ とができます。よって、「横方向にどう割るか」を 2 H−1 通り全探索し、それぞれの場合について「縦 方向にしか割れない」問題を解けばよいです。計算量は O(2HHW) です。 ::test input:: 3 5 4 11100 10001 00111 *********************************************/ namespace TempName { using System; using System.Linq; using System.Collections.Generic; using System.Reflection; using static System.Console; using static IOmacro.CInput; using static IOmacro.CppInput; using static STLExtension.CppExtension; public class CRun { public void solve() { int H = cin; int W = cin; int K = cin; var S = new int [H][]; for (int i = 0; i < H; i++) { string input = _string; S[i] = new int[input.Length]; for (int j = 0; j < input.Length; j++) { S[i][j] = input[j] - 48; } } int ans = int.MaxValue; for (int bits = 0; bits < 1 << (H - 1); bits++) { // nCr 횡긋기 int true_bits = PopCount(bits); int ans_now = true_bits; int section_num = true_bits + 1; //그은 경우의수에 따른 섹션나누기 //값이 같으면 같은 섹션 (ex: 0, 0, 1, 1, 2) var section_y = new int[H]; for (int y = 0; y < H - 1; y++) { section_y[y + 1] = section_y[y] + (bits >> y & 1); } var chocos = new int[section_num]; for (int x = 0; x < W; x++) { for (int y = 0; y < H; y++) { if (S[y][x] == 1) chocos[section_y[y]] += 1; } if (chocos.Any(vcx => vcx > K)) { ans_now += 1; for (int y = 0; y < section_num; y++) { chocos[y] = 0; } for (int y = 0; y < H; y++) { if (S[y][x] == 1) chocos[section_y[y]] += 1; } if (chocos.Any(vcx => vcx > K)) { break; } } } ans = Math.Min(ans, ans_now); } WriteLine(ans); } } class Program { static void Main() { var run = new CRun(); run.solve(); } } } namespace IOmacro { // 20.05.05. 수정 using System; using System.Linq; using System.IO; using System.Collections.Generic; public class CInput { public static StreamWriter _writer = new StreamWriter(Console.OpenStandardOutput()); public const char separator = ' '; public static string _string { get { return Console.ReadLine(); } } public static string[] _stringa { get { return (Console.ReadLine().Split(separator)); } } public static int _int { get { return int.Parse(Console.ReadLine()); } } public static int[] _inta { get { return Console.ReadLine().Split(separator).Select(int.Parse).ToArray(); } } public static long _long { get { return long.Parse(Console.ReadLine()); } } public static long[] _longa { get { return Console.ReadLine().Split(separator).Select(long.Parse).ToArray(); } } public static double _double { get { return double.Parse(Console.ReadLine()); } } public static double[] _doublea { get { return Console.ReadLine().Split(separator).Select(double.Parse).ToArray(); } } } public class CConst { public static readonly int MINI = int.MaxValue; public static readonly long INF = Int64.MaxValue; } public class CppInput { public static CppInput cin => new CppInput(); public const char separator = ' '; private static readonly Queue<string> _input = new Queue<string>(); private CppInput() {} public static implicit operator string(CppInput _) { if (_input.Count == 0) Console.ReadLine().Split(separator).foreachExtension( x => _input.Enqueue(x)); return _input.Dequeue(); } public static implicit operator int(CppInput _) { if (_input.Count == 0) Console.ReadLine().Split(separator).foreachExtension( x => _input.Enqueue(x)); return int.Parse(_input.Dequeue()); } public static implicit operator long(CppInput _) { if (_input.Count == 0) Console.ReadLine().Split(separator).foreachExtension( x => _input.Enqueue(x)); return long.Parse(_input.Dequeue()); } public static implicit operator double(CppInput _) { if (_input.Count == 0) Console.ReadLine().Split(separator).foreachExtension( x => _input.Enqueue(x)); return double.Parse(_input.Dequeue()); } } public static class EnumerableExtension { public delegate void Function<in T>(T val); public static void foreachExtension<T>(this IEnumerable<T> enumerable, Function<T> function) { foreach (var x in enumerable) function(x); } } } namespace STLExtension { // 20.05.05. 수정 public class CppExtension { public static int PopCount(int n) { // A SWAR Algorithm for Popcount //비트의 1의 개수 int msb = 0; if (n < 0) { n &= int.MaxValue; msb = 1; } n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return (int)(((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24) + msb; } } }
/*******************************************c# * 20.04.16 AtCoder Beginner Contest 159. E - Dividing Chocolate * * *********************************************/ /********************************************* 問題文 縦 H マス、横 W マスのグリッドに区切られたチョコレートがあります。 上から i 行目、左から j 列目にあるマス (i,j) のチョコレートは、 Si,j が 0 のとき普通のチョコレートであり、1 のときホワイトチョコレートです。 このチョコレートに対して、マスの境界に沿った直線によってグリッド全体の端から 端まで割る操作を何度か行い、いくつかのブロックに分割します。 分割後のどのブロックにもホワイトチョコレートのマスが K マス以下しか含まれない ようにするためには、最小で操作を何回行う必要があるか求めてください。 ::editorial:: もし「縦方向にしか割れない」という条件があれば、左端から順に貪欲にとることで問題を解くこ とができます。よって、「横方向にどう割るか」を 2 H−1 通り全探索し、それぞれの場合について「縦 方向にしか割れない」問題を解けばよいです。計算量は O(2HHW) です。 ::test input:: 3 5 4 11100 10001 00111 *********************************************/ namespace TempName { using System; using System.Linq; using System.Collections.Generic; using System.Reflection; using static System.Console; using static IOmacro.CInput; using static IOmacro.CppInput; using static STLExtension.CppExtension; public class CRun { public void solve() { int H = cin; int W = cin; int K = cin; var S = new int [H][]; for (int i = 0; i < H; i++) { string input = _string; S[i] = new int[input.Length]; for (int j = 0; j < input.Length; j++) { S[i][j] = input[j] - 48; } } int ans = int.MaxValue; for (int bits = 0; bits < 1 << (H - 1); bits++) { // nCr 횡긋기 int true_bits = PopCount(bits); int ans_now = true_bits; int section_num = true_bits + 1; //그은 경우의수에 따른 섹션나누기 //값이 같으면 같은 섹션 (ex: 0, 0, 1, 1, 2) var section_y = new int[H]; for (int y = 0; y < H - 1; y++) { section_y[y + 1] = section_y[y] + (bits >> y & 1); } var chocos = new int[section_num]; for (int x = 0; x < W; x++) { for (int y = 0; y < H; y++) { if (S[y][x] == 1) chocos[section_y[y]] += 1; } if (chocos.Any(vcx => vcx > K)) { ans_now += 1; for (int y = 0; y < section_num; y++) { chocos[y] = 0; } for (int y = 0; y < H; y++) { if (S[y][x] == 1) chocos[section_y[y]] += 1; } if (chocos.Any(vcx => vcx > K)) { goto end; } } } ans = Math.Min(ans, ans_now); end:; } WriteLine(ans); } } class Program { static void Main() { var run = new CRun(); run.solve(); } } } namespace IOmacro { // 20.05.05. 수정 using System; using System.Linq; using System.IO; using System.Collections.Generic; public class CInput { public static StreamWriter _writer = new StreamWriter(Console.OpenStandardOutput()); public const char separator = ' '; public static string _string { get { return Console.ReadLine(); } } public static string[] _stringa { get { return (Console.ReadLine().Split(separator)); } } public static int _int { get { return int.Parse(Console.ReadLine()); } } public static int[] _inta { get { return Console.ReadLine().Split(separator).Select(int.Parse).ToArray(); } } public static long _long { get { return long.Parse(Console.ReadLine()); } } public static long[] _longa { get { return Console.ReadLine().Split(separator).Select(long.Parse).ToArray(); } } public static double _double { get { return double.Parse(Console.ReadLine()); } } public static double[] _doublea { get { return Console.ReadLine().Split(separator).Select(double.Parse).ToArray(); } } } public class CConst { public static readonly int MINI = int.MaxValue; public static readonly long INF = Int64.MaxValue; } public class CppInput { public static CppInput cin => new CppInput(); public const char separator = ' '; private static readonly Queue<string> _input = new Queue<string>(); private CppInput() {} public static implicit operator string(CppInput _) { if (_input.Count == 0) Console.ReadLine().Split(separator).foreachExtension( x => _input.Enqueue(x)); return _input.Dequeue(); } public static implicit operator int(CppInput _) { if (_input.Count == 0) Console.ReadLine().Split(separator).foreachExtension( x => _input.Enqueue(x)); return int.Parse(_input.Dequeue()); } public static implicit operator long(CppInput _) { if (_input.Count == 0) Console.ReadLine().Split(separator).foreachExtension( x => _input.Enqueue(x)); return long.Parse(_input.Dequeue()); } public static implicit operator double(CppInput _) { if (_input.Count == 0) Console.ReadLine().Split(separator).foreachExtension( x => _input.Enqueue(x)); return double.Parse(_input.Dequeue()); } } public static class EnumerableExtension { public delegate void Function<in T>(T val); public static void foreachExtension<T>(this IEnumerable<T> enumerable, Function<T> function) { foreach (var x in enumerable) function(x); } } } namespace STLExtension { // 20.05.05. 수정 public class CppExtension { public static int PopCount(int n) { // A SWAR Algorithm for Popcount //비트의 1의 개수 int msb = 0; if (n < 0) { n &= int.MaxValue; msb = 1; } n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return (int)(((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24) + msb; } } }
[["-", 64, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 64, 196, 0, 57, 64, 196, 0, 126, 0, 127], ["+", 64, 196, 0, 57, 64, 196, 0, 126, 0, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 97, 0, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 97, 0, 102]]
8
1,155
6