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.Linq; namespace ConsoleApp { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); var N = input[0]; var M = input[1]; var lMax = 1; var rMin = N; for (int i = 0; i < M; i++) { var LR = Console.ReadLine().Split().Select(int.Parse).ToArray(); lMax = Math.Max(lMax, LR[0]); rMin = Math.Min(rMin, LR[1]); } Console.WriteLine(rMin - lMax + 1); } } }
using System; using System.Linq; namespace ConsoleApp { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); var N = input[0]; var M = input[1]; var lMax = 1; var rMin = N; for (int i = 0; i < M; i++) { var LR = Console.ReadLine().Split().Select(int.Parse).ToArray(); lMax = Math.Max(lMax, LR[0]); rMin = Math.Min(rMin, LR[1]); } Console.WriteLine(Math.Max(0, rMin - lMax + 1)); } } }
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
156
7
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace C { public class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { var nm = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); var l = 1; var r = nm[0]; for (var i = 0; i < nm[1]; i++) { var lr = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); l = Math.Max(lr[0], l); r = Math.Min(lr[1], r); } Console.WriteLine(r - l + 1); } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace C { public class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { var nm = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); var l = 1; var r = nm[0]; for (var i = 0; i < nm[1]; i++) { var lr = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); l = Math.Max(lr[0], l); r = Math.Min(lr[1], r); } Console.WriteLine(Math.Max(r - l + 1, 0)); } } }
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
223
7
using System; using System.Linq; public class Program { static void Main() { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]); int left = int.MinValue, right = int.MaxValue; for (int i = 0; i < m; i++) { int[] lr = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); left = Math.Max(left, lr[0]); right = Math.Min(right, lr[1]); } Console.WriteLine(right - left + 1); } }
using System; using System.Linq; public class Program { static void Main() { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]); int left = int.MinValue, right = int.MaxValue; for (int i = 0; i < m; i++) { int[] lr = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); left = Math.Max(left, lr[0]); right = Math.Min(right, lr[1]); } Console.WriteLine(right - left >= 0 ? right - left + 1 : 0); } }
[["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 20], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 28, 0, 41, 64, 16, 31, 16, 31, 22], ["+", 0, 28, 0, 41, 64, 16, 31, 16, 17, 33], ["+", 0, 28, 0, 41, 64, 16, 31, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 75, 203]]
8
159
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 nm = Input3(); var n = nm[0]; var m = nm[1]; var maxrange = n; long minrange = 1; for (int i = 0; i < m; i++) { var lr = Input3(); maxrange = Math.Min(maxrange, lr[1]); minrange = Math.Max(minrange, lr[0]); } Console.WriteLine(maxrange - minrange + 1); } 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 nm = Input3(); var n = nm[0]; var m = nm[1]; var maxrange = n; long minrange = 1; for (int i = 0; i < m; i++) { var lr = Input3(); maxrange = Math.Min(maxrange, lr[1]); minrange = Math.Max(minrange, lr[0]); } if (maxrange - minrange < 0) Console.WriteLine(0); else Console.WriteLine(maxrange - minrange + 1); } 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, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95]]
8
378
16
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace AtCoder { public class Program { public static void Main() { int[] args = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int m = args[1]; int l = 1; int r = args[0]; for (int i = 0; i < m; i++) { args = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); l = Math.Max(l, args[0]); r = Math.Min(r, args[1]); } Console.WriteLine(r - l + 1); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace AtCoder { public class Program { public static void Main() { int[] args = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int m = args[1]; int l = 1; int r = args[0]; for (int i = 0; i < m; i++) { args = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); l = Math.Max(l, args[0]); r = Math.Min(r, args[1]); } Console.WriteLine(Math.Max(r - l + 1, 0)); } } }
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
170
7
using System; using System.Collections.Generic; using System.Linq; class Program { static Scanner sc = new Scanner(); static void Main(string[] args) { var N = sc.ReadInt(); var M = sc.ReadInt(); var D = new Door[M]; var maxL = int.MinValue; var minR = int.MaxValue; for (int i = 0; i < M; i++) { var l = sc.ReadInt(); var r = sc.ReadInt(); maxL = Math.Max(maxL, l); minR = Math.Min(minR, r); } var ans = minR - maxL + 1; Console.WriteLine(ans); } struct Door { public int L { get; set; } public int R { get; set; } public Door(int _L, int _R) { this.L = _L; this.R = _R; } } } class Modulo { public readonly int MOD; private readonly List<int> Facs = new List<int>() { 1 }; public Modulo(int mod = 1000000007) { this.MOD = mod; } public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % MOD); } public int Div(int a, int b) { return Mul(a, Pow(b, MOD - 2)); } public int Pow(int a, int n) { switch (n) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, n / 2); int p2 = Mul(p1, p1); return ((n % 2) == 0) ? p2 : Mul(p2, a); } } public int Fac(int n) { for (int i = this.Facs.Count; i <= n; i++) { this.Facs.Add(Mul(i, Facs[i - 1])); } return this.Facs[n]; } public int nPr(int n, int r) => Div(Fac(n), Fac(n - r)); public int nCr(int n, int r) { if (n < r) return 0; if (n == r) return 1; int res = Fac(n); res = Div(res, Fac(r)); res = Div(res, Fac(n - r)); return res; } } class Debug { public static void Dump<T>(T[,] array) { Console.WriteLine(); var h = array.GetLength(0); var w = array.GetLength(1); for (int r = 0; r < h; r++) { for (int c = 0; c < w; c++) { Console.Write(array[r, c]); Console.Write(" "); } Console.WriteLine(); } Console.WriteLine(); } public static void Dump<T>(T[] array) { Console.WriteLine(); Console.WriteLine(string.Join(" ", array)); Console.WriteLine(); } } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } } class HashMap<K, V> : Dictionary<K, V> where V : new() { private V DefaltValue = new V(); public HashMap() {} public HashMap(V defaultValue) { this.DefaltValue = new V(); } new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = this.DefaltValue; } set { base[i] = value; } } } class PriorityQueue<T> where T : IComparable<T> { public readonly T[] Array; public readonly bool Greater; public int Count { get; private set; } = 0; public PriorityQueue(int capacity, bool greater = true) { this.Array = new T[capacity]; this.Greater = greater; } public void Enqueue(T item) { this.Array[this.Count] = item; this.Count += 1; this.UpHeap(); } public T Dequeue() { this.Swap(0, this.Count - 1); this.Count -= 1; this.DownHeap(); return this.Array[this.Count]; } public T Peek() { return this.Array[0]; } private void UpHeap() { var n = this.Count - 1; while (n != 0) { var parent = (n - 1) / 2; if (this.Array[n].CompareTo(this.Array[parent]) > 0) { this.Swap(n, parent); n = parent; } else { break; } } } private void DownHeap() { var parent = 0; while (true) { var child = 2 * parent + 1; if (child > this.Count - 1) break; if (child < this.Count - 1 && this.Compare(this.Array[child], this.Array[child + 1]) < 0) { child += 1; } if (this.Compare(this.Array[parent], this.Array[child]) < 0) { this.Swap(parent, child); parent = child; } else { break; } } } private int Compare(T a, T b) { var c = a.CompareTo(b); if (!this.Greater) { c = -c; } return c; } private void Swap(int a, int b) { var tmp = this.Array[a]; this.Array[a] = this.Array[b]; this.Array[b] = tmp; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static Scanner sc = new Scanner(); static void Main(string[] args) { var N = sc.ReadInt(); var M = sc.ReadInt(); var D = new Door[M]; var maxL = int.MinValue; var minR = int.MaxValue; for (int i = 0; i < M; i++) { var l = sc.ReadInt(); var r = sc.ReadInt(); maxL = Math.Max(maxL, l); minR = Math.Min(minR, r); } if (minR - maxL < 0) { Console.WriteLine(0); } else { var ans = minR - maxL + 1; Console.WriteLine(ans); } } struct Door { public int L { get; set; } public int R { get; set; } public Door(int _L, int _R) { this.L = _L; this.R = _R; } } } class Modulo { public readonly int MOD; private readonly List<int> Facs = new List<int>() { 1 }; public Modulo(int mod = 1000000007) { this.MOD = mod; } public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % MOD); } public int Div(int a, int b) { return Mul(a, Pow(b, MOD - 2)); } public int Pow(int a, int n) { switch (n) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, n / 2); int p2 = Mul(p1, p1); return ((n % 2) == 0) ? p2 : Mul(p2, a); } } public int Fac(int n) { for (int i = this.Facs.Count; i <= n; i++) { this.Facs.Add(Mul(i, Facs[i - 1])); } return this.Facs[n]; } public int nPr(int n, int r) => Div(Fac(n), Fac(n - r)); public int nCr(int n, int r) { if (n < r) return 0; if (n == r) return 1; int res = Fac(n); res = Div(res, Fac(r)); res = Div(res, Fac(n - r)); return res; } } class Debug { public static void Dump<T>(T[,] array) { Console.WriteLine(); var h = array.GetLength(0); var w = array.GetLength(1); for (int r = 0; r < h; r++) { for (int c = 0; c < w; c++) { Console.Write(array[r, c]); Console.Write(" "); } Console.WriteLine(); } Console.WriteLine(); } public static void Dump<T>(T[] array) { Console.WriteLine(); Console.WriteLine(string.Join(" ", array)); Console.WriteLine(); } } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } } class HashMap<K, V> : Dictionary<K, V> where V : new() { private V DefaltValue = new V(); public HashMap() {} public HashMap(V defaultValue) { this.DefaltValue = new V(); } new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = this.DefaltValue; } set { base[i] = value; } } } class PriorityQueue<T> where T : IComparable<T> { public readonly T[] Array; public readonly bool Greater; public int Count { get; private set; } = 0; public PriorityQueue(int capacity, bool greater = true) { this.Array = new T[capacity]; this.Greater = greater; } public void Enqueue(T item) { this.Array[this.Count] = item; this.Count += 1; this.UpHeap(); } public T Dequeue() { this.Swap(0, this.Count - 1); this.Count -= 1; this.DownHeap(); return this.Array[this.Count]; } public T Peek() { return this.Array[0]; } private void UpHeap() { var n = this.Count - 1; while (n != 0) { var parent = (n - 1) / 2; if (this.Array[n].CompareTo(this.Array[parent]) > 0) { this.Swap(n, parent); n = parent; } else { break; } } } private void DownHeap() { var parent = 0; while (true) { var child = 2 * parent + 1; if (child > this.Count - 1) break; if (child < this.Count - 1 && this.Compare(this.Array[child], this.Array[child + 1]) < 0) { child += 1; } if (this.Compare(this.Array[parent], this.Array[child]) < 0) { this.Swap(parent, child); parent = child; } else { break; } } } private int Compare(T a, T b) { var c = a.CompareTo(b); if (!this.Greater) { c = -c; } return c; } private void Swap(int a, int b) { var tmp = this.Array[a]; this.Array[a] = this.Array[b]; this.Array[b] = tmp; } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
1,645
20
using System; using System.Linq; using System.Collections.Generic; namespace c { class Program { static void Main(string[] args) { var _ = Console.ReadLine().Split(); var n = int.Parse(_[0]); var m = int.Parse(_[1]); var minPos = 0; var maxPos = int.MaxValue; for (var i = 0; i < m; i++) { var t = Console.ReadLine().Split(); var l = int.Parse(t[0]); var r = int.Parse(t[1]); minPos = Math.Max(minPos, l); maxPos = Math.Min(maxPos, r); } Console.WriteLine( Enumerable.Range(minPos, maxPos - minPos + 1).ToArray().Length); } } }
using System; using System.Linq; using System.Collections.Generic; namespace c { class Program { static void Main(string[] args) { var _ = Console.ReadLine().Split(); var n = int.Parse(_[0]); var m = int.Parse(_[1]); var minPos = 0; var maxPos = int.MaxValue; for (var i = 0; i < m; i++) { var t = Console.ReadLine().Split(); var l = int.Parse(t[0]); var r = int.Parse(t[1]); minPos = Math.Max(minPos, l); maxPos = Math.Min(maxPos, r); } var count = maxPos - minPos + 1; Console.WriteLine(count > 0 ? count : 0); } } }
[["-", 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], ["-", 205, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["-", 205, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 205, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 63, 214, 205, 213, 3, 4, 0, 28, 0, 22], ["-", 205, 213, 63, 214, 205, 213, 3, 4, 0, 21], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 0, 28, 0, 214, 205, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 214, 205, 213, 3, 4, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 47], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 64, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 75, 203]]
8
186
28
using System; using System.Linq; using System.Collections.Generic; namespace ABC127_1 { class c { static void Main(string[] args) { var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); int L = 0; int R = int.MaxValue; for (int i = 0; i < a[1]; i++) { var b = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (L < b[0]) L = b[0]; if (b[1] < R) R = b[1]; } Console.WriteLine(R - L + 1); } } }
using System; using System.Linq; using System.Collections.Generic; namespace ABC127_1 { class c { static void Main(string[] args) { var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); int L = 0; int R = int.MaxValue; for (int i = 0; i < a[1]; i++) { var b = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (L < b[0]) L = b[0]; if (b[1] < R) R = b[1]; } if (R - L + 1 < 0) Console.WriteLine(0); else Console.WriteLine(R - L + 1); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95]]
8
156
18
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class107 { static void Main() { var NM = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = NM[0], M = NM[1]; int[] L = new int[M]; int[] R = new int[M]; int min = int.MinValue; int max = int.MaxValue; for (int i = 0; i < M; i++) { var r = Console.ReadLine().Split().Select(int.Parse).ToArray(); min = Math.Max(min, r[0]); max = Math.Min(max, r[1]); } int ans = max - min + 1; Console.WriteLine(Math.Min(N, ans)); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class107 { static void Main() { var NM = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = NM[0], M = NM[1]; int[] L = new int[M]; int[] R = new int[M]; int min = int.MinValue; int max = int.MaxValue; for (int i = 0; i < M; i++) { var r = Console.ReadLine().Split().Select(int.Parse).ToArray(); min = Math.Max(min, r[0]); max = Math.Min(max, r[1]); } int ans = max - min + 1; if (ans < 0) ans = 0; Console.WriteLine(Math.Min(N, ans)); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
8
208
10
using System; using System.Collections.Generic; using static System.Math; using System.Linq; using System.Text; class DandA { static void Main(string[] args) { nm = ReadLineIntArray(); lrArr = ReadMLineIntArray(nm[1]); int min = 1; int max = nm[0]; for (int i = 0; i < nm[1]; i++) { if (lrArr[i][0] > min) { min = lrArr[i][0]; } if (lrArr[i][1] < max) { max = lrArr[i][1]; } } Console.WriteLine(max - min + 1); } static public void myLoop(int index, int lenght, List<bool> boolList) { myLoop(index, lenght, boolList); } 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 int iRtn; static int[] nm = null; static int[][] lrArr = null; static int[] pArr = null; 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; } }
using System; using System.Collections.Generic; using static System.Math; using System.Linq; using System.Text; class DandA { static void Main(string[] args) { nm = ReadLineIntArray(); lrArr = ReadMLineIntArray(nm[1]); int min = 1; int max = nm[0]; for (int i = 0; i < nm[1]; i++) { if (lrArr[i][0] > min) { min = lrArr[i][0]; } if (lrArr[i][1] < max) { max = lrArr[i][1]; } } if (min > max) { Console.WriteLine(0); } else { Console.WriteLine(max - min + 1); } } static public void myLoop(int index, int lenght, List<bool> boolList) { myLoop(index, lenght, boolList); } 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 int iRtn; static int[] nm = null; static int[][] lrArr = null; static int[] pArr = null; 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; } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
1,018
18
using System; public class AtCoderC { static void Main() { int n; int m; { var line = Console.ReadLine(); var words = line.Split(' '); n = int.Parse(words[0]); m = int.Parse(words[1]); } int left = 1; int right = n; for (int i = 0; i < m; i++) { var line = Console.ReadLine(); var words = line.Split(' '); int l = int.Parse(words[0]); int r = int.Parse(words[1]); left = Math.Max(l, left); right = Math.Min(r, right); } Console.WriteLine(right - left + 1); } }
using System; public class AtCoderC { static void Main() { int n; int m; { var line = Console.ReadLine(); var words = line.Split(' '); n = int.Parse(words[0]); m = int.Parse(words[1]); } int left = 1; int right = n; for (int i = 0; i < m; i++) { var line = Console.ReadLine(); var words = line.Split(' '); int l = int.Parse(words[0]); int r = int.Parse(words[1]); left = Math.Max(l, left); right = Math.Min(r, right); } if (right < left) { Console.WriteLine(0); return; } Console.WriteLine(right - left + 1); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22]]
8
174
17
using System; namespace MyProgram { class AtCoder { static void Main(string[] args) { int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int N = input[0]; int M = input[1]; int[] L = new int[M]; int[] R = new int[M]; for (var i = 0; i < M; i++) { int[] temp = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); L[i] = temp[0]; R[i] = temp[1]; } int max_L = 0; int min_R = N; for (var i = 0; i < M; i++) { if (L[i] > max_L) { max_L = L[i]; } if (R[i] < min_R) { min_R = R[i]; } } Console.WriteLine(min_R - max_L + 1); } } }
using System; namespace MyProgram { class AtCoder { static void Main(string[] args) { int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int N = input[0]; int M = input[1]; int[] L = new int[M]; int[] R = new int[M]; for (var i = 0; i < M; i++) { int[] temp = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); L[i] = temp[0]; R[i] = temp[1]; } int max_L = 0; int min_R = N; for (var i = 0; i < M; i++) { if (L[i] > max_L) { max_L = L[i]; } if (R[i] < min_R) { min_R = R[i]; } } if (min_R < max_L) { min_R = max_L - 1; } Console.WriteLine(min_R - max_L + 1); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
223
14
using System; using System.Collections.Generic; using System.Linq; namespace abc127_c { class Program { static void Main(string[] args) { var NM = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); var N = NM[0]; var M = NM[1]; int Lm = 0; int Rm = 0; for (int i = 0; i < M; i++) { var LR = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); if (Lm < LR[0] - 1) Lm = LR[0] - 1; if (Rm < N - LR[1]) Rm = N - LR[1]; } Console.WriteLine(N - (Lm + Rm)); } } }
using System; using System.Collections.Generic; using System.Linq; namespace abc127_c { class Program { static void Main(string[] args) { var NM = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); var N = NM[0]; var M = NM[1]; int Lm = 0; int Rm = 0; for (int i = 0; i < M; i++) { var LR = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); if (Lm < LR[0] - 1) Lm = LR[0] - 1; if (Rm < N - LR[1]) Rm = N - LR[1]; } int r = N - (Lm + Rm); Console.WriteLine(r >= 0 ? r : 0); } } }
[["-", 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], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 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], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 20], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 64, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 75, 203]]
8
193
19
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public const long Giri = 1000000007; public static void Main(string[] args) { var p = Input().ToInt(); var n = p[0]; var m = p[1]; var min = 0; var max = n; for (int i = 0; i < m; i++) { p = Input().ToInt(); min = Math.Max(p[0], min); max = Math.Min(p[1], max); } Console.WriteLine(max - min + 1); } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(' '); } public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt(); return r; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public const long Giri = 1000000007; public static void Main(string[] args) { var p = Input().ToInt(); var n = p[0]; var m = p[1]; var min = 0; var max = n; for (int i = 0; i < m; i++) { p = Input().ToInt(); min = Math.Max(p[0], min); max = Math.Min(p[1], max); } Console.WriteLine(Math.Max(0, max - min + 1)); } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(' '); } public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt(); return r; } }
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
371
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public const long Giri = 1000000007; public static void Main(string[] args) { var ps = Input().ToInt(); var n = ps[0]; var m = ps[1]; int min = -1; int max = 999999999; for (int i = 0; i < m; i++) { ps = Input().ToInt(); min = Math.Max(ps[0], min); max = Math.Min(ps[1], max); } Console.WriteLine(max - min + 1); } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(' '); } public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt(); return r; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public const long Giri = 1000000007; public static void Main(string[] args) { var ps = Input().ToInt(); var n = ps[0]; var m = ps[1]; int min = -1; int max = 999999999; for (int i = 0; i < m; i++) { ps = Input().ToInt(); min = Math.Max(ps[0], min); max = Math.Min(ps[1], max); } if (max < min) Console.WriteLine(0); else Console.WriteLine(max - min + 1); } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(' '); } public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt(); return r; } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95]]
8
372
14
using System; using System.Linq; namespace CSharp { class Program { public static void Main() { var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var N = input[0]; var M = input[1]; var l = 1; var r = N; for (int i = 0; i < M; i++) { input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var L = input[0]; var R = input[1]; l = Math.Max(l, L); r = Math.Min(r, R); } Console.WriteLine(r - l + 1); } } }
using System; using System.Linq; namespace CSharp { class Program { public static void Main() { var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var N = input[0]; var M = input[1]; var l = 1; var r = N; for (int i = 0; i < M; i++) { input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var L = input[0]; var R = input[1]; l = Math.Max(l, L); r = Math.Min(r, R); } Console.WriteLine(Math.Max(0, r - l + 1)); } } }
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
168
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace AtCoder { static class Program { static void Main() { //ここから var M = IO.ReadLineToIntList()[1]; var min = int.MinValue; var max = int.MaxValue; for (var i = 0; i < M; i++) { var vs = IO.ReadLineToIntList(); min = Math.Max(min, vs[0]); max = Math.Min(max, vs[1]); } var ans = max - min + 1; //ここまで Console.WriteLine(ans); Console.ReadKey(); } } static class Func { static long mod = 1000000007; static public void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static public long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; } static public long LCM(long a, long b) { return (long)a * b / GCD(a, b); } static public int Factorial(int a) { return a == 1 ? a : a * Factorial(a - 1); } public static double ToAngle(this double radian) { return (double)(radian * 180 / Math.PI); } public static double ToRadian(this double angle) { return (double)(angle * Math.PI / 180); } static public long Conbination(int n, int m) { if (m == 0) return 1; if (n == 0) return 0; return n * Conbination(n - 1, m - 1) / m; } static public void Factoring(long num, ref long[] vs) { if (num == 1) { vs[1]++; } for (long i = 2; i < Math.Sqrt(num); i++) { if (num % i == 0) { vs[i]++; Factoring(num / i, ref vs); } } vs[1]++; } } static class IO { static public string ReadLineToString() { return Console.ReadLine(); } static public int ReadLineToInt() { return int.Parse(Console.ReadLine()); } static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); } static public List<string> ReadLineToStringList() { return Console.ReadLine().Split(' ').ToList(); } static public List<int> ReadLineToIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); } static public List<long> ReadLineToLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); } static public List<double> ReadLineToDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteStrings(object[] strings) { foreach (var o in strings) { Console.Write(o + " "); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace AtCoder { static class Program { static void Main() { //ここから var M = IO.ReadLineToIntList()[1]; var min = int.MinValue; var max = int.MaxValue; for (var i = 0; i < M; i++) { var vs = IO.ReadLineToIntList(); min = Math.Max(min, vs[0]); max = Math.Min(max, vs[1]); } var ans = Math.Max(max - min + 1, 0); //ここまで Console.WriteLine(ans); Console.ReadKey(); } } static class Func { static long mod = 1000000007; static public void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static public long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; } static public long LCM(long a, long b) { return (long)a * b / GCD(a, b); } static public int Factorial(int a) { return a == 1 ? a : a * Factorial(a - 1); } public static double ToAngle(this double radian) { return (double)(radian * 180 / Math.PI); } public static double ToRadian(this double angle) { return (double)(angle * Math.PI / 180); } static public long Conbination(int n, int m) { if (m == 0) return 1; if (n == 0) return 0; return n * Conbination(n - 1, m - 1) / m; } static public void Factoring(long num, ref long[] vs) { if (num == 1) { vs[1]++; } for (long i = 2; i < Math.Sqrt(num); i++) { if (num % i == 0) { vs[i]++; Factoring(num / i, ref vs); } } vs[1]++; } } static class IO { static public string ReadLineToString() { return Console.ReadLine(); } static public int ReadLineToInt() { return int.Parse(Console.ReadLine()); } static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); } static public List<string> ReadLineToStringList() { return Console.ReadLine().Split(' ').ToList(); } static public List<int> ReadLineToIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); } static public List<long> ReadLineToLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); } static public List<double> ReadLineToDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteStrings(object[] strings) { foreach (var o in strings) { Console.Write(o + " "); } } } }
[["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
8
685
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var NM = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); var N = NM[0]; var M = NM[1]; var L = new int[M]; var R = new int[M]; for (int i = 0; i < M; i++) { var LM = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); L[i] = LM[0]; R[i] = LM[1]; } Console.WriteLine(R.Min() - L.Max() + 1); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var NM = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); var N = NM[0]; var M = NM[1]; var L = new int[M]; var R = new int[M]; for (int i = 0; i < M; i++) { var LM = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); L[i] = LM[0]; R[i] = LM[1]; } if (R.Min() - L.Max() + 1 >= 0) { Console.WriteLine(R.Min() - L.Max() + 1); } else { Console.WriteLine(0); } } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 31, 16, 31, 16, 31, 213, 63, 214, 205, 22], ["+", 31, 16, 31, 16, 31, 213, 63, 214, 0, 131], ["+", 31, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["+", 31, 16, 31, 16, 31, 213, 3, 4, 0, 24], ["+", 31, 16, 31, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 33], ["+", 31, 16, 31, 16, 12, 213, 63, 214, 205, 22], ["+", 31, 16, 31, 16, 12, 213, 63, 214, 0, 131], ["+", 31, 16, 31, 16, 12, 213, 63, 214, 141, 22], ["+", 31, 16, 31, 16, 12, 213, 3, 4, 0, 24], ["+", 31, 16, 31, 16, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
179
30
using System; using System.Linq; using System.Collections.Generic; using System.IO; class Program { public static long ReadInt() { return long.Parse(Console.ReadLine()); } public static long[] ReadInts() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } public static void Main() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var input = ReadInts(); var N = input[0]; var M = input[1]; var min = N; var max = (long)0; for (int i = 0; i < M; i++) { var input0 = ReadInts(); var L = input0[0]; var R = input0[1]; if (max < L) max = L; if (min > R) min = R; } Console.WriteLine(min - max + 1); Console.Out.Flush(); } }
using System; using System.Linq; using System.Collections.Generic; using System.IO; class Program { public static long ReadInt() { return long.Parse(Console.ReadLine()); } public static long[] ReadInts() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } public static void Main() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var input = ReadInts(); var N = input[0]; var M = input[1]; var min = N; var max = (long)0; for (int i = 0; i < M; i++) { var input0 = ReadInts(); var L = input0[0]; var R = input0[1]; if (max < L) max = L; if (min > R) min = R; } if (min - max + 1 >= 0) Console.WriteLine(min - max + 1); else Console.WriteLine(0); Console.Out.Flush(); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 75, 1, 0, 213, 3, 4, 0, 24], ["+", 75, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
223
18
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace AtCoder { public class Program { // static int[] parent; static void Main(string[] args) { int[] input = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray(); int N = input[0]; int M = input[1]; // input = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray(); // 全てのゲートを通過できるカードの下限と上限 int a = 0, b = N + 1; for (int i = 0; i < M; i++) { input = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray(); int L = input[0]; int R = input[1]; if (a < L) a = L; if (b > R) b = R; } // aからbまでのカードが全てのゲートを通過できるので int ret = b - a + 1; Console.WriteLine(ret + ""); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace AtCoder { public class Program { // static int[] parent; static void Main(string[] args) { int[] input = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray(); int N = input[0]; int M = input[1]; // input = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray(); // 全てのゲートを通過できるカードの下限と上限 int a = 0, b = N + 1; for (int i = 0; i < M; i++) { input = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray(); int L = input[0]; int R = input[1]; if (a < L) a = L; if (b > R) b = R; } // aからbまでのカードが全てのゲートを通過できるので int ret = b - a + 1; if (ret < 0) ret = 0; Console.WriteLine(ret + ""); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
8
208
10
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Numerics; namespace AtcoderC { class Program { /*static void Main(string[] args) { }*/ // ABC132C //全探索法 /*static void Main() { BigInteger N = int.Parse(Console.ReadLine()); int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int min = input.Min(); int max = input.Max(); int countARC = 0; int countABC = 0; int Answer = 0; for (int i = min; i <= max; i++) { countABC = 0; countARC = 0; foreach (int n in input) { if (n > i) { countARC++; } else { countABC++; } } if (countABC == countARC) { Answer++; } } Console.WriteLine(Answer); }*/ // 2回目 /*static void Main() { int N = int.Parse(Console.ReadLine()); int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); Array.Sort(input); int min = input[(N / 2) - 1]; int max = input[N / 2]; Console.WriteLine(max - min); }*/ // ABC131C //ユーグリッドの互除法の応用 /*static void Main() { BigInteger[] input = Console.ReadLine().Split().Select(BigInteger.Parse).ToArray(); BigInteger A = input[0]; BigInteger B = input[1]; BigInteger C = input[2]; BigInteger D = input[3]; BigInteger ans = (B / C) + (B / D); //最小公倍数 var ans2 = C * D / lcm(C, D); BigInteger ans3 = B / ans2; var BB = B - ans + ans3; ans = (A - 1) / C + (A - 1) / D; ans3 = (A - 1) / ans2; var AA = (A - 1) - ans + ans3; Console.WriteLine(BB - AA); } static public BigInteger lcm(BigInteger a, BigInteger b) { var r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; }*/ // 129C //動的計画法 // TLEになる時間がかかり過ぎる /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; List<int> ttt = new List<int>(); for (int i = 0;i < M;i++) { var temp = int.Parse(Console.ReadLine()); ttt.Add(temp); } int[] dparray = new int[N+2]; dparray[N] = 1; dparray[N - 1] = 1; for (int i = N-1; i >= 0; i--) { if (ttt.Contains(i)) { dparray[i] = 0; } dparray[i] = (dparray[i + 1] + dparray[i + 2]) % 1000000007; } Console.WriteLine(dparray[0]); }*/ // ABC128 /*static void Main() { }*/ // ABC134A /*static void Main() { int r = int.Parse(Console.ReadLine()); var ans = 3 * r * r; Console.WriteLine(ans); }*/ // ABC134B /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int D = input[1]; int count = 0; int ans = N; while (true) { ans = ans - (D * 2 + 1); count++; if (ans <= 0) { break; } } Console.WriteLine(count); }*/ // ABC134C /*static void Main() { int N = int.Parse(Console.ReadLine()); List<int> array = new List<int>(); for (int i =0;i<N; i++) { array.Add(int.Parse(Console.ReadLine())); } List<int> ans = new List<int>(); int max = array.Max(); var temp = new List<int>(); foreach (int n in array) { temp.Add(n); } temp.Sort(); temp.Reverse(); int second = temp[1]; foreach (int nn in array) { if (nn == max) { Console.WriteLine(second); } else { Console.WriteLine(max); } } }*/ // 134ABCD /*static void Main() { int N = int.Parse(Console.ReadLine()); int count = 0; int ans = 0; int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i = 0;i<N;i++) { for (int j =0;j<N; j++) { if ((j+1)%(i+1)==0) { count += input[j]; } } if (count % 2 == input[i]) { ans++; } count = 0; } if (ans != 0) { } }*/ // AGC036 /*static void Main() { long S = long.Parse(Console.ReadLine()); long X1 = 1000000000; long Y1 = 0; /*while (true) { Y1 = S / X1 + S % X1; } Y1 = S / X1 + S % X1; Console.WriteLine("0 0 " + X1 + " 0 0 " + Y1); /*int tempX = 0; List<long> ss = new List<long>(); while (tempX < S) { var ans = S % tempX; if (ans == 0) { ss.Add(ans); } tempX++; } Console.WriteLine(tempX);*/ /*long X1 = 0; long Y1 = 1; while (true) { X1 = S % Y1; if (X1 <= 1000000000) { break; } Y1++; } Console.WriteLine("0 0 "+X1+" 0 0 "+Y1); }*/ // ABC82A /*static void Main() { double[] input = Console.ReadLine().Split().Select(double.Parse).ToArray(); double a = input[0]; double b = input[1]; double sum = (a + b) / 2; Console.WriteLine(Math.Ceiling(sum)); }*/ // ABC128C /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; int ans = 0; List<int[]> K = new List<int[]>(); for (int i = 0;i<M;i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); K.Add(temp); } int[] P = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] light = new int[M]; for (int i = 0;i < Math.Pow(2,N);i++) { var isrow = 0; var temp = int.Parse(Convert.ToString(i, 2)).ToString("0000000000"); for (int j =0;j < M;j++) { var ison = 0; for (int k = 0; k < K[j][0];k++) { var index = K[j][k] - 1; if (temp[9-index] == '1') { ison++; } } if (ison % 2 == P[j]) { isrow++; } else { break; } } if (isrow == M) { ans++; } } Console.WriteLine(ans);*/ /*nt[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int a = input[0]; int b = input[1]; var temp = a * b % 2; if (temp == 0) { Console.WriteLine("even"); } else { Console.WriteLine("odd"); } }*/ // ABC127C /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; List<int[]> gate = new List<int[]>(); for (int i = 0; i < M; i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); gate.Add(temp); } if (M == 1) { Console.WriteLine(N); } else { List<int> card = new List<int>(); for (int i = gate[0][0]; i <= gate[0][1]; i++) { card.Add(i); } for (int j = 1; j < gate.Count; j++) { List<int> ans = new List<int>(); var count = 0; for (int i = gate[j][0]; i <= gate[j][1]; i++) { if (card.Contains(i)) { count++; ans.Add(i); } } if (count == 0) { break; } card = new List<int>(ans); } Console.WriteLine(card.Count()); } }*/ // 127C Revenge TLE /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; List<int[]> gate = new List<int[]>(); for (int i = 0; i < M; i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); gate.Add(temp); } int Ans = 0; for (int i =1;i<=N;i++) { var count = 0; for (int j = 0;j < gate.Count;j++) { if (gate[j][0] <= i && i <= gate[j][1]) { count++; } } if (count == gate.Count) { Ans++; } } Console.WriteLine(Ans); }*/ // 127C RevengeVer2 static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; List<int[]> gate = new List<int[]>(); for (int i = 0; i < M; i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); gate.Add(temp); } List<int> Max = new List<int>(); List<int> Min = new List<int>(); for (int i = 0; i < M; i++) { Max.Add(gate[i][1]); Min.Add(gate[i][0]); } int max = Max.Min(); int min = Min.Max(); Console.WriteLine(max - min + 1); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Numerics; namespace AtcoderC { class Program { /*static void Main(string[] args) { }*/ // ABC132C //全探索法 /*static void Main() { BigInteger N = int.Parse(Console.ReadLine()); int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int min = input.Min(); int max = input.Max(); int countARC = 0; int countABC = 0; int Answer = 0; for (int i = min; i <= max; i++) { countABC = 0; countARC = 0; foreach (int n in input) { if (n > i) { countARC++; } else { countABC++; } } if (countABC == countARC) { Answer++; } } Console.WriteLine(Answer); }*/ // 2回目 /*static void Main() { int N = int.Parse(Console.ReadLine()); int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); Array.Sort(input); int min = input[(N / 2) - 1]; int max = input[N / 2]; Console.WriteLine(max - min); }*/ // ABC131C //ユーグリッドの互除法の応用 /*static void Main() { BigInteger[] input = Console.ReadLine().Split().Select(BigInteger.Parse).ToArray(); BigInteger A = input[0]; BigInteger B = input[1]; BigInteger C = input[2]; BigInteger D = input[3]; BigInteger ans = (B / C) + (B / D); //最小公倍数 var ans2 = C * D / lcm(C, D); BigInteger ans3 = B / ans2; var BB = B - ans + ans3; ans = (A - 1) / C + (A - 1) / D; ans3 = (A - 1) / ans2; var AA = (A - 1) - ans + ans3; Console.WriteLine(BB - AA); } static public BigInteger lcm(BigInteger a, BigInteger b) { var r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; }*/ // 129C //動的計画法 // TLEになる時間がかかり過ぎる /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; List<int> ttt = new List<int>(); for (int i = 0;i < M;i++) { var temp = int.Parse(Console.ReadLine()); ttt.Add(temp); } int[] dparray = new int[N+2]; dparray[N] = 1; dparray[N - 1] = 1; for (int i = N-1; i >= 0; i--) { if (ttt.Contains(i)) { dparray[i] = 0; } dparray[i] = (dparray[i + 1] + dparray[i + 2]) % 1000000007; } Console.WriteLine(dparray[0]); }*/ // ABC128 /*static void Main() { }*/ // ABC134A /*static void Main() { int r = int.Parse(Console.ReadLine()); var ans = 3 * r * r; Console.WriteLine(ans); }*/ // ABC134B /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int D = input[1]; int count = 0; int ans = N; while (true) { ans = ans - (D * 2 + 1); count++; if (ans <= 0) { break; } } Console.WriteLine(count); }*/ // ABC134C /*static void Main() { int N = int.Parse(Console.ReadLine()); List<int> array = new List<int>(); for (int i =0;i<N; i++) { array.Add(int.Parse(Console.ReadLine())); } List<int> ans = new List<int>(); int max = array.Max(); var temp = new List<int>(); foreach (int n in array) { temp.Add(n); } temp.Sort(); temp.Reverse(); int second = temp[1]; foreach (int nn in array) { if (nn == max) { Console.WriteLine(second); } else { Console.WriteLine(max); } } }*/ // 134ABCD /*static void Main() { int N = int.Parse(Console.ReadLine()); int count = 0; int ans = 0; int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i = 0;i<N;i++) { for (int j =0;j<N; j++) { if ((j+1)%(i+1)==0) { count += input[j]; } } if (count % 2 == input[i]) { ans++; } count = 0; } if (ans != 0) { } }*/ // AGC036 /*static void Main() { long S = long.Parse(Console.ReadLine()); long X1 = 1000000000; long Y1 = 0; /*while (true) { Y1 = S / X1 + S % X1; } Y1 = S / X1 + S % X1; Console.WriteLine("0 0 " + X1 + " 0 0 " + Y1); /*int tempX = 0; List<long> ss = new List<long>(); while (tempX < S) { var ans = S % tempX; if (ans == 0) { ss.Add(ans); } tempX++; } Console.WriteLine(tempX);*/ /*long X1 = 0; long Y1 = 1; while (true) { X1 = S % Y1; if (X1 <= 1000000000) { break; } Y1++; } Console.WriteLine("0 0 "+X1+" 0 0 "+Y1); }*/ // ABC82A /*static void Main() { double[] input = Console.ReadLine().Split().Select(double.Parse).ToArray(); double a = input[0]; double b = input[1]; double sum = (a + b) / 2; Console.WriteLine(Math.Ceiling(sum)); }*/ // ABC128C /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; int ans = 0; List<int[]> K = new List<int[]>(); for (int i = 0;i<M;i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); K.Add(temp); } int[] P = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] light = new int[M]; for (int i = 0;i < Math.Pow(2,N);i++) { var isrow = 0; var temp = int.Parse(Convert.ToString(i, 2)).ToString("0000000000"); for (int j =0;j < M;j++) { var ison = 0; for (int k = 0; k < K[j][0];k++) { var index = K[j][k] - 1; if (temp[9-index] == '1') { ison++; } } if (ison % 2 == P[j]) { isrow++; } else { break; } } if (isrow == M) { ans++; } } Console.WriteLine(ans);*/ /*nt[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int a = input[0]; int b = input[1]; var temp = a * b % 2; if (temp == 0) { Console.WriteLine("even"); } else { Console.WriteLine("odd"); } }*/ // ABC127C /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; List<int[]> gate = new List<int[]>(); for (int i = 0; i < M; i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); gate.Add(temp); } if (M == 1) { Console.WriteLine(N); } else { List<int> card = new List<int>(); for (int i = gate[0][0]; i <= gate[0][1]; i++) { card.Add(i); } for (int j = 1; j < gate.Count; j++) { List<int> ans = new List<int>(); var count = 0; for (int i = gate[j][0]; i <= gate[j][1]; i++) { if (card.Contains(i)) { count++; ans.Add(i); } } if (count == 0) { break; } card = new List<int>(ans); } Console.WriteLine(card.Count()); } }*/ // 127C Revenge TLE /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; List<int[]> gate = new List<int[]>(); for (int i = 0; i < M; i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); gate.Add(temp); } int Ans = 0; for (int i =1;i<=N;i++) { var count = 0; for (int j = 0;j < gate.Count;j++) { if (gate[j][0] <= i && i <= gate[j][1]) { count++; } } if (count == gate.Count) { Ans++; } } Console.WriteLine(Ans); }*/ // 127C RevengeVer2 static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; List<int[]> gate = new List<int[]>(); for (int i = 0; i < M; i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); gate.Add(temp); } List<int> Max = new List<int>(); List<int> Min = new List<int>(); for (int i = 0; i < M; i++) { Max.Add(gate[i][1]); Min.Add(gate[i][0]); } int max = Max.Min(); int min = Min.Max(); if (min <= max) { Console.WriteLine(max - min + 1); } else { Console.WriteLine("0"); } } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
289
20
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { class Program { static void Main(string[] args) { var NM = ReadSplitLong(); var N = NM[0]; var M = NM[1]; var LR = ReadSplitLongLines(M); var min = LR.Max(x => x[0]); var max = LR.Min(x => x[1]); Console.WriteLine(max - min + 1); Console.ReadKey(); } #region MyRegion public static int ReadInt() { return int.Parse(Console.ReadLine()); } /// <summary> /// 空白区切の数値を取得する /// </summary> /// <returns>The read split int.</returns> public static int[] ReadSplitInt() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); } /// <summary> /// 空白区切の数値を取得 /// </summary> /// <returns>The read split long.</returns> public static long[] ReadSplitLong() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); } public static int[][] ReadSplitIntLines(int n) { return Enumerable.Range(0, n).Select(x => ReadSplitInt()).ToArray(); } public static long[][] ReadSplitLongLines(int n) { return Enumerable.Range(0, n).Select(x => ReadSplitLong()).ToArray(); } public static long[][] ReadSplitLongLines(long n) { var ret = new List<long[]>(); for (long i = 0; i < n; i++) { ret.Add(ReadSplitLong().ToArray()); } return ret.ToArray(); } #endregion } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { class Program { static void Main(string[] args) { var NM = ReadSplitLong(); var N = NM[0]; var M = NM[1]; var LR = ReadSplitLongLines(M); var min = LR.Max(x => x[0]); var max = LR.Min(x => x[1]); var a = max - min + 1; Console.WriteLine(a < 1 ? 0 : a); Console.ReadKey(); } #region MyRegion public static int ReadInt() { return int.Parse(Console.ReadLine()); } /// <summary> /// 空白区切の数値を取得する /// </summary> /// <returns>The read split int.</returns> public static int[] ReadSplitInt() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); } /// <summary> /// 空白区切の数値を取得 /// </summary> /// <returns>The read split long.</returns> public static long[] ReadSplitLong() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); } public static int[][] ReadSplitIntLines(int n) { return Enumerable.Range(0, n).Select(x => ReadSplitInt()).ToArray(); } public static long[][] ReadSplitLongLines(int n) { return Enumerable.Range(0, n).Select(x => ReadSplitLong()).ToArray(); } public static long[][] ReadSplitLongLines(long n) { var ret = new List<long[]>(); for (long i = 0; i < n; i++) { ret.Add(ReadSplitLong().ToArray()); } return ret.ToArray(); } #endregion } }
[["-", 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, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 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], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 18], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 64, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 75, 22]]
8
374
19
using System; using System.Linq; using System.Collections.Generic; using static System.Console; class Solver { Scanner sc = new Scanner(); public void Solve() { var N = sc.nextInt(); var M = sc.nextInt(); var L = new int[M]; var R = new int[M]; for (int i = 0; i < M; i++) { L[i] = sc.nextInt(); R[i] = sc.nextInt(); } int l = L[0]; int r = R[0]; for (int i = 1; i < M; i++) { l = Math.Max(l, L[i]); r = Math.Min(r, R[i]); } WriteLine(r - l + 1); } } 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 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 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[] args) { Solver s = new Solver(); s.Solve(); } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; class Solver { Scanner sc = new Scanner(); public void Solve() { var N = sc.nextInt(); var M = sc.nextInt(); var L = new int[M]; var R = new int[M]; for (int i = 0; i < M; i++) { L[i] = sc.nextInt(); R[i] = sc.nextInt(); } int l = L[0]; int r = R[0]; for (int i = 1; i < M; i++) { l = Math.Max(l, L[i]); r = Math.Min(r, R[i]); } if (r < l) { WriteLine(0); } else { WriteLine(r - l + 1); } } } 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 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 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[] args) { Solver s = new Solver(); s.Solve(); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
562
16
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { class Program { static void Main(string[] args) { new ABC127().SolveC(new ConsoleInput(Console.In, ' ')); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } class ABC127 { public void SolveC(ConsoleInput cin) { var n = cin.ReadInt; var m = cin.ReadInt; var L = new int[m]; var R = new int[m]; for (int i = 0; i < m; i++) { L[i] = cin.ReadInt; R[i] = cin.ReadInt; } int min = L[0]; int max = R[0]; for (int i = 1; i < m; i++) { if (min < L[i]) min = L[i]; if (max > R[i]) max = R[i]; } WriteLine(max - min + 1); ReadLine(); } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { class Program { static void Main(string[] args) { new ABC127().SolveC(new ConsoleInput(Console.In, ' ')); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } class ABC127 { public void SolveC(ConsoleInput cin) { var n = cin.ReadInt; var m = cin.ReadInt; var L = new int[m]; var R = new int[m]; for (int i = 0; i < m; i++) { L[i] = cin.ReadInt; R[i] = cin.ReadInt; } int min = L[0]; int max = R[0]; for (int i = 1; i < m; i++) { if (min < L[i]) min = L[i]; if (max > R[i]) max = R[i]; } if (max < min) WriteLine(0); else WriteLine(max - min + 1); ReadLine(); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 213, 63, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95]]
8
569
12
using System; using System.Linq; namespace C___Prison { class Program { static void Main(string[] args) { var NM = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = NM[0], M = NM[1]; var LiRi = new int [M] .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); var L = LiRi.Max(x => x[0]); var R = LiRi.Min(x => x[1]); Console.WriteLine(R - L + 1); } } }
using System; using System.Linq; namespace C___Prison { class Program { static void Main(string[] args) { var NM = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = NM[0], M = NM[1]; var LiRi = new int [M] .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); var L = LiRi.Max(x => x[0]); var R = LiRi.Min(x => x[1]); Console.WriteLine(Math.Max(R - L + 1, 0)); } } }
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
146
7
using System; using System.Linq; namespace abc127 { class C { static void Main(string[] args) { var input = Input.IntArray(); var N = input[0]; var M = input[1]; // ゲート int L, R, maxL = -1, minR = N; for (int i = 0; i < M; i++) { input = Input.IntArray(); L = input[0]; R = input[1]; if (maxL == -1 || maxL < L) { maxL = L; } if (R < minR) { minR = R; } } Console.WriteLine((uint)(minR - maxL + 1)); } internal class LR { public int L; public int R; } /** Input Class */ internal static class Input { /** input int */ public static int Int() => int.Parse(Console.ReadLine()); /** input str */ public static string Str() => Console.ReadLine(); /** input array of int */ public static int[] IntArray() => Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); /** input array of string */ public static string[] StrArray() => Input.Str().Split(' '); /** input array of char */ public static char[] charArray() => Input.Str().ToCharArray(); } } }
using System; using System.Linq; namespace abc127 { class C { static void Main(string[] args) { var input = Input.IntArray(); var N = input[0]; var M = input[1]; // ゲート int L, R, maxL = 1, minR = N; for (int i = 0; i < M; i++) { input = Input.IntArray(); L = input[0]; R = input[1]; if (maxL < L) { maxL = L; } if (R < minR) { minR = R; } } var res = minR - maxL + 1; if (res < 0) { res = 0; } Console.WriteLine(res); } internal class LR { public int L; public int R; } /** Input Class */ internal static class Input { /** input int */ public static int Int() => int.Parse(Console.ReadLine()); /** input str */ public static string Str() => Console.ReadLine(); /** input array of int */ public static int[] IntArray() => Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); /** input array of string */ public static string[] StrArray() => Input.Str().Split(' '); /** input array of char */ public static char[] charArray() => Input.Str().ToCharArray(); } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 241, 0, 33], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 0, 57, 15, 16, 31, 16, 12, 241, 0, 33], ["-", 0, 57, 15, 16, 31, 16, 12, 241, 0, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["-", 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], ["-", 0, 213, 3, 4, 0, 28, 0, 74, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 74, 39, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 74, 0, 25], ["-", 3, 4, 0, 28, 0, 74, 51, 23, 0, 24], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 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], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
280
34
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]); int left_max = 0; int right_min = int.MaxValue; for (int i = 0; i < m; i++) { input = Console.ReadLine().Split(' '); int l = int.Parse(input[0]); int r = int.Parse(input[1]); left_max = Math.Max(left_max, l); right_min = Math.Min(right_min, r); } Console.WriteLine(right_min - left_max + 1); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]); int left_max = 0; int right_min = int.MaxValue; for (int i = 0; i < m; i++) { input = Console.ReadLine().Split(' '); int l = int.Parse(input[0]); int r = int.Parse(input[1]); left_max = Math.Max(left_max, l); right_min = Math.Min(right_min, r); } Console.WriteLine(Math.Max(0, right_min - left_max + 1)); } }
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
176
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC127C { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int M = int.Parse(input[1]); int left = 1; int right = N; for (int i = 0; i < M; i++) { string[] LR = Console.ReadLine().Split(' '); int L = int.Parse(LR[0]); int R = int.Parse(LR[1]); left = Math.Max(left, L); right = Math.Min(right, R); } Console.WriteLine(right - left + 1); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC127C { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int M = int.Parse(input[1]); int left = 1; int right = N; for (int i = 0; i < M; i++) { string[] LR = Console.ReadLine().Split(' '); int L = int.Parse(LR[0]); int R = int.Parse(LR[1]); left = Math.Max(left, L); right = Math.Min(right, R); } //答えは必ず0枚以上 Console.WriteLine(Math.Max(right - left + 1, 0)); } } }
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
193
7
using System; namespace ABC127_C { class Program { static void Main(string[] args) { var nm = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var min = int.MinValue; var max = int.MaxValue; for (var i = 0; i < nm[1]; i++) { var num = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); if (min < num[0]) { min = num[0]; } if (max > num[1]) { max = num[1]; } } Console.WriteLine(max - min + 1); } } }
using System; namespace ABC127_C { class Program { static void Main(string[] args) { var nm = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var min = int.MinValue; var max = int.MaxValue; for (var i = 0; i < nm[1]; i++) { var num = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); if (min < num[0]) { min = num[0]; } if (max > num[1]) { max = num[1]; } } if (max < min) { Console.WriteLine(0); } else { Console.WriteLine(max - min + 1); } } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
152
18
using System; namespace Atcoder { class Program // ABC127 C - Prison { private static void Main(string[] args) { var nm = Console.ReadLine().Split(' '); var n = int.Parse(nm[0]); var m = int.Parse(nm[1]); var ans = 0; var lr = Console.ReadLine().Split(' '); var l = int.Parse(lr[0]); var r = int.Parse(lr[1]); for (var i = 1; i < m; i++) { lr = Console.ReadLine().Split(' '); var l2 = int.Parse(lr[0]); var r2 = int.Parse(lr[1]); if (l2 > r || r2 < l) { ans = 0; break; } if (l2 > l) { l = l2; } if (r2 < r) { r = r2; } } ans = ans == 0 ? r - l + 1 : 0; Console.WriteLine(ans); } } }
using System; namespace Atcoder { class Program // ABC127 C - Prison { private static void Main(string[] args) { var nm = Console.ReadLine().Split(' '); var n = int.Parse(nm[0]); var m = int.Parse(nm[1]); var ans = 0; var lr = Console.ReadLine().Split(' '); var l = int.Parse(lr[0]); var r = int.Parse(lr[1]); for (var i = 1; i < m; i++) { lr = Console.ReadLine().Split(' '); var l2 = int.Parse(lr[0]); var r2 = int.Parse(lr[1]); if (l2 > r || r2 < l || l > r) { ans = -1; break; } if (l2 > l) { l = l2; } if (r2 < r) { r = r2; } } ans = ans < 0 ? 0 : r - l + 1; Console.WriteLine(Math.Min(ans, n)); } } }
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 64, 196, 0, 1, 0, 11, 12, 241, 0, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 241, 0, 203], ["-", 0, 1, 0, 11, 12, 41, 15, 16, 17, 60], ["+", 0, 1, 0, 11, 12, 41, 15, 16, 17, 18], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 64, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 0, 102], ["-", 8, 196, 0, 1, 0, 11, 12, 41, 0, 102], ["-", 8, 196, 0, 1, 0, 11, 12, 41, 75, 203], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
233
20
using System; using System.Linq; using System.Collections.Generic; namespace Program { class Program { static void Main(string[] args) { int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int IDCard = input[0]; int Gate = input[1]; int left = 0, right = IDCard - 1; for (int i = 0; i < Gate; i++) { input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); left = Math.Max(left, input[0]); right = Math.Min(right, input[1]); } Console.WriteLine(Math.Max(right - left + 1, 0)); } } }
using System; using System.Linq; using System.Collections.Generic; namespace Program { class Program { static void Main(string[] args) { int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int IDCard = input[0]; int Gate = input[1]; int left = 1, right = IDCard; for (int i = 0; i < Gate; i++) { input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); left = Math.Max(left, input[0]); right = Math.Min(right, input[1]); } Console.WriteLine(Math.Max(right - left + 1, 0)); Console.ReadKey(); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 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
188
10
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Linq; namespace AtCoder { class Program { static void Main() { int minRight = int.MaxValue; int maxLeft = int.MinValue; var array = ReadIntArray(); int N = array[0]; int M = array[1]; int L; int R; for (int i = 0; i < M; i++) { var lr = ReadIntArray(); L = lr[0]; R = lr[1]; maxLeft = Math.Max(L, maxLeft); minRight = Math.Min(R, minRight); // Console.WriteLine($"maxLeft = {maxLeft}"); // Console.WriteLine($"minRight = {minRight}"); } Console.WriteLine(minRight - maxLeft + 1); } //ここからテンプレート // 1行に1入力 private static string ReadString() { return Console.ReadLine(); } private static int ReadInt() { return int.Parse(ReadString()); } private static long ReadLong() { return long.Parse(ReadString()); } private static double ReadDouble() { return double.Parse(ReadString()); } // 1行に複数入力(配列で取得) private static string[] ReadStringArray() { return ReadString().Split(new[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries); } private static int[] ReadIntArray() { return ReadStringArray().Select(int.Parse).ToArray(); } private static long[] ReadLongArray() { return ReadStringArray().Select(long.Parse).ToArray(); } private static double[] ReadDoubleArray() { return ReadStringArray().Select(double.Parse).ToArray(); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Linq; namespace AtCoder { class Program { static void Main() { int minRight = int.MaxValue; int maxLeft = int.MinValue; var array = ReadIntArray(); int N = array[0]; int M = array[1]; int L; int R; for (int i = 0; i < M; i++) { var lr = ReadIntArray(); L = lr[0]; R = lr[1]; maxLeft = Math.Max(L, maxLeft); minRight = Math.Min(R, minRight); // Console.WriteLine($"maxLeft = {maxLeft}"); // Console.WriteLine($"minRight = {minRight}"); } if (minRight < maxLeft) Console.WriteLine(0); else Console.WriteLine(minRight - maxLeft + 1); } //ここからテンプレート // 1行に1入力 private static string ReadString() { return Console.ReadLine(); } private static int ReadInt() { return int.Parse(ReadString()); } private static long ReadLong() { return long.Parse(ReadString()); } private static double ReadDouble() { return double.Parse(ReadString()); } // 1行に複数入力(配列で取得) private static string[] ReadStringArray() { return ReadString().Split(new[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries); } private static int[] ReadIntArray() { return ReadStringArray().Select(int.Parse).ToArray(); } private static long[] ReadLongArray() { return ReadStringArray().Select(long.Parse).ToArray(); } private static double[] ReadDoubleArray() { return ReadStringArray().Select(double.Parse).ToArray(); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95]]
8
338
14
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { string[] ss = Console.ReadLine().Split(' '); int N = int.Parse(ss[0]); int M = int.Parse(ss[1]); int L, R, LL = 1, RR = N; for (int i = 0; i < M; i++) { ss = Console.ReadLine().Split(' '); L = int.Parse(ss[0]); R = int.Parse(ss[1]); if (LL < L) { LL = L; } if (RR > R) { RR = R; } } Console.WriteLine(RR - LL + 1); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { string[] ss = Console.ReadLine().Split(' '); int N = int.Parse(ss[0]); int M = int.Parse(ss[1]); int L, R, LL = 1, RR = N; for (int i = 0; i < M; i++) { ss = Console.ReadLine().Split(' '); L = int.Parse(ss[0]); R = int.Parse(ss[1]); if (LL > R || RR < L) { Console.WriteLine("0"); return; } if (LL < L) { LL = L; } if (RR > R) { RR = R; } } Console.WriteLine(RR - LL + 1); } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18]]
8
181
23
using System; class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); int M = int.Parse(s[1]); int maxLeft = int.MinValue; int minRight = int.MaxValue; for (int i = 0; i < M; i++) { string[] input = Console.ReadLine().Split(' '); int L = int.Parse(input[0]); int R = int.Parse(input[1]); if (L > maxLeft) maxLeft = L; if (R < minRight) minRight = R; } Console.WriteLine(minRight - maxLeft + 1); } }
using System; class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); int M = int.Parse(s[1]); int maxLeft = int.MinValue; int minRight = int.MaxValue; for (int i = 0; i < M; i++) { string[] input = Console.ReadLine().Split(' '); int L = int.Parse(input[0]); int R = int.Parse(input[1]); if (L > maxLeft) maxLeft = L; if (R < minRight) minRight = R; } if (minRight < maxLeft) Console.WriteLine(0); else Console.WriteLine(minRight - maxLeft + 1); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95]]
8
167
14
using System; namespace AtCoder { 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[] newline = Console.ReadLine().Split(' '); int l_max = int.Parse(newline[0]); int r_min = int.Parse(newline[1]); for (int i = 1; i < M; i++) { newline = Console.ReadLine().Split(' '); if (int.Parse(newline[0]) > l_max) l_max = int.Parse(newline[0]); if (int.Parse(newline[1]) < r_min) r_min = int.Parse(newline[1]); } Console.WriteLine((r_min - l_max + 1).ToString()); } } }
using System; namespace AtCoder { 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[] newline = Console.ReadLine().Split(' '); int l_max = int.Parse(newline[0]); int r_min = int.Parse(newline[1]); for (int i = 1; i < M; i++) { newline = Console.ReadLine().Split(' '); if (int.Parse(newline[0]) > l_max) l_max = int.Parse(newline[0]); if (int.Parse(newline[1]) < r_min) r_min = int.Parse(newline[1]); } if (r_min >= l_max) Console.WriteLine((r_min - l_max + 1).ToString()); else Console.WriteLine("0"); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 75, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
210
16
using System; using System.Collections.Generic; using System.Linq; namespace CsTest { public class Program { static void Main(string[] args) { int[] NM = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int L = 1; int R = NM[0]; for (int i = 0; i < NM[1]; ++i) { int[] LR = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); L = Math.Max(LR[0], L); R = Math.Min(LR[1], R); } Console.WriteLine(R - L + 1); } } }
using System; using System.Collections.Generic; using System.Linq; namespace CsTest { public class Program { static void Main(string[] args) { int[] NM = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int L = 1; int R = NM[0]; for (int i = 0; i < NM[1]; ++i) { int[] LR = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); L = Math.Max(LR[0], L); R = Math.Min(LR[1], R); } if (R < L) Console.WriteLine(0); else Console.WriteLine(R - L + 1); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95]]
8
164
14
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Main { public static class Program { public static List<int> list = new List<int>(); static void Main(string[] arg) { // int r = int.Parse(Console.ReadLine()); var nm = GetIntList(Console.ReadLine()); int answer = 0; //一致範囲を探る int LMax = 1; int RMin = nm[0]; for (int i = 0; i < nm[1]; i++) { var lr = GetIntList(Console.ReadLine()); if (LMax < lr[0]) { if (RMin >= lr[0]) { LMax = lr[0]; } } if (RMin > lr[1]) { if (LMax <= lr[1]) { RMin = lr[1]; } } } answer = RMin - LMax + 1; // Console.WriteLine("lmax=" + LMax + "rmin" + RMin); Console.WriteLine(answer); Console.ReadLine(); } #region libraries private static int[] GetIntList(string line) { return line.Split(' ').Select(x => int.Parse(x)).ToArray(); } private static double[] GetDoubleList(string line) { return line.Split(' ').Select(x => double.Parse(x)).ToArray(); } private static ulong[] GetUlongList(string line) { return line.Split(' ').Select(x => ulong.Parse(x)).ToArray(); } private static long[] GetLongList(string line) { return line.Split(' ').Select(x => long.Parse(x)).ToArray(); } private static int SearchNearest(this IEnumerable<int> list, int target) { var min = list.Min(c => Math.Abs(c - target)); return list.First(c => Math.Abs(c - target) == min); } public static bool IsOdd(int i) { return i % 2 == 1 ? true : false; } public static int Gcd(int a, int b) { if (a < b) { Gcd(b, a); } while (b != 0) { var rm = a % b; a = b; b = rm; } return a; } #endregion } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Main { public static class Program { public static List<int> list = new List<int>(); static void Main(string[] arg) { // int r = int.Parse(Console.ReadLine()); var nm = GetIntList(Console.ReadLine()); int answer = 0; //一致範囲を探る int LMax = 1; int RMin = nm[0]; bool flag = true; for (int i = 0; i < nm[1]; i++) { var lr = GetIntList(Console.ReadLine()); if (LMax < lr[0]) { if (RMin >= lr[0]) { LMax = lr[0]; } else { flag = false; break; } } if (RMin > lr[1]) { if (LMax <= lr[1]) { RMin = lr[1]; } else { flag = false; break; } } } if (flag) { answer = RMin - LMax + 1; } // Console.WriteLine("lmax=" + LMax + "rmin" + RMin); Console.WriteLine(answer); Console.ReadLine(); } #region libraries private static int[] GetIntList(string line) { return line.Split(' ').Select(x => int.Parse(x)).ToArray(); } private static double[] GetDoubleList(string line) { return line.Split(' ').Select(x => double.Parse(x)).ToArray(); } private static ulong[] GetUlongList(string line) { return line.Split(' ').Select(x => ulong.Parse(x)).ToArray(); } private static long[] GetLongList(string line) { return line.Split(' ').Select(x => long.Parse(x)).ToArray(); } private static int SearchNearest(this IEnumerable<int> list, int target) { var min = list.Min(c => Math.Abs(c - target)); return list.First(c => Math.Abs(c - target) == min); } public static bool IsOdd(int i) { return i % 2 == 1 ? true : false; } public static int Gcd(int a, int b) { if (a < b) { Gcd(b, a); } while (b != 0) { var rm = a % b; a = b; b = rm; } return a; } #endregion } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 211, 0, 146], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 1, 0, 11, 12, 211, 0, 147], ["+", 64, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 57, 75, 196, 0, 93, 0, 94], ["+", 64, 196, 0, 57, 75, 196, 0, 93, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 15, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
499
29
using System; using System.Linq; namespace agc030_a { class Program { static void Main(string[] args) { var text = Console.ReadLine(); var list = text.Split(' ').ToList(); var a = int.Parse(list[0]); var b = int.Parse(list[1]); int leftvalue = 1; int rightvalue = a; for (var i = 0; i < b; i++) { text = Console.ReadLine(); list = text.Split(' ').ToList(); var c = int.Parse(list[0]); var d = int.Parse(list[1]); leftvalue = Math.Max(leftvalue, c); rightvalue = Math.Min(rightvalue, d); } Console.WriteLine(rightvalue - leftvalue + 1); } } }
using System; using System.Linq; namespace agc030_a { class Program { static void Main(string[] args) { var text = Console.ReadLine(); var list = text.Split(' ').ToList(); var a = int.Parse(list[0]); var b = int.Parse(list[1]); int leftvalue = 1; int rightvalue = a; for (int i = 0; i < b; i++) { text = Console.ReadLine(); list = text.Split(' ').ToList(); var c = int.Parse(list[0]); var d = int.Parse(list[1]); leftvalue = Math.Max(leftvalue, c); rightvalue = Math.Min(rightvalue, d); } var gate = rightvalue - leftvalue; if (gate < 0) { Console.WriteLine("0"); } else { Console.WriteLine(rightvalue - leftvalue + 1); } } } }
[["-", 8, 196, 0, 7, 10, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
186
29
using System; namespace AtCoder { class Program { static void Main(string[] args) { int ans = 0; string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); int M = int.Parse(s[1]); s = Console.ReadLine().Split(' '); int Min = int.Parse(s[0]); int Max = int.Parse(s[1]); for (int i = 1; i < M; i++) { s = Console.ReadLine().Split(' '); int L = int.Parse(s[0]); int R = int.Parse(s[1]); if (Min < L) Min = L; if (Max > R) Max = R; } ans = Max - Min + 1; Console.WriteLine(ans.ToString()); } } }
using System; namespace AtCoder { class Program { static void Main(string[] args) { int ans = 0; string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); int M = int.Parse(s[1]); s = Console.ReadLine().Split(' '); int Min = int.Parse(s[0]); int Max = int.Parse(s[1]); for (int i = 1; i < M; i++) { s = Console.ReadLine().Split(' '); int L = int.Parse(s[0]); int R = int.Parse(s[1]); if (Min < L) Min = L; if (Max > R) Max = R; } if (Min > Max) ans = 0; else ans = Max - Min + 1; Console.WriteLine(ans.ToString()); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 1, 0, 11, 31, 22]]
8
208
11
namespace ABC127.C { using System; using static System.Console; using System.Linq; using System.Collections.Generic; public class Program { public static void Main(string[] args) { var l = ReadInputsAsInt().ToList(); var n = l[0]; var m = l[1]; WriteLine(Solve(n, m, ReadLinesAsInts(m).ToList())); } public static int Solve(int n, int m, List<List<int>> restriction) { var LMax = restriction.Select(x => x[0]).Max(); var RMin = restriction.Select(x => x[1]).Min(); return RMin - LMax + 1; } static IEnumerable<int> ReadInputsAsInt() => ReadLine().Split(' ').Select(x => int.Parse(x)); static IEnumerable<List<int>> ReadLinesAsInts(int lines) { for (int i = 0; i < lines; i++) { var l = ReadLine(); yield return l.Split(' ').Select(x => int.Parse(x)).ToList(); } } } }
namespace ABC127.C { using System; using static System.Console; using System.Linq; using System.Collections.Generic; public class Program { public static void Main(string[] args) { var l = ReadInputsAsInt().ToList(); var n = l[0]; var m = l[1]; WriteLine(Solve(n, m, ReadLinesAsInts(m).ToList())); } public static int Solve(int n, int m, List<List<int>> restriction) { var LMax = restriction.Select(x => x[0]).Max(); var RMin = restriction.Select(x => x[1]).Min(); if (RMin - LMax < 0) return 0; return RMin - LMax + 1; } static IEnumerable<int> ReadInputsAsInt() => ReadLine().Split(' ').Select(x => int.Parse(x)); static IEnumerable<List<int>> ReadLinesAsInts(int lines) { for (int i = 0; i < lines; i++) { var l = ReadLine(); yield return l.Split(' ').Select(x => int.Parse(x)).ToList(); } } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38]]
8
254
11
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { public class Prog { public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); new Prog().Solve(new ConsoleInput(Console.In, ' ')); Console.Out.Flush(); } public void Solve(ConsoleInput cin) { var n = cin.ReadInt; var m = cin.ReadInt; var max = 0; var min = Int32.MaxValue; for (int i = 0; i < m; i++) { var l = cin.ReadInt; var r = cin.ReadInt; max = Math.Max(max, l); min = Math.Min(min, r); } Console.WriteLine(min - max + 1); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } public void ReadIntArrays(long N, out int[] A, out int[] B) { A = new int[N]; B = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; } } } }
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { public class Prog { public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); new Prog().Solve(new ConsoleInput(Console.In, ' ')); Console.Out.Flush(); } public void Solve(ConsoleInput cin) { var n = cin.ReadInt; var m = cin.ReadInt; var max = 0; var min = Int32.MaxValue; for (int i = 0; i < m; i++) { var l = cin.ReadInt; var r = cin.ReadInt; max = Math.Max(max, l); min = Math.Min(min, r); } var ans = min - max + 1; ans = Math.Max(0, ans); Console.WriteLine(ans); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } public void ReadIntArrays(long N, out int[] A, out int[] B) { A = new int[N]; B = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; } } } }
[["-", 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, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 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], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
613
24
using System; using System.Collections.Generic; using System.Text; using System.Numerics; namespace SolutionCS { class Program { static void Main(string[] args) { string[] inS = Console.ReadLine().Split(' '); int N = int.Parse(inS[0]); int M = int.Parse(inS[1]); int left = 0; int right = int.MaxValue; for (int i = 0; i < M; i++) { string[] s2 = Console.ReadLine().Split(' '); int l = int.Parse(s2[0]) - 1; int r = int.Parse(s2[1]); left = Math.Max(left, l); right = Math.Min(right, r); } Console.WriteLine(right - left); } } }
using System; using System.Collections.Generic; using System.Text; using System.Numerics; namespace SolutionCS { class Program { static void Main(string[] args) { string[] inS = Console.ReadLine().Split(' '); int N = int.Parse(inS[0]); int M = int.Parse(inS[1]); int left = 0; int right = int.MaxValue; for (int i = 0; i < M; i++) { string[] s2 = Console.ReadLine().Split(' '); int l = int.Parse(s2[0]) - 1; int r = int.Parse(s2[1]); left = Math.Max(left, l); right = Math.Min(right, r); } Console.WriteLine(Math.Max(right - left, 0)); } } }
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
188
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC127C { class Program { static void Main(string[] args) { var nums = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList(); var n = nums[0]; var m = nums[1]; var min = int.MinValue; var max = n; foreach (var _ in Enumerable.Range(0, m)) { nums = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList(); min = Math.Max(min, nums[0]); max = Math.Min(max, nums[1]); } Console.WriteLine(max - min + 1); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC127C { class Program { static void Main(string[] args) { var nums = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList(); var n = nums[0]; var m = nums[1]; var min = int.MinValue; var max = n; foreach (var _ in Enumerable.Range(0, m)) { nums = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList(); min = Math.Max(min, nums[0]); max = Math.Min(max, nums[1]); } Console.WriteLine(Math.Max(0, max - min + 1)); } } }
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
192
7
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; namespace AtCodeeeer { class AtCOOOOOOOOOOOder { static void Main(string[] args) { int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray(); int N = s[0]; int M = s[1]; List<int> Lls = new List<int>(); List<int> Rls = new List<int>(); for (int i = 0; i < M; i++) { int[] input = ReadLine().Split(' ').Select(int.Parse).ToArray(); Lls.Add(input[0]); Rls.Add(input[1]); } WriteLine(Abs(Lls.Max() - Rls.Min()) + 1); } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; namespace AtCodeeeer { class AtCOOOOOOOOOOOder { static void Main(string[] args) { int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray(); int N = s[0]; int M = s[1]; List<int> Lls = new List<int>(); List<int> Rls = new List<int>(); for (int i = 0; i < M; i++) { int[] input = ReadLine().Split(' ').Select(int.Parse).ToArray(); Lls.Add(input[0]); Rls.Add(input[1]); } WriteLine(Rls.Min() - Lls.Max() + 1 >= 0 ? Rls.Min() - Lls.Max() + 1 : 0); } } }
[["-", 3, 4, 0, 28, 0, 16, 31, 213, 63, 22], ["+", 31, 16, 31, 16, 31, 213, 63, 214, 205, 22], ["+", 31, 16, 31, 16, 31, 213, 63, 214, 0, 131], ["+", 31, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["+", 31, 16, 31, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 41, 15, 16, 31, 16, 31, 16, 17, 33], ["-", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 28, 0, 41, 15, 16, 31, 16, 17, 72], ["+", 0, 28, 0, 41, 15, 16, 31, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 20], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 28, 0, 41, 64, 16, 31, 16, 17, 33], ["+", 64, 16, 31, 16, 12, 213, 63, 214, 205, 22], ["+", 64, 16, 31, 16, 12, 213, 63, 214, 0, 131], ["+", 64, 16, 31, 16, 12, 213, 63, 214, 141, 22], ["+", 64, 16, 31, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 75, 203]]
8
205
19
using System; namespace C___Prison { class Program { static void Main(string[] args) { var read = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int N = read[0]; int M = read[1]; int Lmax = 1; int Rmin = N; for (int i = 0; i < M; i++) { var LR = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); if (Lmax < LR[0]) Lmax = LR[0]; if (Rmin > LR[1]) Rmin = LR[1]; } Console.WriteLine(Rmin - Lmax + 1); } } }
using System; namespace C___Prison { class Program { static void Main(string[] args) { var read = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int N = read[0]; int M = read[1]; int Lmax = 1; int Rmin = N; for (int i = 0; i < M; i++) { var LR = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); if (Lmax < LR[0]) Lmax = LR[0]; if (Rmin > LR[1]) Rmin = LR[1]; } var result = Lmax <= Rmin ? Rmin - Lmax + 1 : 0; Console.WriteLine(result); } } }
[["-", 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, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 19], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 0, 212, 0, 41, 64, 16, 31, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 75, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 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], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
157
19
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc119d { class Program { static void Main(string[] args) { var s = ReadIntList(); var N = s[0]; var M = s[1]; var a = 1; var z = N; for (int i = 0; i < M; i++) { s = ReadIntList(); a = (a < s[0]) ? s[0] : a; z = (z > s[1]) ? s[1] : z; } Console.WriteLine(z - a + 1); #if DEBUG Console.ReadKey(); #endif } private static bool IsRange(int a, int from, int to) => (from <= a && a <= to); private static int ReadInt() => int.Parse(Console.ReadLine()); private static List<int> ReadIntList() => Console.ReadLine().Split().Select(int.Parse).ToList(); private static double ReadDouble() => double.Parse(Console.ReadLine()); private static List<double> ReadDoubleList() => Console.ReadLine().Split().Select(double.Parse).ToList(); private static long ReadLong() => long.Parse(Console.ReadLine()); private static List<long> ReadLongList() => Console.ReadLine().Split().Select(long.Parse).ToList(); private static List<int> Int2Digits(int a) => a.ToString().ToCharArray().Select(_ => int.Parse(_.ToString())).ToList(); private static int BinarySearch<Type>(IReadOnlyList<Type> s, Type target) // target 以下の最大要素のインデックスを返す where Type : IComparable { var lower = 0; var upper = s.Count - 1; while (upper - lower > 1) { var mid = lower + (upper - lower) / 2; if (s[mid].CompareTo(target) <= 0) { lower = mid; } else { upper = mid; } } return lower; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc119d { class Program { static void Main(string[] args) { var s = ReadIntList(); var N = s[0]; var M = s[1]; var a = 1; var z = N; for (int i = 0; i < M; i++) { s = ReadIntList(); a = (a < s[0]) ? s[0] : a; z = (z > s[1]) ? s[1] : z; } if (a <= z) Console.WriteLine(z - a + 1); else Console.WriteLine(0); #if DEBUG Console.ReadKey(); #endif } private static bool IsRange(int a, int from, int to) => (from <= a && a <= to); private static int ReadInt() => int.Parse(Console.ReadLine()); private static List<int> ReadIntList() => Console.ReadLine().Split().Select(int.Parse).ToList(); private static double ReadDouble() => double.Parse(Console.ReadLine()); private static List<double> ReadDoubleList() => Console.ReadLine().Split().Select(double.Parse).ToList(); private static long ReadLong() => long.Parse(Console.ReadLine()); private static List<long> ReadLongList() => Console.ReadLine().Split().Select(long.Parse).ToList(); private static List<int> Int2Digits(int a) => a.ToString().ToCharArray().Select(_ => int.Parse(_.ToString())).ToList(); private static int BinarySearch<Type>(IReadOnlyList<Type> s, Type target) // target 以下の最大要素のインデックスを返す where Type : IComparable { var lower = 0; var upper = s.Count - 1; while (upper - lower > 1) { var mid = lower + (upper - lower) / 2; if (s[mid].CompareTo(target) <= 0) { lower = mid; } else { upper = mid; } } return lower; } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 75, 1, 0, 213, 3, 4, 0, 24], ["+", 75, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
464
14
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp { class Program { static void Main(string[] args) { var ss = Console.ReadLine().Split(); var N = int.Parse(ss[0]); var M = int.Parse(ss[1]); var maxL = 1; var minR = N; for (int i = 0; i < M; i++) { ss = Console.ReadLine().Split(); var L = int.Parse(ss[0]); var R = int.Parse(ss[1]); maxL = Math.Max(L, maxL); minR = Math.Min(R, minR); } Console.WriteLine(minR - maxL + 1); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp { class Program { static void Main(string[] args) { var ss = Console.ReadLine().Split(); var N = int.Parse(ss[0]); var M = int.Parse(ss[1]); var maxL = 1; var minR = N; for (int i = 0; i < M; i++) { ss = Console.ReadLine().Split(); var L = int.Parse(ss[0]); var R = int.Parse(ss[1]); maxL = Math.Max(L, maxL); minR = Math.Min(R, minR); } var num = minR - maxL + 1; if (num >= 0) Console.WriteLine(minR - maxL + 1); else Console.WriteLine(0); } } }
[["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 33], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 75, 1, 0, 213, 3, 4, 0, 24], ["+", 75, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
170
23
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { static void Main(string[] args) { C(); } public static void C() { Scanner cin = new Scanner(); int n = cin.Int(); int m = cin.Int(); int[] ls = new int[m]; int[] rs = new int[m]; for (int i = 0; i < m; i++) { ls[i] = cin.Int(); rs[i] = cin.Int(); } int min = 1; int max = n; for (int i = 0; i < m; i++) { if (ls[i] > min) { min = ls[i]; } if (rs[i] < max) { max = rs[i]; } } int count = max - min + 1; Console.WriteLine(count); } } public 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 Int() { 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] = Int() + add; } return Array; } public long Long() { 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] = Long() + add; } return Array; } public double Double() { 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] = Double() + add; } return Array; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { static void Main(string[] args) { C(); } public static void C() { Scanner cin = new Scanner(); int n = cin.Int(); int m = cin.Int(); int[] ls = new int[m]; int[] rs = new int[m]; for (int i = 0; i < m; i++) { ls[i] = cin.Int(); rs[i] = cin.Int(); } int min = 1; int max = n; for (int i = 0; i < m; i++) { if (ls[i] > min) { min = ls[i]; } if (rs[i] < max) { max = rs[i]; } } int count = max - min + 1; if (count < 0) { count = 0; } Console.WriteLine(count); } } public 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 Int() { 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] = Int() + add; } return Array; } public long Long() { 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] = Long() + add; } return Array; } public double Double() { 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] = Double() + add; } return Array; } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
574
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace C { class Program { static void Main(string[] args) { int[] nm = RArInt(); int n = nm[0]; int m = nm[1]; int min = int.MinValue; int max = int.MaxValue; for (int i = 0; i < m; i++) { int[] vs = RArInt(); min = Math.Max(min, vs[0]); max = Math.Min(max, vs[1]); } Console.WriteLine(max - min + 1); } static string RSt() { return Console.ReadLine(); } static int RInt() { return int.Parse(Console.ReadLine().Trim()); } static long RLong() { return long.Parse(Console.ReadLine().Trim()); } static double RDouble() { return double.Parse(Console.ReadLine()); } static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); } static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); } static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); } static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); } static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace C { class Program { static void Main(string[] args) { int[] nm = RArInt(); int n = nm[0]; int m = nm[1]; int min = int.MinValue; int max = int.MaxValue; for (int i = 0; i < m; i++) { int[] vs = RArInt(); min = Math.Max(min, vs[0]); max = Math.Min(max, vs[1]); } if (max - min >= 0) { Console.WriteLine(max - min + 1); } else { Console.WriteLine(0); } } static string RSt() { return Console.ReadLine(); } static int RInt() { return int.Parse(Console.ReadLine().Trim()); } static long RLong() { return long.Parse(Console.ReadLine().Trim()); } static double RDouble() { return double.Parse(Console.ReadLine()); } static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); } static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); } static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); } static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); } static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
434
20
using System; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.IO; using System.Text; public class Solver { public void Solve() { int n = ri, m = ri, min = 1, max = n; int t = 0; for (int i = 0; i < m; i++) { t = ri; if (t > min) min = t; t = ri; if (t < max) max = t; } Console.WriteLine(max - min + 1); } int ri { get { return sc.Integer(); } } long rl { get { return sc.Long(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } public StreamScanner sc = new StreamScanner(Console.OpenStandardInput()); private const int mod = 1000000007; int PowUpper(int n, int b) { int p = 1; while (p <= n) { p *= b; } return p; } int Abs(int n) { return (n > 0) ? n : -n; } int Gcd(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = Gcd(p, n[i]); } return p; } int Gcd(int a, int b) { return (a == 0) ? b : Gcd(b % a, a); } int Lcm(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = Lcm(p, n[i]); } return p; } int Lcm(int a, int b) { return a * b / Gcd(a, b); } int Max(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = (p > n[i]) ? p : n[i]; } return p; } int Min(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = (p < n[i]) ? p : n[i]; } return p; } void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); } void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); } void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); } } static class Program { static public void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var solver = new Solver(); solver.Solve(); Console.Out.Flush(); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public int Integer() { return (int)Long(); } public double Double() { return double.Parse(Scan()); } }
using System; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.IO; using System.Text; public class Solver { public void Solve() { int n = ri, m = ri, min = 1, max = n; int t = 0; for (int i = 0; i < m; i++) { t = ri; if (t > min) { min = t; } t = ri; if (t < max) { max = t; } } int p = max - min + 1; Console.WriteLine(p > 0 ? p : 0); } int ri { get { return sc.Integer(); } } long rl { get { return sc.Long(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } public StreamScanner sc = new StreamScanner(Console.OpenStandardInput()); private const int mod = 1000000007; int PowUpper(int n, int b) { int p = 1; while (p <= n) { p *= b; } return p; } int Abs(int n) { return (n > 0) ? n : -n; } int Gcd(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = Gcd(p, n[i]); } return p; } int Gcd(int a, int b) { return (a == 0) ? b : Gcd(b % a, a); } int Lcm(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = Lcm(p, n[i]); } return p; } int Lcm(int a, int b) { return a * b / Gcd(a, b); } int Max(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = (p > n[i]) ? p : n[i]; } return p; } int Min(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = (p < n[i]) ? p : n[i]; } return p; } void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); } void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); } void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); } } static class Program { static public void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var solver = new Solver(); solver.Solve(); Console.Out.Flush(); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public int Integer() { return (int)Long(); } public double Double() { return double.Parse(Scan()); } }
[["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 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], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 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], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 47], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 64, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 75, 203]]
8
1,012
23
/* csc -debug C.cs && mono --debug C.exe <<< "4 2 1 3 2 4" */ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Reflection; public class HelloWorld { public static void SolveCodeForces() { var N = cin.NextInt(); var M = cin.NextInt(); var min = 1; var max = N; for (var i = 0; i < M; i++) { var l = cin.NextInt(); var r = cin.NextInt(); min = Math.Max(min, l); max = Math.Min(max, r); } System.Console.WriteLine(max - min + 1); } static Scanner cin = new Scanner(); static StringBuilder cout = new StringBuilder(); static public void Main() { SolveCodeForces(); // IncreaseStack(SolveCodeForces); // System.Console.Write(cout.ToString()); } public static void IncreaseStack(ThreadStart action, int stackSize = 128000000) { var thread = new Thread(action, stackSize); thread.Start(); thread.Join(); } } public static class Helpers { public static T[] CreateArray<T>(int length, Func<int, T> itemCreate) { var result = new T[length]; for (var i = 0; i < result.Length; i++) result[i] = itemCreate(i); return result; } } public class Scanner { private string[] line = new string[0]; private int index = 0; public string Next() { if (line.Length <= index) { line = Console.ReadLine().Split(' '); index = 0; } var res = line[index]; index++; return res; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public ulong NextUlong() { return ulong.Parse(Next()); } public string[] Array() { line = Console.ReadLine().Split(' '); index = line.Length; return line; } public int[] IntArray(int emptyPrefixLen = 0) { var array = Array(); var result = new int[emptyPrefixLen + array.Length]; for (int i = 0; i < array.Length; i++) result[emptyPrefixLen + i] = int.Parse(array[i]); return result; } public long[] LongArray() { var array = Array(); var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) result[i] = long.Parse(array[i]); return result; } public ulong[] UlongArray() { var array = Array(); var result = new ulong[array.Length]; for (int i = 0; i < array.Length; i++) result[i] = ulong.Parse(array[i]); return result; } }
/* csc -debug C.cs && mono --debug C.exe <<< "4 2 1 3 2 4" */ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Reflection; public class HelloWorld { public static void SolveCodeForces() { var N = cin.NextInt(); var M = cin.NextInt(); var min = 1; var max = N; for (var i = 0; i < M; i++) { var l = cin.NextInt(); var r = cin.NextInt(); min = Math.Max(min, l); max = Math.Min(max, r); } System.Console.WriteLine(Math.Max(0, max - min + 1)); } static Scanner cin = new Scanner(); static StringBuilder cout = new StringBuilder(); static public void Main() { SolveCodeForces(); // IncreaseStack(SolveCodeForces); // System.Console.Write(cout.ToString()); } public static void IncreaseStack(ThreadStart action, int stackSize = 128000000) { var thread = new Thread(action, stackSize); thread.Start(); thread.Join(); } } public static class Helpers { public static T[] CreateArray<T>(int length, Func<int, T> itemCreate) { var result = new T[length]; for (var i = 0; i < result.Length; i++) result[i] = itemCreate(i); return result; } } public class Scanner { private string[] line = new string[0]; private int index = 0; public string Next() { if (line.Length <= index) { line = Console.ReadLine().Split(' '); index = 0; } var res = line[index]; index++; return res; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public ulong NextUlong() { return ulong.Parse(Next()); } public string[] Array() { line = Console.ReadLine().Split(' '); index = line.Length; return line; } public int[] IntArray(int emptyPrefixLen = 0) { var array = Array(); var result = new int[emptyPrefixLen + array.Length]; for (int i = 0; i < array.Length; i++) result[emptyPrefixLen + i] = int.Parse(array[i]); return result; } public long[] LongArray() { var array = Array(); var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) result[i] = long.Parse(array[i]); return result; } public ulong[] UlongArray() { var array = Array(); var result = new ulong[array.Length]; for (int i = 0; i < array.Length; i++) result[i] = ulong.Parse(array[i]); return result; } }
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
626
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC127_C { class Program { static void Main(string[] args) { var NM = Console.ReadLine().Split().Select(int.Parse).ToArray(); var N = NM[0]; var M = NM[1]; var L = new int[M]; var R = new int[M]; for (int i = 0; i < M; i++) { var LR = Console.ReadLine().Split().Select(int.Parse).ToArray(); L[i] = LR[0]; R[i] = LR[1]; } Console.WriteLine(R.Min() - L.Max() + 1); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC127_C { class Program { static void Main(string[] args) { var NM = Console.ReadLine().Split().Select(int.Parse).ToArray(); var N = NM[0]; var M = NM[1]; var L = new int[M]; var R = new int[M]; for (int i = 0; i < M; i++) { var LR = Console.ReadLine().Split().Select(int.Parse).ToArray(); L[i] = LR[0]; R[i] = LR[1]; } var sum = R.Min() - L.Max(); Console.WriteLine(sum >= 0 ? sum + 1 : 0); } } }
[["-", 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, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 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], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 20], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 3, 4, 0, 28, 0, 41, 64, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 75, 203]]
8
183
19
using System; using System.Collections.Generic; using System.Linq; class Program { static Scanner sc = new Scanner(); static void Main(string[] args) { var N = sc.ReadInt(); var M = sc.ReadInt(); var A = sc.ReadLongArray(N); var list = new BC[M]; for (int i = 0; i < M; i++) { list[i] = new BC(sc.ReadInt(), sc.ReadInt()); } list = list.OrderByDescending(x => x.C).ToArray(); Array.Sort(A); var id = 0; for (int i = 0; i < M; i++) { var breakFlag = false; var bc = list[i]; for (int j = 0; j < bc.B; j++) { if (A[id] < bc.C) { A[id] = bc.C; id += 1; } else { breakFlag = true; break; } } if (breakFlag == true) break; } var ans = A.Sum(); Console.WriteLine(ans); } struct BC { public int B { get; set; } public int C { get; set; } public BC(int _B, int _C) { this.B = _B; this.C = _C; } } } class Modulo { public readonly int MOD; private readonly List<int> Facs = new List<int>() { 1 }; public Modulo(int mod = 1000000007) { this.MOD = mod; } public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % MOD); } public int Div(int a, int b) { return Mul(a, Pow(b, MOD - 2)); } public int Pow(int a, int n) { switch (n) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, n / 2); int p2 = Mul(p1, p1); return ((n % 2) == 0) ? p2 : Mul(p2, a); } } public int Fac(int n) { for (int i = this.Facs.Count; i <= n; i++) { this.Facs.Add(Mul(i, Facs[i - 1])); } return this.Facs[n]; } public int nPr(int n, int r) => Div(Fac(n), Fac(n - r)); public int nCr(int n, int r) { if (n < r) return 0; if (n == r) return 1; int res = Fac(n); res = Div(res, Fac(r)); res = Div(res, Fac(n - r)); return res; } } class Debug { public static void Dump<T>(T[,] array) { Console.WriteLine(); var h = array.GetLength(0); var w = array.GetLength(1); for (int r = 0; r < h; r++) { for (int c = 0; c < w; c++) { Console.Write(array[r, c]); Console.Write(" "); } Console.WriteLine(); } Console.WriteLine(); } public static void Dump<T>(T[] array) { Console.WriteLine(); Console.WriteLine(string.Join(" ", array)); Console.WriteLine(); } } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } } class HashMap<K, V> : Dictionary<K, V> where V : new() { private V DefaltValue = new V(); public HashMap() {} public HashMap(V defaultValue) { this.DefaltValue = new V(); } new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = this.DefaltValue; } set { base[i] = value; } } } class PriorityQueue<T> where T : IComparable<T> { public readonly T[] Array; public readonly bool Greater; public int Count { get; private set; } = 0; public PriorityQueue(int capacity, bool greater = true) { this.Array = new T[capacity]; this.Greater = greater; } public void Enqueue(T item) { this.Array[this.Count] = item; this.Count += 1; this.UpHeap(); } public T Dequeue() { this.Swap(0, this.Count - 1); this.Count -= 1; this.DownHeap(); return this.Array[this.Count]; } public T Peek() { return this.Array[0]; } private void UpHeap() { var n = this.Count - 1; while (n != 0) { var parent = (n - 1) / 2; if (this.Array[n].CompareTo(this.Array[parent]) > 0) { this.Swap(n, parent); n = parent; } else { break; } } } private void DownHeap() { var parent = 0; while (true) { var child = 2 * parent + 1; if (child > this.Count - 1) break; if (child < this.Count - 1 && this.Compare(this.Array[child], this.Array[child + 1]) < 0) { child += 1; } if (this.Compare(this.Array[parent], this.Array[child]) < 0) { this.Swap(parent, child); parent = child; } else { break; } } } private int Compare(T a, T b) { var c = a.CompareTo(b); if (!this.Greater) { c = -c; } return c; } private void Swap(int a, int b) { var tmp = this.Array[a]; this.Array[a] = this.Array[b]; this.Array[b] = tmp; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static Scanner sc = new Scanner(); static void Main(string[] args) { var N = sc.ReadInt(); var M = sc.ReadInt(); var A = sc.ReadLongArray(N); var list = new BC[M]; for (int i = 0; i < M; i++) { list[i] = new BC(sc.ReadInt(), sc.ReadInt()); } list = list.OrderByDescending(x => x.C).ToArray(); Array.Sort(A); var id = 0; for (int i = 0; i < M; i++) { var breakFlag = false; var bc = list[i]; for (int j = 0; j < bc.B; j++) { if (id >= N) break; if (A[id] < bc.C) { A[id] = bc.C; id += 1; } else { breakFlag = true; break; } } if (breakFlag == true) break; } var ans = A.Sum(); Console.WriteLine(ans); } struct BC { public int B { get; set; } public int C { get; set; } public BC(int _B, int _C) { this.B = _B; this.C = _C; } } } class Modulo { public readonly int MOD; private readonly List<int> Facs = new List<int>() { 1 }; public Modulo(int mod = 1000000007) { this.MOD = mod; } public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % MOD); } public int Div(int a, int b) { return Mul(a, Pow(b, MOD - 2)); } public int Pow(int a, int n) { switch (n) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, n / 2); int p2 = Mul(p1, p1); return ((n % 2) == 0) ? p2 : Mul(p2, a); } } public int Fac(int n) { for (int i = this.Facs.Count; i <= n; i++) { this.Facs.Add(Mul(i, Facs[i - 1])); } return this.Facs[n]; } public int nPr(int n, int r) => Div(Fac(n), Fac(n - r)); public int nCr(int n, int r) { if (n < r) return 0; if (n == r) return 1; int res = Fac(n); res = Div(res, Fac(r)); res = Div(res, Fac(n - r)); return res; } } class Debug { public static void Dump<T>(T[,] array) { Console.WriteLine(); var h = array.GetLength(0); var w = array.GetLength(1); for (int r = 0; r < h; r++) { for (int c = 0; c < w; c++) { Console.Write(array[r, c]); Console.Write(" "); } Console.WriteLine(); } Console.WriteLine(); } public static void Dump<T>(T[] array) { Console.WriteLine(); Console.WriteLine(string.Join(" ", array)); Console.WriteLine(); } } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } } class HashMap<K, V> : Dictionary<K, V> where V : new() { private V DefaltValue = new V(); public HashMap() {} public HashMap(V defaultValue) { this.DefaltValue = new V(); } new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = this.DefaltValue; } set { base[i] = value; } } } class PriorityQueue<T> where T : IComparable<T> { public readonly T[] Array; public readonly bool Greater; public int Count { get; private set; } = 0; public PriorityQueue(int capacity, bool greater = true) { this.Array = new T[capacity]; this.Greater = greater; } public void Enqueue(T item) { this.Array[this.Count] = item; this.Count += 1; this.UpHeap(); } public T Dequeue() { this.Swap(0, this.Count - 1); this.Count -= 1; this.DownHeap(); return this.Array[this.Count]; } public T Peek() { return this.Array[0]; } private void UpHeap() { var n = this.Count - 1; while (n != 0) { var parent = (n - 1) / 2; if (this.Array[n].CompareTo(this.Array[parent]) > 0) { this.Swap(n, parent); n = parent; } else { break; } } } private void DownHeap() { var parent = 0; while (true) { var child = 2 * parent + 1; if (child > this.Count - 1) break; if (child < this.Count - 1 && this.Compare(this.Array[child], this.Array[child + 1]) < 0) { child += 1; } if (this.Compare(this.Array[parent], this.Array[child]) < 0) { this.Swap(parent, child); parent = child; } else { break; } } } private int Compare(T a, T b) { var c = a.CompareTo(b); if (!this.Greater) { c = -c; } return c; } private void Swap(int a, int b) { var tmp = this.Array[a]; this.Array[a] = this.Array[b]; this.Array[b] = tmp; } }
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24]]
8
1,741
8
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Hello { static public int mod = 1000000007; public static void Main() { // 方針 // int[] n = inta(); int[] list = inta(); Array.Sort(list); Array.Reverse(list); // WriteLine(string.Join(" ",list)); var num = new int[n[1]]; var alt = new int[n[1]]; for (int i = 0; i < n[1]; i++) { int[] temp = inta(); num[i] = temp[0]; alt[i] = temp[1]; } Array.Sort(alt, num); Array.Reverse(alt); Array.Reverse(num); int nowplace = 0; int usecount = 0; long total = 0; for (int i = 0; i < n[0]; i++) { if (nowplace >= n[1]) { total += list[i]; } else { if (num[nowplace] <= usecount) { nowplace++; usecount = 0; } // WriteLine(nowplace); if (nowplace < n[1]) { if (list[i] < alt[nowplace]) { total += alt[nowplace]; usecount++; } else { total += list[i]; } } else { total += list[i]; } } // WriteLine(total); } WriteLine(total); } static void unionfind(ref int[] uni, int a, int b) { var memo = new List<int>(); memo.Add(a); memo.Add(b); int min = Min(a, b); while (uni[a] != a) { a = uni[a]; memo.Add(a); } while (uni[b] != b) { b = uni[b]; memo.Add(b); } min = Min(min, a); min = Min(min, b); foreach (var k in memo) { uni[k] = min; } } static int unionfind2(ref int[] uni, int a) { var memo = new List<int>(); memo.Add(a); while (uni[a] != a) { a = uni[a]; memo.Add(a); } foreach (var k in memo) { uni[k] = a; } return a; } static int binarysearchd(int[] a, int b) { int leng = a.Length; int min = 0; int max = leng - 1; while (max - min > 1) { int mid = (min + max) / 2; if (a[mid] < b) { min = mid; } else { max = mid; } } if (a[0] >= b) { return 0; } else if (a[leng - 1] < b) { return leng; } else { if (a[max] < b) { return max + 1; } return min + 1; } } static int binarysearchu(int[] a, int b) { int leng = a.Length; int min = 0; int max = leng - 1; while (max - min > 1) { int mid = (min + max) / 2; if (a[mid] < b) { min = mid; } else { max = mid; } } if (a[0] > b) { return leng; } else if (a[leng - 1] <= b) { return 0; } else { if (a[max] <= b) { return leng - (max + 1); } return leng - (min + 1); } } // 1からaまでの数字並べ替え全通り返すやつ static List<string> permutation(int a) { var list = new List<string>(); if (a == 1) { list.Add("1"); return list; } else { foreach (var k in permutation(a - 1)) { var ch = k.ToCharArray(); for (int i = 0; i <= ch.Length; i++) { string intemp = ""; if (i == 0) { intemp += a.ToString(); } for (int j = 0; j < ch.Length; j++) { intemp += ch[j].ToString(); if (i == j + 1) { intemp += a.ToString(); } } list.Add(intemp); } } } return list; } static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(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 int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //各種読取 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 int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } 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] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } 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); } } //知見 // (string) hogestr -> (char[]) hoge // char hoge = hogestr.ToCharArray(); // (char[]) hoge -> (string) hogestr // string hoge = new string(hoge); // Hashtable × Dictionary ○ // Dictionary hoge<string,int> // hoge.ContainsKey(string) -> return boolean // hoge[string] -> return int // hoge[int] -> CE // Dictionary hoge<int1,int2> // hoge<int1,int2>: hoge[int1] -> return int2 // KeyValuePair<int,int> k <-> k.Key == int1 / k.Value == int2 // SortedDictionary() > SortedList() ??? // キュー -> 幅優先 ??? // var queue = new Queue<int>(); queue.Enqueue() queue.Dequeue() // スタック -> 深さ優先 ??? // var stack = new Stack<int>(); stack.Push(hoge) stack.Pop() stackPeek() // stack.Count // if (list?.Count > 0) リストが空でもnullでもない // ソート // list.Sort(StringComparer.Ordinal); listの(辞書順?)ソート // StringComparer.Ordinal とは // Array.Sort(list1,list2); // 出力 // foreach(var a int list){ WriteLine(a); } より // WriteLine(string.Join("\n", list)); が速い // var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false}; // Console.SetOut(sw); // foreach(var k in list[num-1]){ // WriteLine(k); // } // Console.Out.Flush(); // 未知 // 最小費用流 // 二分探索の理解が浅い
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Hello { static public int mod = 1000000007; public static void Main() { // 方針 // int[] n = inta(); int[] list = inta(); Array.Sort(list); // Array.Reverse(list); // WriteLine(string.Join(" ",list)); var num = new int[n[1]]; var alt = new int[n[1]]; for (int i = 0; i < n[1]; i++) { int[] temp = inta(); num[i] = temp[0]; alt[i] = temp[1]; } Array.Sort(alt, num); Array.Reverse(alt); Array.Reverse(num); int nowplace = 0; int usecount = 0; long total = 0; for (int i = 0; i < n[0]; i++) { if (nowplace >= n[1]) { total += list[i]; } else { if (num[nowplace] <= usecount) { nowplace++; usecount = 0; } // WriteLine(nowplace); if (nowplace < n[1]) { if (list[i] < alt[nowplace]) { total += alt[nowplace]; usecount++; } else { total += list[i]; } } else { total += list[i]; } } // WriteLine(total); } WriteLine(total); Array.Reverse(list); } static void unionfind(ref int[] uni, int a, int b) { var memo = new List<int>(); memo.Add(a); memo.Add(b); int min = Min(a, b); while (uni[a] != a) { a = uni[a]; memo.Add(a); } while (uni[b] != b) { b = uni[b]; memo.Add(b); } min = Min(min, a); min = Min(min, b); foreach (var k in memo) { uni[k] = min; } } static int unionfind2(ref int[] uni, int a) { var memo = new List<int>(); memo.Add(a); while (uni[a] != a) { a = uni[a]; memo.Add(a); } foreach (var k in memo) { uni[k] = a; } return a; } static int binarysearchd(int[] a, int b) { int leng = a.Length; int min = 0; int max = leng - 1; while (max - min > 1) { int mid = (min + max) / 2; if (a[mid] < b) { min = mid; } else { max = mid; } } if (a[0] >= b) { return 0; } else if (a[leng - 1] < b) { return leng; } else { if (a[max] < b) { return max + 1; } return min + 1; } } static int binarysearchu(int[] a, int b) { int leng = a.Length; int min = 0; int max = leng - 1; while (max - min > 1) { int mid = (min + max) / 2; if (a[mid] < b) { min = mid; } else { max = mid; } } if (a[0] > b) { return leng; } else if (a[leng - 1] <= b) { return 0; } else { if (a[max] <= b) { return leng - (max + 1); } return leng - (min + 1); } } // 1からaまでの数字並べ替え全通り返すやつ static List<string> permutation(int a) { var list = new List<string>(); if (a == 1) { list.Add("1"); return list; } else { foreach (var k in permutation(a - 1)) { var ch = k.ToCharArray(); for (int i = 0; i <= ch.Length; i++) { string intemp = ""; if (i == 0) { intemp += a.ToString(); } for (int j = 0; j < ch.Length; j++) { intemp += ch[j].ToString(); if (i == j + 1) { intemp += a.ToString(); } } list.Add(intemp); } } } return list; } static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(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 int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //各種読取 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 int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } 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] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } 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); } } //知見 // (string) hogestr -> (char[]) hoge // char hoge = hogestr.ToCharArray(); // (char[]) hoge -> (string) hogestr // string hoge = new string(hoge); // Hashtable × Dictionary ○ // Dictionary hoge<string,int> // hoge.ContainsKey(string) -> return boolean // hoge[string] -> return int // hoge[int] -> CE // Dictionary hoge<int1,int2> // hoge<int1,int2>: hoge[int1] -> return int2 // KeyValuePair<int,int> k <-> k.Key == int1 / k.Value == int2 // SortedDictionary() > SortedList() ??? // キュー -> 幅優先 ??? // var queue = new Queue<int>(); queue.Enqueue() queue.Dequeue() // スタック -> 深さ優先 ??? // var stack = new Stack<int>(); stack.Push(hoge) stack.Pop() stackPeek() // stack.Count // if (list?.Count > 0) リストが空でもnullでもない // ソート // list.Sort(StringComparer.Ordinal); listの(辞書順?)ソート // StringComparer.Ordinal とは // Array.Sort(list1,list2); // 出力 // foreach(var a int list){ WriteLine(a); } より // WriteLine(string.Join("\n", list)); が速い // var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false}; // Console.SetOut(sw); // foreach(var k in list[num-1]){ // WriteLine(k); // } // Console.Out.Flush(); // 未知 // 最小費用流 // 二分探索の理解が浅い
[["-", 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], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 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], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
1,959
14
using System; using System.Collections.Generic; using static System.Math; using System.Linq; using System.Text; class DandA { static void Main(string[] args) { nm = ReadLineIntArray(); List<long> aList = ReadLineLongList(); int[] bArr = new int[nm[1]]; int[] cArr = new int[nm[1]]; for (int i = 0; i < nm[1]; i++) { int[] bc = ReadLineIntArray(); bArr[i] = bc[0]; cArr[i] = bc[1]; } Array.Sort(cArr, bArr); aList.Sort(); int index = 0; bool flg = false; for (int i = nm[1] - 1; i >= 0; i--) { for (int j = index; j < bArr[i] + index; j++) { if (aList[j] < cArr[i]) { aList[j] = cArr[i]; } else { flg = true; break; } } index += bArr[i]; if (flg) { break; } } Console.WriteLine(aList.Sum()); } static public void myLoop(int index, int lenght, List<bool> boolList) { myLoop(index, lenght, boolList); } 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 int iRtn; static int[] nm = null; static int[][] lrArr = null; static int[] pArr = null; 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; } }
using System; using System.Collections.Generic; using static System.Math; using System.Linq; using System.Text; class DandA { static void Main(string[] args) { nm = ReadLineIntArray(); List<long> aList = ReadLineLongList(); int[] bArr = new int[nm[1]]; int[] cArr = new int[nm[1]]; for (int i = 0; i < nm[1]; i++) { int[] bc = ReadLineIntArray(); bArr[i] = bc[0]; cArr[i] = bc[1]; } Array.Sort(cArr, bArr); aList.Sort(); int index = 0; bool flg = false; for (int i = nm[1] - 1; i >= 0; i--) { for (int j = index; j < bArr[i] + index; j++) { if (j == nm[0]) { flg = true; break; } if (aList[j] < cArr[i]) { aList[j] = cArr[i]; } else { flg = true; break; } } index += bArr[i]; if (flg) { break; } } Console.WriteLine(aList.Sum()); } static public void myLoop(int index, int lenght, List<bool> boolList) { myLoop(index, lenght, boolList); } 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 int iRtn; static int[] nm = null; static int[][] lrArr = null; static int[] pArr = null; 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; } }
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24]]
8
1,129
17
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using static Ha2ne2Util.Cin; using static Ha2ne2Util.Util; using static System.Console; using static System.Math; using System.Collections; namespace Test { class Program { static void Main(string[] args) { START: D127(); // 1 3 6 14 38 77 // A(); 1m // B(); 5m // C(); 8m // D(); 10m // E(); 30m // F(); // 36m #if DEBUG goto START; #endif } private static void D127() { long N = ReadLong(); long M = ReadLong(); long[] As = ReadLongArray(); List<Tuple<long, long>> BC = new List<Tuple<long, long>>(); for (int i = 0; i < M; i++) { long b = ReadLong(); long c = ReadLong(); BC.Add(new Tuple<long, long>(b, c)); } BC = BC.OrderByDescending(bc => bc.Item2).ToList(); As = As.OrderBy(a => a).ToArray(); long jSum = 0; for (int i = 0; i < M; i++) { for (int j = 0; j < BC[i].Item1; j++) { long nj = jSum + j; if (As[nj] < BC[i].Item2) { As[nj] = BC[i].Item2; } else { goto BIG_BREAK; } } jSum += BC[i].Item1; } BIG_BREAK: long ans = As.Sum(); WriteLine(ans); } class Monster { public long X { get; set; } public long H { get; set; } } private static void F() { long N = ReadLong(); long D = ReadLong(); long A = ReadLong(); Monster[] monsters = new Monster[N]; for (int i = 0; i < N; i++) { var m = new Monster(); m.X = ReadLong(); m.H = ReadLong(); monsters[i] = m; } monsters = monsters.OrderBy(m => m.X).ToArray(); long countSum = 0; long[] counts = new long[N]; int l = 0; for (int i = 0; i < N; i++) { while (monsters[l].X + 2 * D < monsters[i].X) { countSum -= counts[l]; l++; } var hp = Max(monsters[i].H - countSum * A, 0); var cnt = hp / A; if (hp % A != 0) cnt++; counts[i] = cnt; countSum += cnt; } WriteLine(counts.Sum()); } private static void E() { long H = ReadLong(); long N = ReadLong(); long[] A = new long[N]; long[] B = new long[N]; for (int i = 0; i < N; i++) { A[i] = ReadLong(); B[i] = ReadLong(); } long[] dp = new long[H + 1]; for (int i = 0; i <= H; i++) dp[i] = long.MaxValue; dp[0] = 0; for (int i = 0; i <= H; i++) { if (dp[i] == long.MaxValue) continue; for (int j = 0; j < N; j++) { long ni = Min(H, i + A[j]); dp[ni] = Min(dp[ni], dp[i] + B[j]); } } WriteLine(dp[H]); } private static void D() { long H = ReadLong(); long cnt = 0; while (0 < H) { H /= 2; cnt++; } long ans = 0; for (; 0 < cnt; cnt--) ans = ans * 2 + 1; WriteLine(ans); } private static void C() { long N = ReadLong(); int K = ReadInt(); long[] H = ReadLongArray(); var ans = H.OrderByDescending(h => h).Skip(K).Sum(); WriteLine(ans); } private static void B() { long H = ReadLong(); long N = ReadLong(); long[] A = ReadLongArray(); WriteLine(A.Sum() >= H ? "Yes" : "No"); } private static void A() { long H = ReadLong(); long A = ReadLong(); long ans = H / A; if (H % A != 0) ans++; WriteLine(ans); } } } namespace Ha2ne2Util { public static class Cin { static string[] Tokens { get; set; } static int Ptr { get; set; } public static string Next() { if (Tokens == null || Tokens.Length <= Ptr) { Tokens = Console.ReadLine().Split(' '); Ptr = 0; } return Tokens[Ptr++]; } public static int ReadInt() { return int.Parse(Next()); } public static long ReadLong() { return long.Parse(Next()); } public static int[] ReadIntArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static int[][] ReadIntTable(int n) { Tokens = null; int[][] ret = new int [n][]; for (int i = 0; i < n; i++) { ret[i] = ReadIntArray(); } return ret; } public static long[][] ReadLongTable(long n) { Tokens = null; long[][] ret = new long [n][]; for (long i = 0; i < n; i++) { ret[i] = ReadLongArray(); } return ret; } public static string ReadString() { return Next(); } /// <summary> /// "00101001010"という様な入力をintの配列にして返す /// </summary> /// <returns></returns> public static int[] ReadIntArrayFromBinaryString() { Tokens = null; return Array.ConvertAll(Console.ReadLine().ToArray(), c => int.Parse(c.ToString())); } /// <summary> /// "00101001010"という様な入力をboolの配列にして返す /// </summary> /// <returns></returns> public static bool[] ReadBoolArrayFromBinaryString() { Tokens = null; return Console.ReadLine().Select(c => c == '1').ToArray(); } } /// <summary> /// ユーティリティー /// </summary> public static class Util { // 10^17 public static readonly long INF = (long)1e17; public static IEnumerable<int> Range(int end) { for (int i = 0; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end) { for (int i = from; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end, int step) { for (int i = from; i < end; i += step) { yield return i; } } /// <summary> /// ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] Sort<T>(T[] array) { Array.Sort<T>(array); return array; } /// <summary> /// 逆順ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] ReverseSort<T>(T[] array) { Array.Sort<T>(array); Array.Reverse(array); return array; } /// <summary> /// Rubyにあるようなやつ /// ex) 5.Times(i => Console.WriteLine(i)); /// </summary> /// <param name="times"></param> /// <param name="action"></param> public static void Times(this int times, Action<int> action) { for (int i = 0; i < times; i++) { action(i); } } /// <summary> /// 引数aと引数bの値を入れ替えます /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> /// <param name="b"></param> public static void Swap<T>(ref T a, ref T b) { T _a = a; a = b; b = _a; } /// <summary> /// Console.WriteLineの自動フラッシュをしないようにする /// </summary> public static void DontAutoFlush() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public static void Flush() { Console.Out.Flush(); } /// <summary> /// 先頭と末尾に要素を増やした新しい配列を返します。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] AddHeadAndTail<T>(T[] array) { int len = array.Length; T[] res = new T[len + 2]; Array.Copy(array, 0, res, 1, len); return res; } /// <summary> /// 昇順ソート済みの配列を2分探索します。 /// 要素が見つからなかった場合はnより大きい数値の中で最小の数値のインデックスを返す。 /// </summary> /// <param name="array"></param> /// <param name="n"></param> /// <returns></returns> public static int BinarySearch(long[] array, long n) { int left = 0; int right = array.Length - 1; while (left <= right) { int mid = (right - left) / 2 + left; if (array[mid] == n) { return mid; } else if (n < array[mid]) { right = mid - 1; } else { left = mid + 1; } } return left; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static int[] GetDivisor(int n) { double sqrt = Math.Sqrt(n); List<int> divisor = new List<int>(); for (int i = 1; i <= sqrt; i++) { if (n % i == 0) { divisor.Add(i); int tmp = n / i; if (tmp != i) { divisor.Add(tmp); } } } return Sort(divisor.ToArray()); } public static int[] LongToBinaryArray(long n) { List<int> lst = new List<int>(); while (n > 0) { int amari = (int)(n % 2); lst.Add(amari); n /= 2; } return lst.ToArray(); } public static long BinaryArrayToLong(int[] binaryArray) { long result = 0; long b = 1; int len = binaryArray.Length; for (int i = 0; i < len; i++) { result += binaryArray[i] * b; b *= 2; } return result; } public static void Deconstruct<T>(this T[] items, out T t0) { t0 = items.Length > 0 ? items[0] : default(T); } public static void Deconstruct<T>(this T[] items, out T t0, out T t1) { if (items.Length < 2) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2) { if (items.Length < 3) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2, out T t3) { if (items.Length < 4) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; t3 = items[3]; } public static void ArrayInitialize<T>(T[,] array, T value) { int len0 = array.GetLength(0); int len1 = array.GetLength(1); for (int i = 0; i < len0; i++) { for (int j = 0; j < len1; j++) { array[i, j] = value; } } } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public readonly static int MOD = 1000000007; public static void ModAdd(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long minValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (n < minValue) { min = x; } } return min; } public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long maxValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (maxValue < n) { min = x; } } return min; } } /// <summary> /// HashSetにTupleを入れた時の、等値性判定方法の指定に使います。 /// HashSetのコンストラクタに渡して使います。 /// EqualsとGetHashCodeを提供します。 /// </summary> /// <typeparam name="T"></typeparam> public class EqualityComparer<T> : IEqualityComparer<T> { private Func<T, T, bool> _equals; private Func<T, int> _getHashCode; public EqualityComparer(Func<T, T, bool> equals, Func<T, int> getHashCode) { _equals = equals; _getHashCode = getHashCode; } public bool Equals(T x, T y) { return _equals(x, y); } public int GetHashCode(T obj) { return _getHashCode(obj); } } /// <summary> /// UnionFindTree /// </summary> public class UnionFindTree { public int[] Node; public UnionFindTree(int N) { Node = new int[N]; for (int i = 0; i < N; i++) { Node[i] = -1; } } public bool IsSameGroup(int x, int y) { return GetRoot(x) == GetRoot(y); } public bool Merge(int x, int y) { int xr = GetRoot(x); int yr = GetRoot(y); if (xr == yr) return false; // xが、大きなグループを示すようにSwapする(値が小さい方が大きなグループ) if (Node[xr] > Node[yr]) Swap(ref xr, ref yr); // グループの数を合算する Node[xr] += Node[yr]; // 根を張り替える Node[yr] = xr; return true; } public int Size(int x) { return -Node[GetRoot(x)]; } public int GetRoot(int n) { if (Node[n] < 0) { return n; } else { // 根を張りなおす。 Node[n] = GetRoot(Node[n]); return Node[n]; } } } /// <summary> /// PriorityQueue /// </summary> /// <typeparam name="T"></typeparam> public class PriorityQueue<T> { private Comparison<T> _comparison = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } public PriorityQueue(int maxSize, Comparison<T> comparison) { _heap = new T[maxSize]; _comparison = comparison; } private int Compare(T x, T y) { return _comparison(x, y); // if (_comparison != null) return _comparison(x, y); // return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using static Ha2ne2Util.Cin; using static Ha2ne2Util.Util; using static System.Console; using static System.Math; using System.Collections; namespace Test { class Program { static void Main(string[] args) { START: D127(); // 1 3 6 14 38 77 // A(); 1m // B(); 5m // C(); 8m // D(); 10m // E(); 30m // F(); // 36m #if DEBUG goto START; #endif } private static void D127() { long N = ReadLong(); long M = ReadLong(); long[] As = ReadLongArray(); List<Tuple<long, long>> BC = new List<Tuple<long, long>>(); for (int i = 0; i < M; i++) { long b = ReadLong(); long c = ReadLong(); BC.Add(new Tuple<long, long>(b, c)); } BC = BC.OrderByDescending(bc => bc.Item2).ToList(); As = As.OrderBy(a => a).ToArray(); long jSum = 0; for (int i = 0; i < M; i++) { for (int j = 0; j < BC[i].Item1; j++) { long nj = jSum + j; if (N <= nj || BC[i].Item2 <= As[nj]) goto BIG_BREAK; As[nj] = BC[i].Item2; } jSum += BC[i].Item1; } BIG_BREAK: long ans = As.Sum(); WriteLine(ans); } class Monster { public long X { get; set; } public long H { get; set; } } private static void F() { long N = ReadLong(); long D = ReadLong(); long A = ReadLong(); Monster[] monsters = new Monster[N]; for (int i = 0; i < N; i++) { var m = new Monster(); m.X = ReadLong(); m.H = ReadLong(); monsters[i] = m; } monsters = monsters.OrderBy(m => m.X).ToArray(); long countSum = 0; long[] counts = new long[N]; int l = 0; for (int i = 0; i < N; i++) { while (monsters[l].X + 2 * D < monsters[i].X) { countSum -= counts[l]; l++; } var hp = Max(monsters[i].H - countSum * A, 0); var cnt = hp / A; if (hp % A != 0) cnt++; counts[i] = cnt; countSum += cnt; } WriteLine(counts.Sum()); } private static void E() { long H = ReadLong(); long N = ReadLong(); long[] A = new long[N]; long[] B = new long[N]; for (int i = 0; i < N; i++) { A[i] = ReadLong(); B[i] = ReadLong(); } long[] dp = new long[H + 1]; for (int i = 0; i <= H; i++) dp[i] = long.MaxValue; dp[0] = 0; for (int i = 0; i <= H; i++) { if (dp[i] == long.MaxValue) continue; for (int j = 0; j < N; j++) { long ni = Min(H, i + A[j]); dp[ni] = Min(dp[ni], dp[i] + B[j]); } } WriteLine(dp[H]); } private static void D() { long H = ReadLong(); long cnt = 0; while (0 < H) { H /= 2; cnt++; } long ans = 0; for (; 0 < cnt; cnt--) ans = ans * 2 + 1; WriteLine(ans); } private static void C() { long N = ReadLong(); int K = ReadInt(); long[] H = ReadLongArray(); var ans = H.OrderByDescending(h => h).Skip(K).Sum(); WriteLine(ans); } private static void B() { long H = ReadLong(); long N = ReadLong(); long[] A = ReadLongArray(); WriteLine(A.Sum() >= H ? "Yes" : "No"); } private static void A() { long H = ReadLong(); long A = ReadLong(); long ans = H / A; if (H % A != 0) ans++; WriteLine(ans); } } } namespace Ha2ne2Util { public static class Cin { static string[] Tokens { get; set; } static int Ptr { get; set; } public static string Next() { if (Tokens == null || Tokens.Length <= Ptr) { Tokens = Console.ReadLine().Split(' '); Ptr = 0; } return Tokens[Ptr++]; } public static int ReadInt() { return int.Parse(Next()); } public static long ReadLong() { return long.Parse(Next()); } public static int[] ReadIntArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static int[][] ReadIntTable(int n) { Tokens = null; int[][] ret = new int [n][]; for (int i = 0; i < n; i++) { ret[i] = ReadIntArray(); } return ret; } public static long[][] ReadLongTable(long n) { Tokens = null; long[][] ret = new long [n][]; for (long i = 0; i < n; i++) { ret[i] = ReadLongArray(); } return ret; } public static string ReadString() { return Next(); } /// <summary> /// "00101001010"という様な入力をintの配列にして返す /// </summary> /// <returns></returns> public static int[] ReadIntArrayFromBinaryString() { Tokens = null; return Array.ConvertAll(Console.ReadLine().ToArray(), c => int.Parse(c.ToString())); } /// <summary> /// "00101001010"という様な入力をboolの配列にして返す /// </summary> /// <returns></returns> public static bool[] ReadBoolArrayFromBinaryString() { Tokens = null; return Console.ReadLine().Select(c => c == '1').ToArray(); } } /// <summary> /// ユーティリティー /// </summary> public static class Util { // 10^17 public static readonly long INF = (long)1e17; public static IEnumerable<int> Range(int end) { for (int i = 0; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end) { for (int i = from; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end, int step) { for (int i = from; i < end; i += step) { yield return i; } } /// <summary> /// ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] Sort<T>(T[] array) { Array.Sort<T>(array); return array; } /// <summary> /// 逆順ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] ReverseSort<T>(T[] array) { Array.Sort<T>(array); Array.Reverse(array); return array; } /// <summary> /// Rubyにあるようなやつ /// ex) 5.Times(i => Console.WriteLine(i)); /// </summary> /// <param name="times"></param> /// <param name="action"></param> public static void Times(this int times, Action<int> action) { for (int i = 0; i < times; i++) { action(i); } } /// <summary> /// 引数aと引数bの値を入れ替えます /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> /// <param name="b"></param> public static void Swap<T>(ref T a, ref T b) { T _a = a; a = b; b = _a; } /// <summary> /// Console.WriteLineの自動フラッシュをしないようにする /// </summary> public static void DontAutoFlush() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public static void Flush() { Console.Out.Flush(); } /// <summary> /// 先頭と末尾に要素を増やした新しい配列を返します。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] AddHeadAndTail<T>(T[] array) { int len = array.Length; T[] res = new T[len + 2]; Array.Copy(array, 0, res, 1, len); return res; } /// <summary> /// 昇順ソート済みの配列を2分探索します。 /// 要素が見つからなかった場合はnより大きい数値の中で最小の数値のインデックスを返す。 /// </summary> /// <param name="array"></param> /// <param name="n"></param> /// <returns></returns> public static int BinarySearch(long[] array, long n) { int left = 0; int right = array.Length - 1; while (left <= right) { int mid = (right - left) / 2 + left; if (array[mid] == n) { return mid; } else if (n < array[mid]) { right = mid - 1; } else { left = mid + 1; } } return left; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static int[] GetDivisor(int n) { double sqrt = Math.Sqrt(n); List<int> divisor = new List<int>(); for (int i = 1; i <= sqrt; i++) { if (n % i == 0) { divisor.Add(i); int tmp = n / i; if (tmp != i) { divisor.Add(tmp); } } } return Sort(divisor.ToArray()); } public static int[] LongToBinaryArray(long n) { List<int> lst = new List<int>(); while (n > 0) { int amari = (int)(n % 2); lst.Add(amari); n /= 2; } return lst.ToArray(); } public static long BinaryArrayToLong(int[] binaryArray) { long result = 0; long b = 1; int len = binaryArray.Length; for (int i = 0; i < len; i++) { result += binaryArray[i] * b; b *= 2; } return result; } public static void Deconstruct<T>(this T[] items, out T t0) { t0 = items.Length > 0 ? items[0] : default(T); } public static void Deconstruct<T>(this T[] items, out T t0, out T t1) { if (items.Length < 2) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2) { if (items.Length < 3) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2, out T t3) { if (items.Length < 4) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; t3 = items[3]; } public static void ArrayInitialize<T>(T[,] array, T value) { int len0 = array.GetLength(0); int len1 = array.GetLength(1); for (int i = 0; i < len0; i++) { for (int j = 0; j < len1; j++) { array[i, j] = value; } } } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public readonly static int MOD = 1000000007; public static void ModAdd(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long minValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (n < minValue) { min = x; } } return min; } public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long maxValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (maxValue < n) { min = x; } } return min; } } /// <summary> /// HashSetにTupleを入れた時の、等値性判定方法の指定に使います。 /// HashSetのコンストラクタに渡して使います。 /// EqualsとGetHashCodeを提供します。 /// </summary> /// <typeparam name="T"></typeparam> public class EqualityComparer<T> : IEqualityComparer<T> { private Func<T, T, bool> _equals; private Func<T, int> _getHashCode; public EqualityComparer(Func<T, T, bool> equals, Func<T, int> getHashCode) { _equals = equals; _getHashCode = getHashCode; } public bool Equals(T x, T y) { return _equals(x, y); } public int GetHashCode(T obj) { return _getHashCode(obj); } } /// <summary> /// UnionFindTree /// </summary> public class UnionFindTree { public int[] Node; public UnionFindTree(int N) { Node = new int[N]; for (int i = 0; i < N; i++) { Node[i] = -1; } } public bool IsSameGroup(int x, int y) { return GetRoot(x) == GetRoot(y); } public bool Merge(int x, int y) { int xr = GetRoot(x); int yr = GetRoot(y); if (xr == yr) return false; // xが、大きなグループを示すようにSwapする(値が小さい方が大きなグループ) if (Node[xr] > Node[yr]) Swap(ref xr, ref yr); // グループの数を合算する Node[xr] += Node[yr]; // 根を張り替える Node[yr] = xr; return true; } public int Size(int x) { return -Node[GetRoot(x)]; } public int GetRoot(int n) { if (Node[n] < 0) { return n; } else { // 根を張りなおす。 Node[n] = GetRoot(Node[n]); return Node[n]; } } } /// <summary> /// PriorityQueue /// </summary> /// <typeparam name="T"></typeparam> public class PriorityQueue<T> { private Comparison<T> _comparison = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } public PriorityQueue(int maxSize, Comparison<T> comparison) { _heap = new T[maxSize]; _comparison = comparison; } private int Compare(T x, T y) { return _comparison(x, y); // if (_comparison != null) return _comparison(x, y); // return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 64, 126, 0, 127], ["+", 0, 7, 8, 196, 0, 57, 64, 126, 0, 22], ["+", 0, 7, 8, 196, 0, 57, 64, 126, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["-", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 8, 196, 0, 57, 75, 196, 0, 126, 0, 127], ["-", 8, 196, 0, 57, 75, 196, 0, 126, 0, 22], ["-", 8, 196, 0, 57, 75, 196, 0, 126, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46]]
8
3,596
23
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtC { class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); long N = long.Parse(str[0]); long M = long.Parse(str[1]); string[] str2 = Console.ReadLine().Split(' '); long[] A = new long[N]; for (long i = 0; i < N; i++) A[i] = long.Parse(str2[i]); long[] B = new long[M]; long[] C = new long[M]; for (long i = 0; i < M; i++) { string[] str3 = Console.ReadLine().Split(' '); B[i] = long.Parse(str3[0]); C[i] = long.Parse(str3[1]); } Array.Sort(A); Array.Sort(C, B); Array.Reverse(B); Array.Reverse(C); long cnum = C[0]; long bnum = B[0]; long countA = 0; long countBC = 0; while (true) { if (cnum > A[countA]) { A[countA] = cnum; countA++; bnum--; } else break; if (bnum == 0) { countBC++; if (countBC == M) break; bnum = B[countBC]; cnum = C[countBC]; } } // for (long i = 0; i < N; i++) Console.WriteLine(A[i]); long ans = 0; for (long i = 0; i < N; i++) ans += A[i]; Console.WriteLine(ans); Console.ReadLine(); } private static void Change(long[] array, long a, long b) { long tmp = array[a]; array[a] = array[b]; array[b] = tmp; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtC { class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); long N = long.Parse(str[0]); long M = long.Parse(str[1]); string[] str2 = Console.ReadLine().Split(' '); long[] A = new long[N]; for (long i = 0; i < N; i++) A[i] = long.Parse(str2[i]); long[] B = new long[M]; long[] C = new long[M]; for (long i = 0; i < M; i++) { string[] str3 = Console.ReadLine().Split(' '); B[i] = long.Parse(str3[0]); C[i] = long.Parse(str3[1]); } Array.Sort(A); Array.Sort(C, B); Array.Reverse(B); Array.Reverse(C); long cnum = C[0]; long bnum = B[0]; long countA = 0; long countBC = 0; while (true) { if (cnum > A[countA]) { A[countA] = cnum; countA++; bnum--; } else break; if (countA == N) break; if (bnum == 0) { countBC++; if (countBC == M) break; bnum = B[countBC]; cnum = C[countBC]; } } // for (long i = 0; i < N; i++) Console.WriteLine(A[i]); long ans = 0; for (long i = 0; i < N; i++) ans += A[i]; Console.WriteLine(ans); Console.ReadLine(); } private static void Change(long[] array, long a, long b) { long tmp = array[a]; array[a] = array[b]; array[b] = tmp; } } }
[["+", 0, 52, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 25], ["+", 0, 52, 8, 196, 0, 57, 64, 93, 0, 94], ["+", 0, 52, 8, 196, 0, 57, 64, 93, 0, 35], ["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 24]]
8
439
8
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace AtCoder { static class Extensions { public static int LowerBound<T>(this IList<T> list, T value, IComparer<T> comp = null) { if (comp == null) comp = Comparer<T>.Default; var l = 0; var r = list.Count; while (l < r) { var m = (l + r) / 2; var c = comp.Compare(value, list[m]); if (c > 0) l = m + 1; else r = m; } return l; } public static int UpperBound<T>(this IList<T> list, T value, IComparer<T> comp = null) { if (comp == null) comp = Comparer<T>.Default; var l = 0; var r = list.Count; while (l < r) { var m = (l + r) / 2; var c = comp.Compare(value, list[m]); if (c >= 0) l = m + 1; else r = m; } return r; } } class Program { 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; } public static int[] ZAlgotithm(string s) { var len = s.Length; var a = new int[len]; a[0] = len; var i = 1; var j = 0; while (i < len) { while (i + j < len && s[j] == s[i + j]) j++; a[i] = j; if (j == 0) { i++; continue; } var k = 1; while (i + k < len && k + a[k] < j) { a[i + k] = a[k]; k++; } i += k; j -= k; } return a; } public class MaxHeap<T> : IEnumerable<T> { private List<T> _list; private Comparer<T> _comp; public int Count { get { return _list.Count; } } public MaxHeap() : this(0) {} public MaxHeap(int capacity, Comparison<T> comp = null) { _list = new List<T>(capacity); if (comp == null) { _comp = Comparer<T>.Default; } else { _comp = Comparer<T>.Create(comp); } } public void Push(T elem) { Upheap(elem); } public T Pop() { return Downheap(); } public T Peek() { return _list[0]; } private void Swap(int i, int j) { var a = _list[j]; _list[j] = _list[i]; _list[i] = a; } private void Upheap(T elem) { _list.Add(elem); var i = _list.Count - 1; while (true) { if (i == 0) return; var j = (i - 1) / 2; var e = _list[i]; var p = _list[j]; var c = _comp.Compare(e, p); if (c > 0) { Swap(i, j); i = j; continue; } else { break; } } } private T Downheap() { var result = _list[0]; var last = _list.Count - 1; Swap(0, last); _list.RemoveAt(last); if (_list.Count == 0) return result; var i = 0; while (true) { if (i == _list.Count - 1) return result; var p = _list[i]; var j = i * 2 + 1; if (j >= _list.Count) return result; if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) < 0) { j++; } if (_comp.Compare(_list[i], _list[j]) < 0) { Swap(i, j); i = j; } else { return result; } } } public MaxHeap<T> Copy(Comparison<T> comp = null) { var c = new MaxHeap<T>(0, comp); c._list = _list.ToList(); return c; } public MaxHeap(List<T> list) { _list = list; _comp = Comparer<T>.Default; } public List<T> GetList() { return _list; } public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } public class MinHeap<T> : IEnumerable<T> { private List<T> _list; private Comparer<T> _comp; public int Count { get { return _list.Count; } } public MinHeap() : this(0) {} public MinHeap(int capacity, Comparison<T> comp = null) { _list = new List<T>(capacity); if (comp == null) { _comp = Comparer<T>.Default; } else { _comp = Comparer<T>.Create(comp); } } public void Push(T elem) { Upheap(elem); } public T Pop() { return Downheap(); } public T Peek() { return _list[0]; } private void Swap(int i, int j) { var a = _list[j]; _list[j] = _list[i]; _list[i] = a; } private void Upheap(T elem) { _list.Add(elem); var i = _list.Count - 1; while (true) { if (i == 0) return; var j = (i - 1) / 2; var e = _list[i]; var p = _list[j]; var c = _comp.Compare(e, p); if (c < 0) { Swap(i, j); i = j; continue; } else { break; } } } private T Downheap() { var result = _list[0]; var last = _list.Count - 1; Swap(0, last); _list.RemoveAt(last); if (_list.Count == 0) return result; var i = 0; while (true) { if (i == _list.Count - 1) return result; var p = _list[i]; var j = i * 2 + 1; if (j >= _list.Count) return result; if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) > 0) { j++; } if (_comp.Compare(_list[i], _list[j]) > 0) { Swap(i, j); i = j; } else { return result; } } } public MinHeap<T> Copy(Comparison<T> comp = null) { var c = new MinHeap<T>(0, comp); c._list = _list.ToList(); return c; } public MinHeap(List<T> list) { _list = list; _comp = Comparer<T>.Default; } public List<T> GetList() { return _list; } public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } class InputLine { private string[] _inputs; private int _index = 0; InputLine(string input) { _inputs = input.Split(); _index = 0; } public static InputLine Read() { return new InputLine(Console.ReadLine()); } public int NextInt() { return int.Parse(_inputs[_index++]); } public long NextLong() { return long.Parse(_inputs[_index++]); } public double NextDouble() { return double.Parse(_inputs[_index++]); } } public static int GCD(int x, int y) { var a = Math.Max(x, y); var b = x + y - a; while (b != 0) { var c = b; b = a % b; a = c; } return a; } public static long GCD(long x, long y) { var a = Math.Max(x, y); var b = x + y - a; while (b != 0) { var c = b; b = a % b; a = c; } return a; } static long ModPower(long x, long y, long mod) { var bytes = BitConverter.GetBytes(y); var bits = new System.Collections.BitArray(bytes); var max2 = 0; for (int i = bits.Length - 1; i >= 0; i--) { if (bits[i]) { max2 = i; break; } } long result = 1; for (int i = max2; i >= 0; i--) { result = (result * result) % mod; if (bits[i]) { result = (result * x) % mod; } } return result; } static long ModFact(long n, long mod) { long result = 1; for (int i = 1; i <= n; i++) { result = result * i % mod; } return result; } static long ModAdd(long x, long y, long mod) { return ((x % mod) + (y % mod)) % mod; } static long ModMul(long x, long y, long mod) { return ((x % mod) * (y % mod)) % mod; } static long ModDiv(long x, long y, long mod) { //フェルマーの小定理より、a^(-1) = a^(p-2) return ModMul(x, ModPower(y, mod - 2, mod), mod); } static long ModComb(long n, long r, long mod) { long numerator = 1; for (int i = 0; i < r; i++) { numerator = ModMul(numerator, n - i, mod); } long denominator = ModFact(r, mod); return ModDiv(numerator, denominator, mod); } class Graph { private int _size; private List<int>[] _map; public IEnumerable<int> this[int i] { get { if (_map[i] == null) return Enumerable.Empty<int>(); return _map[i]; } } public Graph(int size) { _size = size; _map = new List<int>[size]; } public void Add(int from, int to) { if (_map[from] == null) { _map[from] = new List<int>(); } _map[from].Add(to); } } static List<T> NewList<T>(T template) { return new List<T>(); } static long p1097 = 1000000007; static void Main(string[] args) { //↓ var nm = ReadIntArray(); var n = nm[0]; var m = nm[1]; var aas = ReadIntArray().ToList(); var bcs = ReadObjects(m, x => new { B = x[0], C = x[1] }); aas.Sort(); bcs.Sort((x, y) => -x.C.CompareTo(y.C)); long sum = 0; var i = 0; var isOver = false; for (int j = 0; j < m; j++) { var bc = bcs[j]; var b = bc.B; for (int k = 0; k < b; k++) { if (bc.C <= aas[i]) { isOver = true; break; } sum += bc.C; i++; } if (isOver) break; } for (; i < n; i++) { sum += aas[i]; } Console.WriteLine(sum); //↑ } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace AtCoder { static class Extensions { public static int LowerBound<T>(this IList<T> list, T value, IComparer<T> comp = null) { if (comp == null) comp = Comparer<T>.Default; var l = 0; var r = list.Count; while (l < r) { var m = (l + r) / 2; var c = comp.Compare(value, list[m]); if (c > 0) l = m + 1; else r = m; } return l; } public static int UpperBound<T>(this IList<T> list, T value, IComparer<T> comp = null) { if (comp == null) comp = Comparer<T>.Default; var l = 0; var r = list.Count; while (l < r) { var m = (l + r) / 2; var c = comp.Compare(value, list[m]); if (c >= 0) l = m + 1; else r = m; } return r; } } class Program { 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; } public static int[] ZAlgotithm(string s) { var len = s.Length; var a = new int[len]; a[0] = len; var i = 1; var j = 0; while (i < len) { while (i + j < len && s[j] == s[i + j]) j++; a[i] = j; if (j == 0) { i++; continue; } var k = 1; while (i + k < len && k + a[k] < j) { a[i + k] = a[k]; k++; } i += k; j -= k; } return a; } public class MaxHeap<T> : IEnumerable<T> { private List<T> _list; private Comparer<T> _comp; public int Count { get { return _list.Count; } } public MaxHeap() : this(0) {} public MaxHeap(int capacity, Comparison<T> comp = null) { _list = new List<T>(capacity); if (comp == null) { _comp = Comparer<T>.Default; } else { _comp = Comparer<T>.Create(comp); } } public void Push(T elem) { Upheap(elem); } public T Pop() { return Downheap(); } public T Peek() { return _list[0]; } private void Swap(int i, int j) { var a = _list[j]; _list[j] = _list[i]; _list[i] = a; } private void Upheap(T elem) { _list.Add(elem); var i = _list.Count - 1; while (true) { if (i == 0) return; var j = (i - 1) / 2; var e = _list[i]; var p = _list[j]; var c = _comp.Compare(e, p); if (c > 0) { Swap(i, j); i = j; continue; } else { break; } } } private T Downheap() { var result = _list[0]; var last = _list.Count - 1; Swap(0, last); _list.RemoveAt(last); if (_list.Count == 0) return result; var i = 0; while (true) { if (i == _list.Count - 1) return result; var p = _list[i]; var j = i * 2 + 1; if (j >= _list.Count) return result; if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) < 0) { j++; } if (_comp.Compare(_list[i], _list[j]) < 0) { Swap(i, j); i = j; } else { return result; } } } public MaxHeap<T> Copy(Comparison<T> comp = null) { var c = new MaxHeap<T>(0, comp); c._list = _list.ToList(); return c; } public MaxHeap(List<T> list) { _list = list; _comp = Comparer<T>.Default; } public List<T> GetList() { return _list; } public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } public class MinHeap<T> : IEnumerable<T> { private List<T> _list; private Comparer<T> _comp; public int Count { get { return _list.Count; } } public MinHeap() : this(0) {} public MinHeap(int capacity, Comparison<T> comp = null) { _list = new List<T>(capacity); if (comp == null) { _comp = Comparer<T>.Default; } else { _comp = Comparer<T>.Create(comp); } } public void Push(T elem) { Upheap(elem); } public T Pop() { return Downheap(); } public T Peek() { return _list[0]; } private void Swap(int i, int j) { var a = _list[j]; _list[j] = _list[i]; _list[i] = a; } private void Upheap(T elem) { _list.Add(elem); var i = _list.Count - 1; while (true) { if (i == 0) return; var j = (i - 1) / 2; var e = _list[i]; var p = _list[j]; var c = _comp.Compare(e, p); if (c < 0) { Swap(i, j); i = j; continue; } else { break; } } } private T Downheap() { var result = _list[0]; var last = _list.Count - 1; Swap(0, last); _list.RemoveAt(last); if (_list.Count == 0) return result; var i = 0; while (true) { if (i == _list.Count - 1) return result; var p = _list[i]; var j = i * 2 + 1; if (j >= _list.Count) return result; if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) > 0) { j++; } if (_comp.Compare(_list[i], _list[j]) > 0) { Swap(i, j); i = j; } else { return result; } } } public MinHeap<T> Copy(Comparison<T> comp = null) { var c = new MinHeap<T>(0, comp); c._list = _list.ToList(); return c; } public MinHeap(List<T> list) { _list = list; _comp = Comparer<T>.Default; } public List<T> GetList() { return _list; } public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } class InputLine { private string[] _inputs; private int _index = 0; InputLine(string input) { _inputs = input.Split(); _index = 0; } public static InputLine Read() { return new InputLine(Console.ReadLine()); } public int NextInt() { return int.Parse(_inputs[_index++]); } public long NextLong() { return long.Parse(_inputs[_index++]); } public double NextDouble() { return double.Parse(_inputs[_index++]); } } public static int GCD(int x, int y) { var a = Math.Max(x, y); var b = x + y - a; while (b != 0) { var c = b; b = a % b; a = c; } return a; } public static long GCD(long x, long y) { var a = Math.Max(x, y); var b = x + y - a; while (b != 0) { var c = b; b = a % b; a = c; } return a; } static long ModPower(long x, long y, long mod) { var bytes = BitConverter.GetBytes(y); var bits = new System.Collections.BitArray(bytes); var max2 = 0; for (int i = bits.Length - 1; i >= 0; i--) { if (bits[i]) { max2 = i; break; } } long result = 1; for (int i = max2; i >= 0; i--) { result = (result * result) % mod; if (bits[i]) { result = (result * x) % mod; } } return result; } static long ModFact(long n, long mod) { long result = 1; for (int i = 1; i <= n; i++) { result = result * i % mod; } return result; } static long ModAdd(long x, long y, long mod) { return ((x % mod) + (y % mod)) % mod; } static long ModMul(long x, long y, long mod) { return ((x % mod) * (y % mod)) % mod; } static long ModDiv(long x, long y, long mod) { //フェルマーの小定理より、a^(-1) = a^(p-2) return ModMul(x, ModPower(y, mod - 2, mod), mod); } static long ModComb(long n, long r, long mod) { long numerator = 1; for (int i = 0; i < r; i++) { numerator = ModMul(numerator, n - i, mod); } long denominator = ModFact(r, mod); return ModDiv(numerator, denominator, mod); } class Graph { private int _size; private List<int>[] _map; public IEnumerable<int> this[int i] { get { if (_map[i] == null) return Enumerable.Empty<int>(); return _map[i]; } } public Graph(int size) { _size = size; _map = new List<int>[size]; } public void Add(int from, int to) { if (_map[from] == null) { _map[from] = new List<int>(); } _map[from].Add(to); } } static List<T> NewList<T>(T template) { return new List<T>(); } static long p1097 = 1000000007; static void Main(string[] args) { //↓ var nm = ReadIntArray(); var n = nm[0]; var m = nm[1]; var aas = ReadIntArray().ToList(); var bcs = ReadObjects(m, x => new { B = x[0], C = x[1] }); aas.Sort(); bcs.Sort((x, y) => -x.C.CompareTo(y.C)); long sum = 0; var i = 0; var isOver = false; for (int j = 0; j < m; j++) { var bc = bcs[j]; var b = bc.B; for (int k = 0; k < b; k++) { if (bc.C <= aas[i]) { isOver = true; break; } sum += bc.C; i++; if (i >= n) { isOver = true; break; } } if (isOver) break; } for (; i < n; i++) { sum += aas[i]; } Console.WriteLine(sum); //↑ } } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
2,855
14
using System; using System.Text; using System.Collections.Generic; using System.Linq; using E = System.Linq.Enumerable; class Program { static Dictionary<int, int> Query; static int H; static int[] A; static void Main(string[] args) { //入力を受け取る int[] NM = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var N = NM[0]; var M = NM[1]; Query = new Dictionary<int, int>(); A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); Array.Sort(A); for (int i = 0; i < M; i++) { var BC = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var B = BC[0]; var C = BC[1]; if (!Query.ContainsKey(C)) { Query.Add(C, B); } else { Query[C] += B; } } // buildMaxHeap(A); var SortedQuery = Query.OrderByDescending((x) => x.Key); var count = 0; foreach (KeyValuePair<int, int> item in SortedQuery) { bool flag = true; // Console.WriteLine("[{0}:{1}]", item.Key, item.Value); for (int j = 0; j < item.Value; j++) { if (count < A.Length && A[count] < item.Key) { A[j] = item.Key; count++; } else { if (j == 0) { flag = false; } break; } } if (!flag) { break; } else { Array.Sort(A); } } long sum = 0; for (int i = 0; i < N; i++) { sum += A[i]; } Console.WriteLine(sum); } }
using System; using System.Text; using System.Collections.Generic; using System.Linq; using E = System.Linq.Enumerable; class Program { static Dictionary<int, int> Query; static int H; static int[] A; static void Main(string[] args) { //入力を受け取る int[] NM = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var N = NM[0]; var M = NM[1]; Query = new Dictionary<int, int>(); A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); Array.Sort(A); for (int i = 0; i < M; i++) { var BC = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var B = BC[0]; var C = BC[1]; if (!Query.ContainsKey(C)) { Query.Add(C, B); } else { Query[C] += B; } } // buildMaxHeap(A); var SortedQuery = Query.OrderByDescending((x) => x.Key); var count = 0; foreach (KeyValuePair<int, int> item in SortedQuery) { bool flag = true; // Console.WriteLine("[{0}:{1}]", item.Key, item.Value); for (int j = 0; j < item.Value; j++) { if (count < A.Length && A[count] < item.Key) { A[count] = item.Key; count++; } else { if (j == 0) { flag = false; } break; } } if (!flag) { break; } } long sum = 0; for (int i = 0; i < N; i++) { sum += A[i]; } Console.WriteLine(sum); } }
[["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["-", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 95], ["-", 0, 210, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25]]
8
421
12
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace ABC127D { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); return; } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; var M = cin.ReadInt; var A = cin.ReadLongArray(N); List<CardStock> cardStocks = new List<CardStock>(); for (int i = 0; i < M; i++) { cardStocks.Add( new CardStock() { Maisu = cin.ReadInt, Kazu = cin.ReadInt }); } cardStocks.Sort((a, b) => b.Kazu - a.Kazu); var changeList = new long[N]; var index = 0; foreach (var cardStock in cardStocks) { for (int i = 0; i < cardStock.Maisu; i++) { changeList[index] = cardStock.Kazu; if (index == N) { break; } else { index++; } } if (index == N) { break; } } Array.Sort(A); for (int i = 0; i < N; i++) { if (A[i] >= changeList[i]) { break; } else { A[i] = changeList[i]; } } long ans = 0; for (int i = 0; i < N; i++) { ans += A[i]; } Console.WriteLine(ans); } public class CardStock { public int Maisu { get; set; } public int Kazu { get; set; } } } public static class Extensions { public static string Reverse(this string sourse) { char[] chrAry = sourse.ToCharArray(); Array.Reverse(chrAry); return new string(chrAry); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public 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.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace ABC127D { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); return; } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; var M = cin.ReadInt; var A = cin.ReadIntArray(N); List<CardStock> cardStocks = new List<CardStock>(); for (int i = 0; i < M; i++) { cardStocks.Add( new CardStock() { Maisu = cin.ReadInt, Kazu = cin.ReadInt }); } cardStocks.Sort((a, b) => b.Kazu - a.Kazu); var changeArray = new int[N]; var index = 0; foreach (var cardStock in cardStocks) { for (long i = 0; i < cardStock.Maisu; i++) { changeArray[index] = cardStock.Kazu; if (index == N - 1) { break; } else { index++; } } if (index == N - 1) { break; } } Array.Sort(A); for (int i = 0; i < N; i++) { if (A[i] >= changeArray[i]) { break; } else { A[i] = changeArray[i]; } } long ans = 0; for (int i = 0; i < N; i++) { ans += (long)A[i]; } Console.WriteLine(ans); } public class CardStock { public int Maisu { get; set; } public int Kazu { get; set; } } } public static class Extensions { public static string Reverse(this string sourse) { char[] chrAry = sourse.ToCharArray(); Array.Reverse(chrAry); return new string(chrAry); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 210, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 210, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["-", 75, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 75, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 0, 24], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 0, 25]]
8
750
21
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtCoder { public class Program { static void Main(string[] args) { int[] vs = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray(); int N = vs[0]; int M = vs[1]; int[] A = Console.ReadLine() .Split() .Select(p => int.Parse(p)) .OrderBy(p => p) .ToArray(); int[][] op = new int [M][]; for (int i = 0; i < M; i++) { op[i] = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray(); } op = op.OrderByDescending(p => p[0]).OrderByDescending(p => p[1]).ToArray(); int index = 0; for (int i = 0; i < M; i++) { int B = op[i][0]; int C = op[i][1]; while (B > 0) { if (A[index] < C) { A[index] = C; index++; B--; } else { break; } } if (index >= N) { break; } } Console.WriteLine(A.Select(p => (long)p).Sum()); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtCoder { public class Program { static void Main(string[] args) { int[] vs = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray(); int N = vs[0]; int M = vs[1]; int[] A = Console.ReadLine() .Split() .Select(p => int.Parse(p)) .OrderBy(p => p) .ToArray(); int[][] op = new int [M][]; for (int i = 0; i < M; i++) { op[i] = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray(); } op = op.OrderByDescending(p => p[0]).OrderByDescending(p => p[1]).ToArray(); int index = 0; for (int i = 0; i < M; i++) { int B = op[i][0]; int C = op[i][1]; while (B > 0) { if (A[index] < C) { A[index] = C; index++; B--; if (index >= N) { break; } } else { break; } } if (index >= N) { break; } } Console.WriteLine(A.Select(p => (long)p).Sum()); } } }
[["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 64, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 46]]
8
326
10
using System; using System.Linq; namespace D___Integer_Cards { class Program { static void Main(string[] args) { var read = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); var N = read[0]; var M = read[1]; var Ai = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); Array.Sort(Ai); var BiCi = new BC[M]; for (int i = 0; i < M; i++) { read = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); BiCi[i] = new BC(); BiCi[i].B = read[0]; BiCi[i].C = read[1]; } BiCi = BiCi.OrderByDescending(BC => BC.C).ToArray(); long count = 0; for (int i = 0; i < M; i++) { for (int j = 0; j < BiCi[i].B; j++) { if (Ai[count] < BiCi[i].C) { Ai[count] = BiCi[i].C; count++; } else { break; } } } Console.WriteLine(Ai.Sum()); Console.ReadKey(); } } public struct BC { public long B { get; set; } public long C { get; set; } } }
using System; using System.Linq; namespace D___Integer_Cards { class Program { static void Main(string[] args) { var read = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); var N = read[0]; var M = read[1]; var Ai = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); Array.Sort(Ai); var BiCi = new BC[M]; for (int i = 0; i < M; i++) { read = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); BiCi[i] = new BC(); BiCi[i].B = read[0]; BiCi[i].C = read[1]; } BiCi = BiCi.OrderByDescending(BC => BC.C).ToArray(); long count = 0; for (int i = 0; i < M; i++) { for (int j = 0; j < BiCi[i].B; j++) { if (count >= N) break; if (Ai[count] < BiCi[i].C) { Ai[count] = BiCi[i].C; count++; } else { break; } } } Console.WriteLine(Ai.Sum()); } } public struct BC { public long B { get; set; } public long C { get; set; } } }
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 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
318
14
using System; using System.Linq; using System.Collections.Generic; class Mondai { static void Main() { var line = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray(); var N = line[0]; var M = line[1]; var A = Console.ReadLine() .Split(' ') .Select(x => Int64.Parse(x)) .OrderBy(x => x) .ToArray(); var list = new List<long[]>(); for (int i = 0; i < M; ++i) { var bc = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray(); list.Add(new long[2] { bc[0], bc[1] }); } var l = list.OrderByDescending(x => x[1]).ThenByDescending(x => x[0]).ToArray(); var index = 0; var array = new long[N]; foreach (var i in l) { for (int j = 0; j < i[0]; j++) { array[index] = i[1]; index++; if (N <= index) break; } } var ans = 0L; for (int i = 0; i < N; ++i) ans += array[i] < A[i] ? A[i] : array[i]; Console.WriteLine(ans); } }
using System; using System.Linq; using System.Collections.Generic; class Mondai { static void Main() { var line = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray(); var N = line[0]; var M = line[1]; var A = Console.ReadLine() .Split(' ') .Select(x => Int64.Parse(x)) .OrderBy(x => x) .ToArray(); var list = new List<long[]>(); for (int i = 0; i < M; ++i) { var bc = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray(); list.Add(new long[2] { bc[0], bc[1] }); } var l = list.OrderByDescending(x => x[1]).ThenByDescending(x => x[0]).ToArray(); var index = 0; var array = new long[N]; foreach (var i in l) { for (int j = 0; j < i[0]; j++) { array[index] = i[1]; index++; if (N <= index) break; } if (N <= index) break; } var ans = 0L; for (int i = 0; i < N; ++i) ans += array[i] < A[i] ? A[i] : array[i]; Console.WriteLine(ans); } }
[["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 24], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 25], ["+", 0, 210, 8, 196, 0, 57, 64, 93, 0, 94], ["+", 0, 210, 8, 196, 0, 57, 64, 93, 0, 35]]
8
336
8
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var line = Console.ReadLine().Split().Select(z => int.Parse(z)).ToArray(); int n = line[0], m = line[1]; var k = Console.ReadLine().Split().Select(z => long.Parse(z)).ToArray(); Array.Sort(k); var array = new int [m][]; for (var i = 0; i < m; i++) { array[i] = Console.ReadLine().Split().Select(z => int.Parse(z)).ToArray(); } array = array.OrderByDescending(o => o[1]).ToArray(); var count = 0; var isLoop = true; for (var i = 0; i < m; i++) { for (var j = count; j < count + array[i][0]; j++) { if (k[j] < array[i][1]) { k[j] = array[i][1]; } else { isLoop = false; break; } } if (!isLoop) break; count += array[i][0]; } Console.WriteLine(k.Sum()); } } }
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var line = Console.ReadLine().Split().Select(z => int.Parse(z)).ToArray(); int n = line[0], m = line[1]; var k = Console.ReadLine().Split().Select(z => long.Parse(z)).ToArray(); Array.Sort(k); var array = new int [m][]; for (var i = 0; i < m; i++) { array[i] = Console.ReadLine().Split().Select(z => int.Parse(z)).ToArray(); } array = array.OrderByDescending(o => o[1]).ToArray(); var count = 0; var isLoop = true; for (var i = 0; i < m; i++) { for (var j = count; j < count + array[i][0]; j++) { if (j >= k.Length || k[j] > array[i][1]) { isLoop = false; break; } k[j] = array[i][1]; } if (!isLoop) break; count += array[i][0]; } Console.WriteLine(k.Sum()); } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["+", 0, 57, 15, 16, 31, 16, 12, 214, 205, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 214, 0, 131], ["+", 0, 57, 15, 16, 31, 16, 12, 214, 141, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 211, 0, 147], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["-", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 75, 196, 0, 1, 0, 11, 12, 211, 0, 147], ["-", 8, 196, 0, 57, 75, 196, 0, 93, 0, 94], ["-", 8, 196, 0, 57, 75, 196, 0, 93, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46]]
8
307
25
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { string[] s1 = Console.ReadLine().Split(' '); int n = int.Parse(s1[0]), m = int.Parse(s1[1]); string[] s2 = Console.ReadLine().Split(' '); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = int.Parse(s2[i]); } Array.Sort(a); Dictionary<int, int> dic = new Dictionary<int, int>(); for (int i = 0; i < m; i++) { string[] s3 = Console.ReadLine().Split(' '); int b = int.Parse(s3[0]), c = int.Parse(s3[1]); if (dic.ContainsKey(c)) dic[c] += b; else dic.Add(c, b); } List<KeyValuePair<int, int>> pairs = new List<KeyValuePair<int, int>>(dic); pairs.Sort((x, y) => y.Key - x.Key); int point = 0; foreach (KeyValuePair<int, int> p in pairs) { // onsole.Error.WriteLine(p.Key + " " + p.Value); for (int i = 0; i < p.Value; i++) { if (a[point] < p.Key) { a[point] = p.Key; point++; } else { long ans = 0; foreach (int j in a) { // Console.Error.WriteLine(j); ans += (long)j; } Console.WriteLine(ans); return; } } } { long ans = 0; foreach (int j in a) { // Console.Error.WriteLine(j); ans += (long)j; } Console.WriteLine(ans); } } } // mcs Main.cs // mono Main.exe
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { string[] s1 = Console.ReadLine().Split(' '); int n = int.Parse(s1[0]), m = int.Parse(s1[1]); string[] s2 = Console.ReadLine().Split(' '); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = int.Parse(s2[i]); } Array.Sort(a); Dictionary<int, int> dic = new Dictionary<int, int>(); for (int i = 0; i < m; i++) { string[] s3 = Console.ReadLine().Split(' '); int b = int.Parse(s3[0]), c = int.Parse(s3[1]); if (dic.ContainsKey(c)) dic[c] += b; else dic.Add(c, b); } List<KeyValuePair<int, int>> pairs = new List<KeyValuePair<int, int>>(dic); pairs.Sort((x, y) => y.Key - x.Key); int point = 0; foreach (KeyValuePair<int, int> p in pairs) { // onsole.Error.WriteLine(p.Key + " " + p.Value); for (int i = 0; i < p.Value; i++) { if (a[point] < p.Key) { a[point] = p.Key; point++; if (point >= n) { long ans = 0; foreach (int j in a) { // Console.Error.WriteLine(j); ans += (long)j; } Console.WriteLine(ans); return; } } else { long ans = 0; foreach (int j in a) { // Console.Error.WriteLine(j); ans += (long)j; } Console.WriteLine(ans); return; } } } { long ans = 0; foreach (int j in a) { // Console.Error.WriteLine(j); ans += (long)j; } Console.WriteLine(ans); } } } // mcs Main.cs // mono Main.exe
[["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 197, 0, 198, 39, 199], ["+", 64, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 64, 196, 0, 57, 64, 196, 0, 197, 0, 35], ["+", 64, 196, 0, 57, 64, 196, 0, 210, 0, 266], ["+", 64, 196, 0, 57, 64, 196, 0, 210, 0, 24], ["+", 64, 196, 0, 57, 64, 196, 0, 210, 39, 199], ["+", 64, 196, 0, 57, 64, 196, 0, 210, 31, 22], ["+", 64, 196, 0, 57, 64, 196, 0, 210, 0, 267], ["+", 64, 196, 0, 57, 64, 196, 0, 210, 12, 22], ["+", 64, 196, 0, 57, 64, 196, 0, 210, 0, 25], ["+", 0, 57, 64, 196, 0, 210, 8, 196, 0, 45], ["+", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 0, 24], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 0, 25], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 51, 22], ["+", 64, 196, 0, 210, 8, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 210, 8, 196, 0, 46], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 64, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
417
38
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; namespace AtCodeeeer { class AtCOOOOOOOOOOOder { static void Main(string[] args) { long[] s = ReadLine().Split(' ').Select(long.Parse).ToArray(); long N = s[0]; long M = s[1]; List<long> ls = new List<long>(); ls.AddRange(ReadLine().Split(' ').Select(long.Parse).ToArray()); Dictionary<long, long> input = new Dictionary<long, long>(); for (int i = 0; i < M; i++) { long[] inp = ReadLine().Split(' ').Select(long.Parse).ToArray(); if (input.ContainsKey(inp[1])) { input[inp[1]] += inp[0]; } else { input.Add(inp[1], inp[0]); } } ls.Sort(); var SortedInput = input.OrderByDescending(x => x.Key); int j = 0; // lsの見る場所 foreach (var item in SortedInput) { long Keycnt = 0; while (item.Value - Keycnt > 0 && ls.Count > j) { if (ls[j] < item.Key && ls.Count > j) { ls[j] = item.Key; Keycnt++; } else { break; } j++; } if (ls[j] >= item.Key) { break; } } long ans = ls.Sum(); WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; namespace AtCodeeeer { class AtCOOOOOOOOOOOder { static void Main(string[] args) { long[] s = ReadLine().Split(' ').Select(long.Parse).ToArray(); long N = s[0]; long M = s[1]; List<long> ls = new List<long>(); ls.AddRange(ReadLine().Split(' ').Select(long.Parse).ToArray()); Dictionary<long, long> input = new Dictionary<long, long>(); for (int i = 0; i < M; i++) { long[] inp = ReadLine().Split(' ').Select(long.Parse).ToArray(); if (input.ContainsKey(inp[1])) { input[inp[1]] += inp[0]; } else { input.Add(inp[1], inp[0]); } } ls.Sort(); var SortedInput = input.OrderByDescending(x => x.Key); int j = 0; // lsの見る場所 foreach (var item in SortedInput) { long Valcnt = 0; while (item.Value - Valcnt > 0 && ls.Count > j) { if (ls[j] < item.Key && ls.Count > j) { ls[j] = item.Key; Valcnt++; } else { break; } j++; } if (ls.Count > j) { if (ls[j] >= item.Key) { break; } } } long ans = ls.Sum(); WriteLine(ans); } } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 52, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 52, 15, 16, 31, 16, 31, 16, 12, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 25], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
367
16
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { var inputs = Console.ReadLine().Split(' '); var N = int.Parse(inputs[0]); var M = int.Parse(inputs[1]); var A = new long[N]; inputs = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { A[i] = long.Parse(inputs[i]); } var bcList = new List<BC>(M); for (int i = 0; i < M; i++) { inputs = Console.ReadLine().Split(' '); var b = int.Parse(inputs[0]); var c = long.Parse(inputs[1]); var newBc = new BC(b, c); bcList.Add(newBc); } bcList = bcList.OrderByDescending(bcd => bcd.C).ToList(); A = A.OrderBy(a => a).ToArray(); int bcIndex = 0; var bc = bcList[bcIndex]; var cCount = 0; long sum = 0; for (int i = 0; i < N; i++) { var a = A[i]; sum += a; if (bc.C >= a && cCount < bc.B) { sum -= a; sum += bc.C; cCount++; } if (cCount >= bc.B) { bc = bcList[++bcIndex]; cCount = 0; } } Console.WriteLine(sum); } struct BC { internal int B; internal long C; internal BC(int B, long C) { this.B = B; this.C = C; } } }
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { var inputs = Console.ReadLine().Split(' '); var N = int.Parse(inputs[0]); var M = int.Parse(inputs[1]); var A = new long[N]; inputs = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { A[i] = long.Parse(inputs[i]); } var bcList = new List<BC>(M); for (int i = 0; i < M; i++) { inputs = Console.ReadLine().Split(' '); var b = int.Parse(inputs[0]); var c = long.Parse(inputs[1]); var newBc = new BC(b, c); bcList.Add(newBc); } bcList = bcList.OrderByDescending(bcd => bcd.C).ToList(); A = A.OrderBy(a => a).ToArray(); int bcIndex = 0; var bc = bcList[bcIndex]; var cCount = 0; long sum = 0; for (int i = 0; i < N; i++) { var a = A[i]; sum += a; if (bc.C >= a && cCount < bc.B && bcIndex <= bcList.Count - 1) { sum -= a; sum += bc.C; cCount++; } if (cCount >= bc.B) { bcIndex++; if (bcIndex <= bcList.Count - 1) { bc = bcList[bcIndex]; cCount = 0; } } } Console.WriteLine(sum); } struct BC { internal int B; internal long C; internal BC(int B, long C) { this.B = B; this.C = C; } } }
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 15, 16, 12, 16, 12, 16, 31, 214, 205, 22], ["+", 15, 16, 12, 16, 12, 16, 31, 214, 0, 131], ["+", 15, 16, 12, 16, 12, 16, 31, 214, 141, 22], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 205, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 0, 131], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 141, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 12, 204, 206, 207, 0, 28, 0, 241, 0, 29], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
390
24
using System; using System.Collections.Generic; class ABC_127_D { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int M = int.Parse(input[1]); int[] A = new int[N]; int[] newA = new int[N]; string[] input2 = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { A[i] = int.Parse(input2[i]); newA[i] = 0; } List<Pair> list = new List<Pair>(); for (int i = 0; i < M; i++) { string[] input3 = Console.ReadLine().Split(' '); int b = int.Parse(input3[0]); int c = int.Parse(input3[1]); list.Add(new Pair(b, c)); } Array.Sort(A); list.Sort((a, b) => b.C - a.C); int cnt = 0; for (int i = 0; i < list.Count; i++) { Pair p = list[i]; for (int j = 0; j < p.B; j++) { newA[cnt] = p.C; cnt++; } if (cnt >= N) break; } for (int i = 0; i < N; i++) { A[i] = Math.Max(A[i], newA[i]); } long sum = 0; for (int i = 0; i < N; i++) { sum += A[i]; } Console.WriteLine(sum); } class Pair { public Pair(int b, int c) { B = b; C = c; } public int B; public int C; } }
using System; using System.Collections.Generic; class ABC_127_D { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int M = int.Parse(input[1]); int[] A = new int[N]; int[] newA = new int[N]; string[] input2 = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { A[i] = int.Parse(input2[i]); newA[i] = 0; } List<Pair> list = new List<Pair>(); for (int i = 0; i < M; i++) { string[] input3 = Console.ReadLine().Split(' '); int b = int.Parse(input3[0]); int c = int.Parse(input3[1]); list.Add(new Pair(b, c)); } Array.Sort(A); list.Sort((a, b) => b.C - a.C); int cnt = 0; for (int i = 0; i < list.Count && cnt < N; i++) { Pair p = list[i]; for (int j = 0; j < p.B && cnt < N; j++) { newA[cnt] = p.C; cnt++; } } for (int i = 0; i < N; i++) { A[i] = Math.Max(A[i], newA[i]); } long sum = 0; for (int i = 0; i < N; i++) { sum += A[i]; } Console.WriteLine(sum); } class Pair { public Pair(int b, int c) { B = b; C = c; } public int B; public int C; } }
[["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 98], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 98], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94], ["-", 0, 7, 8, 196, 0, 57, 64, 93, 0, 35]]
8
431
16
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Collections; class Program { static void Main() { long[] nm = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray(); long N = nm[0]; long M = nm[1]; List<long> A = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToList(); var bcList = Enumerable.Range(0, (int)M) .Select(n => Console.ReadLine() .Split(' ') .Select(s => long.Parse(s)) .ToArray()) .Select(arr => new { B = arr[0], C = arr[1] }) .ToList(); bcList.Sort((bc1, bc2) => -Math.Sign(bc1.C - bc2.C)); A.Sort((num1, num2) => -Math.Sign(num1 - num2)); int count = 0; int AIdx = 0; long ans = 0; foreach (var c in bcList.SelectMany( bc => Enumerable.Repeat(bc.C, (int)bc.B))) { while (A[AIdx] >= c) { ans += A[AIdx]; AIdx++; count++; if (count == N) { Console.WriteLine(ans); return; } } ans += c; count++; if (count == N) { Console.WriteLine(ans); return; } } Console.WriteLine(ans); return; } } static class MathUtil { public static T Max<T>(params T[] datas) { return datas.Max(); } public static T Min<T>(params T[] datas) { return datas.Min(); } public static IEnumerable<IEnumerable<int>> GetPermutation(int n) { if (n == 0) { yield return Single(0); yield break; } for (int i = 0; i <= n; i++) { foreach (var x in GetPermutation(n - 1)) { yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1)); } } } private static IEnumerable<int> Single(int x) { yield return x; } public static IEnumerable<int> EnumeratePrimeNumbers() { List<int> primes = new List<int>() { 2 }; yield return 2; for (int i = 3; i < int.MaxValue; i++) { bool isPrime = true; int Sqrt = (int)Math.Sqrt(i) + 1; foreach (var prime in primes) { if (prime > Sqrt) { break; } if (i % prime == 0) { isPrime = false; break; } } if (isPrime) { primes.Add(i); yield return i; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Collections; class Program { static void Main() { long[] nm = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray(); long N = nm[0]; long M = nm[1]; List<long> A = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToList(); var bcList = Enumerable.Range(0, (int)M) .Select(n => Console.ReadLine() .Split(' ') .Select(s => long.Parse(s)) .ToArray()) .Select(arr => new { B = arr[0], C = arr[1] }) .ToList(); bcList.Sort((bc1, bc2) => -Math.Sign(bc1.C - bc2.C)); A.Sort((num1, num2) => -Math.Sign(num1 - num2)); int count = 0; int AIdx = 0; long ans = 0; foreach (var c in bcList.SelectMany( bc => Enumerable.Repeat(bc.C, (int)bc.B))) { while (A[AIdx] >= c) { ans += A[AIdx]; AIdx++; count++; if (count == N) { Console.WriteLine(ans); return; } } ans += c; count++; if (count == N) { Console.WriteLine(ans); return; } } while (count < N) { ans += A[AIdx]; AIdx++; count++; } Console.WriteLine(ans); return; } } static class MathUtil { public static T Max<T>(params T[] datas) { return datas.Max(); } public static T Min<T>(params T[] datas) { return datas.Min(); } public static IEnumerable<IEnumerable<int>> GetPermutation(int n) { if (n == 0) { yield return Single(0); yield break; } for (int i = 0; i <= n; i++) { foreach (var x in GetPermutation(n - 1)) { yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1)); } } } private static IEnumerable<int> Single(int x) { yield return x; } public static IEnumerable<int> EnumeratePrimeNumbers() { List<int> primes = new List<int>() { 2 }; yield return 2; for (int i = 3; i < int.MaxValue; i++) { bool isPrime = true; int Sqrt = (int)Math.Sqrt(i) + 1; foreach (var prime in primes) { if (prime > Sqrt) { break; } if (i % prime == 0) { isPrime = false; break; } } if (isPrime) { primes.Add(i); yield return i; } } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 89], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 24], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 25], ["+", 0, 195, 8, 196, 0, 52, 8, 196, 0, 45], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 52, 8, 196, 0, 46]]
8
656
21
using System; namespace AtCoder { class Program { static void Main(string[] args) { long ans = 0; string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); int M = int.Parse(s[1]); s = Console.ReadLine().Split(' '); int[] X = new int[N]; for (int i = 0; i < N; i++) { X[i] = int.Parse(s[i]); } Array.Sort(X); int[][] L = new int [M][]; for (int i = 0; i < M; i++) { s = Console.ReadLine().Split(' '); L[i] = new int[2]; L[i][0] = int.Parse(s[0]); L[i][1] = int.Parse(s[1]); } OrgComparer comp = new OrgComparer(); Array.Sort(L, comp); int counter = 0; for (int i = 0; i < M; i++) { for (int j = 0; j < L[i][0]; j++) { if (X[counter] < L[i][1]) { X[counter] = L[i][1]; counter++; } if (counter > N) break; } if (counter > N) break; } for (int i = 0; i < N; i++) { ans += X[i]; } Console.WriteLine(ans.ToString()); } } public class OrgComparer : System.Collections.IComparer { //配列2項目目で昇順 public int Compare(object x, object y) { int[] X = (int[])x; int[] Y = (int[])y; if (X[1] > Y[1]) return -1; if (X[1] < Y[1]) return 1; return 0; } } }
using System; namespace AtCoder { class Program { static void Main(string[] args) { long ans = 0; string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); int M = int.Parse(s[1]); s = Console.ReadLine().Split(' '); int[] X = new int[N]; for (int i = 0; i < N; i++) { X[i] = int.Parse(s[i]); } Array.Sort(X); int[][] L = new int [M][]; for (int i = 0; i < M; i++) { s = Console.ReadLine().Split(' '); L[i] = new int[2]; L[i][0] = int.Parse(s[0]); L[i][1] = int.Parse(s[1]); } OrgComparer comp = new OrgComparer(); Array.Sort(L, comp); int counter = 0; for (int i = 0; i < M; i++) { for (int j = 0; j < L[i][0]; j++) { if (X[counter] < L[i][1]) { X[counter] = L[i][1]; counter++; } else counter = N; if (counter == N) break; } if (counter == N) break; } for (int i = 0; i < N; i++) { ans += X[i]; } Console.WriteLine(ans.ToString()); } } public class OrgComparer : System.Collections.IComparer { //配列2項目目で昇順 public int Compare(object x, object y) { int[] X = (int[])x; int[] Y = (int[])y; if (X[1] > Y[1]) return -1; if (X[1] < Y[1]) return 1; return 0; } } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 1, 0, 11, 31, 22], ["+", 0, 57, 75, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 57, 75, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 75, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60]]
8
453
9
using System; using System.Collections.Generic; namespace 私が灰コーダーです { class Inonoa { static void Main() { string[] n_m = Console.ReadLine().Split(); int n = int.Parse(n_m[0]); int m = int.Parse(n_m[1]); string[] sa = Console.ReadLine().Split(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = int.Parse(sa[i]); } Array.Sort(a); int[][] bc = new int [m][]; for (int i = 0; i < m; i++) { string[] b_c = Console.ReadLine().Split(); bc[i] = new int[] { int.Parse(b_c[0]), int.Parse(b_c[1]) }; } Array.Sort(bc, Compare); bool owari = false; int k = 0; for (int i = bc.Length - 1; i > -1; i--) { for (int j = 0; j < bc[i][0]; j++) { if (a[k] > bc[i][1]) { owari = true; break; } a[k] = bc[i][1]; k++; } if (owari) { break; } } long ans = 0; for (int i = 0; i < a.Length; i++) { ans += a[i]; } Console.WriteLine(ans); } static int Compare(int[] a, int[] b) { if (a[1] > b[1]) { return 1; } if (a[1] < b[1]) { return -1; } return 0; } } }
using System; using System.Collections.Generic; namespace 私が灰コーダーです { class Inonoa { static void Main() { string[] n_m = Console.ReadLine().Split(); int n = int.Parse(n_m[0]); int m = int.Parse(n_m[1]); string[] sa = Console.ReadLine().Split(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = int.Parse(sa[i]); } Array.Sort(a); int[][] bc = new int [m][]; for (int i = 0; i < m; i++) { string[] b_c = Console.ReadLine().Split(); bc[i] = new int[] { int.Parse(b_c[0]), int.Parse(b_c[1]) }; } Array.Sort(bc, Compare); bool owari = false; int k = 0; for (int i = bc.Length - 1; i > -1; i--) { for (int j = 0; j < bc[i][0]; j++) { if (k > a.Length - 1) { owari = true; break; } if (a[k] > bc[i][1]) { owari = true; break; } a[k] = bc[i][1]; k++; } if (owari) { break; } } long ans = 0; for (int i = 0; i < a.Length; i++) { ans += a[i]; } Console.WriteLine(ans); } static int Compare(int[] a, int[] b) { if (a[1] > b[1]) { return 1; } if (a[1] < b[1]) { return -1; } return 0; } } }
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 205, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 0, 131], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24]]
8
410
18
using System; using System.Collections.Generic; using System.Linq; using static Input; public class Hello { public static void Main() { string S = NextString(); int A = int.Parse(S.Substring(0, 2)); int B = int.Parse(S.Substring(2)); if (1 <= A && 1 <= B && A <= 12 && B <= 12) Console.WriteLine("AMBIGUOUS"); else if (1 <= A && 1 <= B && A <= 12) Console.WriteLine("MMYY"); else if (1 <= A && 1 <= B && B <= 12) Console.WriteLine("YYMM"); else Console.WriteLine("NA"); // Console.WriteLine(A + " " + B); } } public class Input { private static Queue<string> queue = new Queue<string>(); private static void Confirm() { if (queue.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(queue.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(queue.Dequeue()); } public static string NextString() { Confirm(); return queue.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(queue.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using static Input; public class Hello { public static void Main() { string S = NextString(); int A = int.Parse(S.Substring(0, 2)); int B = int.Parse(S.Substring(2)); if (1 <= A && 1 <= B && A <= 12 && B <= 12) Console.WriteLine("AMBIGUOUS"); else if (1 <= A && A <= 12) Console.WriteLine("MMYY"); else if (1 <= B && B <= 12) Console.WriteLine("YYMM"); else Console.WriteLine("NA"); // Console.WriteLine(A + " " + B); } } public class Input { private static Queue<string> queue = new Queue<string>(); private static void Confirm() { if (queue.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(queue.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(queue.Dequeue()); } public static string NextString() { Confirm(); return queue.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(queue.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } }
[["-", 75, 57, 15, 16, 31, 16, 12, 16, 31, 203], ["-", 75, 57, 15, 16, 31, 16, 12, 16, 17, 19], ["-", 75, 57, 15, 16, 31, 16, 12, 16, 12, 22], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 98], ["-", 75, 57, 15, 16, 31, 16, 31, 16, 31, 203], ["-", 75, 57, 15, 16, 31, 16, 31, 16, 17, 19], ["-", 75, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["-", 75, 57, 75, 57, 15, 16, 31, 16, 17, 98]]
8
443
8
using System; using System.Text.RegularExpressions; namespace C_DiceAndCoin { class Program { static void Main(string[] args) { double[] numlist = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384 }; string[] tmplist = Regex.Split(Console.ReadLine(), @"\s+"); int num; double Ans = 0; for (double tmpnum = 1; tmpnum <= Convert.ToDouble(tmplist[0]); ++tmpnum) { num = Convert.ToInt32(Math.Ceiling( Math.Log10(Convert.ToDouble(tmplist[1]) / tmpnum) / Math.Log10(2))); if (num < 0) num = 0; if (num > 14) { num = 14; } Ans += 1.0 / numlist[num]; } Console.WriteLine(Ans / Convert.ToDouble(tmplist[0])); } } }
using System; using System.Text.RegularExpressions; namespace C_DiceAndCoin { class Program { static void Main(string[] args) { double[] numlist = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072 }; string[] tmplist = Regex.Split(Console.ReadLine(), @"\s+"); int num; double Ans = 0; for (double tmpnum = 1; tmpnum <= Convert.ToDouble(tmplist[0]); ++tmpnum) { num = Convert.ToInt32(Math.Ceiling( Math.Log10(Convert.ToDouble(tmplist[1]) / tmpnum) / Math.Log10(2))); if (num < 0) num = 0; Ans += 1.0 / numlist[num]; } Console.WriteLine(Ans / Convert.ToDouble(tmplist[0])); } } }
[["+", 0, 198, 0, 200, 0, 212, 0, 229, 0, 21], ["+", 0, 198, 0, 200, 0, 212, 0, 229, 0, 203], ["-", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
200
18
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Collections; class Program { static void Main() { int[] nk = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int N = nk[0]; int K = nk[1]; double ans = 0; for (int i = 1; i <= N; i++) { int n = 0; if (K < i) { n = 0; } else { n = (int)Math.Ceiling(Math.Log(K / i, 2)); } ans += 1 / Math.Pow(2, n); } ans /= N; Console.WriteLine(ans); } class MyNum { int bunbo; int bunshi; void Add(MyNum n) { this.bunbo = this.bunbo * n.bunbo; this.bunshi = this.bunshi * n.bunbo + n.bunshi * this.bunbo; } } static long calcGCD(long num1, long num2) { if (num1 < num2) { var tmp = num1; num1 = num2; num2 = tmp; } while (true) { long res; long div = Math.DivRem(num1, num2, out res); if (res == 0) { return num2; } else { num1 = num2; num2 = res; } } } } static class MathUtil { public static T Max<T>(params T[] datas) { return datas.Max(); } public static T Min<T>(params T[] datas) { return datas.Min(); } public static IEnumerable<IEnumerable<int>> GetPermutation(int n) { if (n == 0) { yield return Single(0); yield break; } for (int i = 0; i <= n; i++) { foreach (var x in GetPermutation(n - 1)) { yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1)); } } } private static IEnumerable<int> Single(int x) { yield return x; } public static IEnumerable<int> EnumeratePrimeNumbers() { List<int> primes = new List<int>() { 2 }; yield return 2; for (int i = 3; i < int.MaxValue; i++) { bool isPrime = true; int Sqrt = (int)Math.Sqrt(i) + 1; foreach (var prime in primes) { if (prime > Sqrt) { break; } if (i % prime == 0) { isPrime = false; break; } } if (isPrime) { primes.Add(i); yield return i; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Collections; class Program { static void Main() { int[] nk = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int N = nk[0]; int K = nk[1]; double ans = 0; for (int i = 1; i <= N; i++) { int n = 0; if (K < i) { n = 0; } else { n = (int)Math.Ceiling(Math.Log(K / (double)i, 2)); } ans += 1 / Math.Pow(2, n); } ans /= N; Console.WriteLine(ans.ToString("F15")); } class MyNum { int bunbo; int bunshi; void Add(MyNum n) { this.bunbo = this.bunbo * n.bunbo; this.bunshi = this.bunshi * n.bunbo + n.bunshi * this.bunbo; } } static long calcGCD(long num1, long num2) { if (num1 < num2) { var tmp = num1; num1 = num2; num2 = tmp; } while (true) { long res; long div = Math.DivRem(num1, num2, out res); if (res == 0) { return num2; } else { num1 = num2; num2 = res; } } } } static class MathUtil { public static T Max<T>(params T[] datas) { return datas.Max(); } public static T Min<T>(params T[] datas) { return datas.Min(); } public static IEnumerable<IEnumerable<int>> GetPermutation(int n) { if (n == 0) { yield return Single(0); yield break; } for (int i = 0; i <= n; i++) { foreach (var x in GetPermutation(n - 1)) { yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1)); } } } private static IEnumerable<int> Single(int x) { yield return x; } public static IEnumerable<int> EnumeratePrimeNumbers() { List<int> primes = new List<int>() { 2 }; yield return 2; for (int i = 3; i < int.MaxValue; i++) { bool isPrime = true; int Sqrt = (int)Math.Sqrt(i) + 1; foreach (var prime in primes) { if (prime > Sqrt) { break; } if (i % prime == 0) { isPrime = false; break; } } if (isPrime) { primes.Add(i); yield return i; } } } }
[["+", 3, 4, 0, 28, 0, 16, 12, 74, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 12, 74, 39, 199], ["+", 3, 4, 0, 28, 0, 16, 12, 74, 0, 25], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
596
10
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int k = int.Parse(input[1]); double res = 0; for (int i = 1; i <= n; i++) { int count = 1; while (i * Math.Pow(2, count) < k) count++; res += 1 / (Math.Pow(2, count) * n); } Console.WriteLine(res); } }
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int k = int.Parse(input[1]); double res = 0; for (int i = 1; i <= n; i++) { if (i >= k) { res += 1 / (double)n; continue; } int count = 1; while (i * Math.Pow(2, count) < k) count++; res += 1 / (Math.Pow(2, count) * n); } Console.WriteLine(res); } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 31, 203], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["+", 0, 1, 0, 11, 12, 16, 12, 74, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 12, 74, 39, 199], ["+", 0, 1, 0, 11, 12, 16, 12, 74, 0, 25], ["+", 0, 1, 0, 11, 12, 16, 12, 74, 51, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
130
19
using System; using System.Linq; class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); int K = int.Parse(s[1]); double ans = 0; int iter = 1; while (N + 1 > iter) { int pow = 0; int num = iter; while (K > num) { pow++; num *= 2; } ans += 1 / Math.Pow(2, pow); iter++; } if (N > K) ans += N - K; Console.WriteLine(ans / N); } }
using System; class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); int K = int.Parse(s[1]); double ans = 0; int iter = 1; while (N + 1 > iter) { int pow = 0; int num = iter; while (K > num) { pow++; num *= 2; } ans += 1 / Math.Pow(2, pow); iter++; } Console.WriteLine(ans / N); } }
[["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["-", 0, 57, 64, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 57, 64, 1, 0, 11, 12, 16, 31, 22], ["-", 0, 57, 64, 1, 0, 11, 12, 16, 17, 33], ["-", 0, 57, 64, 1, 0, 11, 12, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
8
149
17
using System; using System.Text; namespace ABC126 { class Program { static int Main(string[] args) { ProblemC(); return 0; } static void ProblemC() { string[] input = System.Console.ReadLine().Split(' '); double N = int.Parse(input[0]); double K = int.Parse(input[1]); double victory; victory = 0; for (int i = 1; i < N + 1; i++) { //コインを振らずとも勝てる if (i > K) { victory += 1 / i; } //コインで数回連続で勝つ必要がある else { int tmp; tmp = (int)Math.Ceiling(Math.Log(K / i, 2)); double a, b; a = (double)(1 / N); b = (double)((1 / (Math.Pow(2, tmp)))); victory += a * b; } } Console.WriteLine(victory); } } }
using System; using System.Text; namespace ABC126 { class Program { static int Main(string[] args) { ProblemC(); return 0; } static void ProblemC() { string[] input = System.Console.ReadLine().Split(' '); double N = int.Parse(input[0]); double K = int.Parse(input[1]); double victory; victory = 0; for (int i = 1; i < N + 1; i++) { //コインを振らずとも勝てる if (i > K) { double a = 1 / N; victory += a; } //コインで数回連続で勝つ必要がある else { int tmp; tmp = (int)Math.Ceiling(Math.Log(K / i, 2)); double a, b; a = (double)(1 / N); b = (double)((1 / (Math.Pow(2, tmp)))); victory += a * b; } } Console.WriteLine(victory); } } }
[["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 64, 196, 0, 197, 0, 198, 39, 199], ["+", 64, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 197, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22]]
8
206
11
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); double kaku = 0; for (int i = 1; i <= a; i++) { int n = i; int sum = 0; while (n < b) { n *= 2; sum++; } kaku += (1 / a) * Math.Pow(0.5, sum); } Console.WriteLine(kaku); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); double kaku = 0; for (int i = 1; i <= a; i++) { int n = i; int sum = 0; while (n < b) { n *= 2; sum++; } kaku += Math.Pow(0.5, sum) / a; } Console.WriteLine(kaku); } }
[["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 31, 203], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 17, 85], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 12, 22], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
8
156
8
using System; using System.Linq; namespace abc126 { class Program { static void Main(string[] args) { var tmp = Console.ReadLine() .Split(' ') .Select(_ => int.Parse((string)_)) .ToArray(); // var tmp = new int[] {10000, 5}; // var tmp = new int[] {3, 10}; var n = tmp[0]; var k = tmp[1]; var kratio = 1; var krate = 1.0; var total = 0.0; var inversen = 1.0 / n; var firstmaxNext = n; for (var ik = 0; ik < k; ik++) { var firstmax = firstmaxNext; var firstmin = Math.Min((k + kratio - 1) / kratio, firstmax); if (firstmin < 1) { break; } if (firstmin <= n) { firstmax = Math.Min(firstmax, n); var rate = krate * (firstmax - firstmin + 1) * inversen; total += rate; } firstmaxNext = firstmin - 1; if (firstmaxNext < 1) { break; } krate *= 0.5; kratio *= 2; } Console.WriteLine(total); } } }
using System; using System.Linq; namespace abc126 { class Program { static void Main(string[] args) { var tmp = Console.ReadLine() .Split(' ') .Select(_ => int.Parse((string)_)) .ToArray(); // var tmp = new int[] {10000, 5}; // var tmp = new int[] {3, 10}; var n = tmp[0]; var k = tmp[1]; var kratio = 1; var krate = 1.0; var total = 0.0; var inversen = 1.0 / n; var firstmaxNext = n; for (var ik = 0; ik < k; ik++) { var firstmax = firstmaxNext; var firstmin = (k + kratio - 1) / kratio; if (firstmin < 1) { break; } if (firstmin <= n) { firstmax = Math.Min(firstmax, n); var rate = krate * (firstmax - firstmin + 1) * inversen; total += rate; } firstmaxNext = firstmin - 1; if (firstmaxNext < 1) { break; } krate *= 0.5; kratio *= 2; } Console.WriteLine(total); } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["-", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
8
227
7
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; namespace AtCorder { public class Program { public static void Main(string[] args) { var l = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var n = l[0]; var k = l[1]; var result = 0.0; for (int dice = 1; dice <= n; dice++) { if (dice >= k) { result += 1.0 / n; } else { var logD = Ceiling(Log(k / dice, 2)); result += 1.0 / n * Pow(0.5, logD); } } Console.WriteLine(result); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; namespace AtCorder { public class Program { public static void Main(string[] args) { var l = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var n = l[0]; var k = l[1]; var result = 0.0; for (int dice = 1; dice <= n; dice++) { double pow; if (dice >= k) { pow = 0; } else { var log = Log((double)k / dice, 2); pow = Ceiling(log); } result += 1.0 / n * Pow(0.5, pow); } Console.WriteLine($"{result:F12}"); } } }
[["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 31, 250], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["-", 75, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 75, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 74, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 74, 39, 199], ["+", 3, 4, 0, 28, 0, 16, 31, 74, 0, 25], ["+", 8, 196, 0, 57, 75, 196, 0, 197, 0, 35], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46], ["-", 12, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 12, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 0, 213, 3, 4, 0, 28, 0, 283, 0, 295], ["+", 3, 4, 0, 28, 0, 283, 0, 284, 0, 45], ["+", 0, 28, 0, 283, 0, 284, 0, 298, 0, 102], ["+", 3, 4, 0, 28, 0, 283, 0, 284, 0, 46], ["+", 0, 213, 3, 4, 0, 28, 0, 283, 0, 62]]
8
172
34
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace ConsoleApp1 { using static Util; internal class Program { static void Main(string[] args) { var s = ReadIntArray(); var n = s[0]; var k = s[1]; var res = 0.0; for (var i = 0; i < n; i++) { var now = k / (i + 1.0); var l = Math.Ceiling(Math.Log(now, 2)); var c = Math.Pow(1 / 2.0, l); res += (c / n); ; } Console.WriteLine(res); #if DEBUG Console.Read(); #endif } public static bool IsDate(string s, string format) { DateTime d = DateTime.MinValue; return DateTime.TryParseExact( s, format, null, System.Globalization.DateTimeStyles.None, out d); } } public static class Util { public static long[] ReadLongArray() => Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); public static int[] ReadIntArray() => Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); public static long ReadLong() => long.Parse(Console.ReadLine()); public static long ReadInt() => int.Parse(Console.ReadLine()); } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace ConsoleApp1 { using static Util; internal class Program { static void Main(string[] args) { var s = ReadIntArray(); var n = s[0]; var k = s[1]; var res = 0.0; for (var i = 0; i < n; i++) { if (i + 1 < k) { var now = k / (i + 1.0); var l = Math.Ceiling(Math.Log(now, 2)); var c = Math.Pow(1 / 2.0, l); res += (c / n); } else { res += (1.0 / n); } } Console.WriteLine(res.ToString("0.00000000000000")); #if DEBUG Console.Read(); #endif } public static bool IsDate(string s, string format) { DateTime d = DateTime.MinValue; return DateTime.TryParseExact( s, format, null, System.Globalization.DateTimeStyles.None, out d); } } public static class Util { public static long[] ReadLongArray() => Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); public static int[] ReadIntArray() => Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); public static long ReadLong() => long.Parse(Console.ReadLine()); public static long ReadInt() => int.Parse(Console.ReadLine()); } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 75, 196, 0, 1, 0, 11, 12, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 23, 0, 16, 31, 250], ["+", 0, 1, 0, 11, 12, 23, 0, 16, 17, 85], ["+", 0, 1, 0, 11, 12, 23, 0, 16, 12, 22], ["+", 75, 196, 0, 1, 0, 11, 12, 23, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
318
27
using System; using System.Collections.Generic; using static AtCoderer.Exter; using static System.Console; using static System.Math; using System.Linq; namespace AtCoderer { public class App { public static void Main(string[] args) { double Perc = 0; var r = readarr; double n = r[0], k = r[1]; for (int i = 1; i <= n; i++) { Perc += Pow(0.5, Ceiling(Log(k / i, 2))) / n; } cout = Perc; Console.ReadKey(); } } public static class Exter { public static void rep(int loop, Action<int> act) { for (int i = 0; i < loop; i++) act(i); } public static int ToInt(this string v) => int.Parse(v); public static int Max(params int[] p) => p.Max(); public static long Max(params long[] p) => p.Max(); public static int Min(params int[] p) => p.Min(); public static long Min(params long[] p) => p.Min(); public static int Gcd(int a, int b) => a > b? GcdRecursive(a, b) : GcdRecursive(b, a); private static int GcdRecursive(int a, int b) => b == 0 ? a : GcdRecursive(b, a % b); public static object cout { set { Console.Write(value.ToString()); Console.WriteLine(); } } public static void ToCout<t>(this IEnumerable<t> v) { cout = string.Join(",", v); } public static int[] readarr { get { preadarr = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); return preadarr; } } public static int[] preadarr; } }
using System; using System.Collections.Generic; using static AtCoderer.Exter; using static System.Console; using static System.Math; using System.Linq; namespace AtCoderer { public class App { public static void Main(string[] args) { double Perc = 0; var r = readarr; double n = r[0], k = r[1]; for (int i = 1; i <= n; i++) { int p = 0; for (int j = i; j < k; j *= 2) { p++; } Perc += Pow(0.5, p); } cout = Perc / n; Console.ReadKey(); } } public static class Exter { public static void rep(int loop, Action<int> act) { for (int i = 0; i < loop; i++) act(i); } public static int ToInt(this string v) => int.Parse(v); public static int Max(params int[] p) => p.Max(); public static long Max(params long[] p) => p.Max(); public static int Min(params int[] p) => p.Min(); public static long Min(params long[] p) => p.Min(); public static int Gcd(int a, int b) => a > b? GcdRecursive(a, b) : GcdRecursive(b, a); private static int GcdRecursive(int a, int b) => b == 0 ? a : GcdRecursive(b, a % b); public static object cout { set { Console.Write(value.ToString()); Console.WriteLine(); } } public static void ToCout<t>(this IEnumerable<t> v) { cout = string.Join(",", v); } public static int[] readarr { get { preadarr = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); return preadarr; } } public static int[] preadarr; } }
[["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 88], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 24], ["+", 0, 7, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 7, 26, 11, 31, 22], ["+", 8, 196, 0, 7, 26, 11, 0, 202, 0, 108], ["+", 0, 7, 8, 196, 0, 7, 26, 11, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 25], ["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 11, 12, 16, 31, 213, 3, 4, 0, 21], ["-", 31, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 11, 12, 16, 31, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
8
418
41
using AtCoderBeginnerContest126.Questions; using AtCoderBeginnerContest126.Extensions; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace AtCoderBeginnerContest126.Questions { public class QuestionE : AtCoderQuestionBase { public override IEnumerable<object> Solve(TextReader inputStream) { var nm = inputStream.ReadIntArray(); var n = nm[0]; var m = nm[1]; var cards = Enumerable.Range(0, n) .Select(i => new UnionFindNode<int>(i)) .ToArray(); for (int i = 0; i < m; i++) { var xyz = inputStream.ReadIntArray(); var x = xyz[0] - 1; var y = xyz[1] - 1; cards[x].Unite(cards[y]); } var roots = new HashSet<int>(); foreach (var card in cards) { roots.Add(card.Parent.Item); } yield return roots.Count; } // See https://kumikomiya.com/competitive-programming-with-c-sharp/ public class UnionFindNode<T> { private int _height; // rootのときのみ有効 private int _groupSize; // 同上 private UnionFindNode<T> _parent; public T Item { get; } public UnionFindNode<T> Parent => _parent; public UnionFindNode(T item) { _height = 0; _groupSize = 1; _parent = this; Item = item; } private UnionFindNode<T> FindRoot() { if (_parent != this) // not ref equals { var root = _parent.FindRoot(); _parent = root; } return _parent; } public int GetGroupSize() => FindRoot()._groupSize; public void Unite(UnionFindNode<T> other) { var thisRoot = this.FindRoot(); var otherRoot = other.FindRoot(); if (thisRoot == otherRoot) { return; } if (thisRoot._height < otherRoot._height) { thisRoot._parent = otherRoot; otherRoot._groupSize += thisRoot._groupSize; otherRoot._height = Math.Max(thisRoot._height + 1, otherRoot._height); } else { otherRoot._parent = thisRoot; thisRoot._groupSize += otherRoot._groupSize; thisRoot._height = Math.Max(otherRoot._height + 1, thisRoot._height); } } public bool IsInSameGroup(UnionFindNode<T> other) => this.FindRoot() == other.FindRoot(); public override string ToString() => $"{Item} root:{FindRoot().Item}"; } } } namespace AtCoderBeginnerContest126 { class Program { static void Main(string[] args) { IAtCoderQuestion question = new QuestionE(); // 問題に合わせて書き換え var answers = question.Solve(Console.In); foreach (var answer in answers) { Console.WriteLine(answer); } } } } #region Base Classes namespace AtCoderBeginnerContest126.Questions { public interface IAtCoderQuestion { IEnumerable<object> Solve(string input); IEnumerable<object> Solve(TextReader inputStream); } public abstract class AtCoderQuestionBase : IAtCoderQuestion { public IEnumerable<object> Solve(string input) { var stream = new MemoryStream(Encoding.Unicode.GetBytes(input)); var reader = new StreamReader(stream, Encoding.Unicode); return Solve(reader); } public abstract IEnumerable<object> Solve(TextReader inputStream); } } #endregion #region Extensions namespace AtCoderBeginnerContest126.Extensions { internal static class TextReaderExtensions { internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader)); internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader)); internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader)); internal static string ReadString(this TextReader reader) => reader.ReadLine(); internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray(); internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray(); internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray(); internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator); } } #endregion
using AtCoderBeginnerContest126.Questions; using AtCoderBeginnerContest126.Extensions; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace AtCoderBeginnerContest126.Questions { public class QuestionE : AtCoderQuestionBase { public override IEnumerable<object> Solve(TextReader inputStream) { var nm = inputStream.ReadIntArray(); var n = nm[0]; var m = nm[1]; var cards = Enumerable.Range(0, n) .Select(_ => new UnionFindNode<bool>(false)) .ToArray(); for (int i = 0; i < m; i++) { var xyz = inputStream.ReadIntArray(); var x = xyz[0] - 1; var y = xyz[1] - 1; cards[x].Unite(cards[y]); } var roots = new HashSet<UnionFindNode<bool>>(); foreach (var card in cards) { roots.Add(card.FindRoot()); } yield return roots.Count; } // See https://kumikomiya.com/competitive-programming-with-c-sharp/ public class UnionFindNode<T> { private int _height; // rootのときのみ有効 private int _groupSize; // 同上 private UnionFindNode<T> _parent; public T Item { get; set; } public UnionFindNode(T item) { _height = 0; _groupSize = 1; _parent = this; Item = item; } public UnionFindNode<T> FindRoot() { if (_parent != this) // not ref equals { var root = _parent.FindRoot(); _parent = root; } return _parent; } public int GetGroupSize() => FindRoot()._groupSize; public void Unite(UnionFindNode<T> other) { var thisRoot = this.FindRoot(); var otherRoot = other.FindRoot(); if (thisRoot == otherRoot) { return; } if (thisRoot._height < otherRoot._height) { thisRoot._parent = otherRoot; otherRoot._groupSize += thisRoot._groupSize; otherRoot._height = Math.Max(thisRoot._height + 1, otherRoot._height); } else { otherRoot._parent = thisRoot; thisRoot._groupSize += otherRoot._groupSize; thisRoot._height = Math.Max(otherRoot._height + 1, thisRoot._height); } } public bool IsInSameGroup(UnionFindNode<T> other) => this.FindRoot() == other.FindRoot(); public override string ToString() => $"{Item} root:{FindRoot().Item}"; } } } namespace AtCoderBeginnerContest126 { class Program { static void Main(string[] args) { IAtCoderQuestion question = new QuestionE(); // 問題に合わせて書き換え var answers = question.Solve(Console.In); foreach (var answer in answers) { Console.WriteLine(answer); } } } } #region Base Classes namespace AtCoderBeginnerContest126.Questions { public interface IAtCoderQuestion { IEnumerable<object> Solve(string input); IEnumerable<object> Solve(TextReader inputStream); } public abstract class AtCoderQuestionBase : IAtCoderQuestion { public IEnumerable<object> Solve(string input) { var stream = new MemoryStream(Encoding.Unicode.GetBytes(input)); var reader = new StreamReader(stream, Encoding.Unicode); return Solve(reader); } public abstract IEnumerable<object> Solve(TextReader inputStream); } } #endregion #region Extensions namespace AtCoderBeginnerContest126.Extensions { internal static class TextReaderExtensions { internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader)); internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader)); internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader)); internal static string ReadString(this TextReader reader) => reader.ReadLine(); internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray(); internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray(); internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray(); internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator); } } #endregion
[["-", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["-", 0, 218, 8, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 218, 8, 230, 39, 236, 237, 238, 0, 199], ["-", 0, 218, 8, 230, 3, 4, 0, 28, 0, 22], ["+", 8, 230, 3, 4, 0, 28, 0, 211, 0, 147], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 230, 39, 236, 237, 238, 0, 236, 141, 22], ["+", 39, 236, 237, 238, 0, 236, 237, 238, 0, 18], ["+", 39, 236, 237, 238, 0, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 47], ["-", 3, 4, 0, 28, 0, 214, 205, 214, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 0, 235, 8, 201, 0, 277, 278, 279, 0, 46], ["-", 0, 235, 8, 201, 0, 277, 0, 251, 0, 259], ["-", 0, 235, 8, 201, 0, 277, 39, 236, 141, 22], ["-", 8, 201, 0, 277, 39, 236, 237, 238, 0, 18], ["-", 8, 201, 0, 277, 39, 236, 237, 238, 0, 22], ["-", 8, 201, 0, 277, 39, 236, 237, 238, 0, 47], ["-", 8, 201, 0, 235, 8, 201, 0, 277, 141, 22], ["-", 0, 235, 8, 201, 0, 277, 51, 306, 0, 221], ["-", 0, 235, 8, 201, 0, 277, 51, 306, 0, 22], ["+", 8, 201, 0, 277, 278, 279, 0, 280, 141, 282], ["+", 0, 235, 8, 201, 0, 277, 278, 279, 0, 46], ["-", 0, 235, 8, 201, 0, 195, 0, 251, 0, 261], ["+", 0, 235, 8, 201, 0, 195, 0, 251, 0, 259]]
8
882
30
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Numerics; using static System.Math; using static System.Array; using static AtCoder.Tool; using static AtCoder.CalcL; namespace AtCoder { class AC { const int MOD = 1000000007; // const int MOD = 998244353; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dI = { 0, 1, 0, -1 }; static readonly int[] dJ = { 1, 0, -1, 0 }; static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>> G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); var cin = new Scanner(); int N = int.Parse(Console.ReadLine()); for (var i = 0; i < N; i++) G.Add(new List<int>()); for (var i = 0; i < N - 1; i++) { var p = cin.ReadSplitInt(); int a = --p[0]; int b = --p[1]; G[a].Add(b); G[b].Add(a); } Func<int, int, int, int> dfs = null; var d = new int[N]; Initialize(ref d, 0); dfs = (v, prev, dist) => { d[v] = dist; foreach (var nx in G[v]) { if (nx == prev) continue; dfs(nx, v, dist + 1); } return 0; }; dfs(0, -1, 0); int mx = d.Max(); int st = -1; for (var i = 0; i < N; i++) { if (d[i] == mx) { st = i; break; } } Initialize(ref d, 0); dfs(st, -1, 0); int dia = d.Max(); // Console.WriteLine(dia); var dp = new bool[dia + 1]; dp[0] = true; dp[1] = false; for (var i = 2; i <= dia; i++) { dp[i] = (!dp[i - 1] || !dp[i - 2]); } // Console.WriteLine(string.Join(",", dp)); Console.WriteLine(dp[dia] ? "First" : "Second"); // Console.Out.Flush(); } struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } } public class UnionFind { private int[] parent; private int[] rank; private int[] size; public UnionFind(int n) { parent = new int[n]; rank = new int[n]; size = new int[n]; for (var i = 0; i < n; i++) { parent[i] = i; rank[i] = 0; size[i] = 1; } } public int Root(int x) { return parent[x] == x ? x : parent[x] = Root(parent[x]); } public bool SameRoot(int x, int y) { return Root(x) == Root(y); } public void Unite(int x, int y) { x = Root(x); y = Root(y); if (x == y) { return; } if (rank[x] < rank[y]) { parent[x] = y; size[y] += size[x]; size[x] = 0; } else { parent[y] = x; if (rank[x] == rank[y]) { rank[x]++; } size[x] += size[y]; size[y] = 0; } } public int SizeOf(int x) { return size[Root(x)]; } } public class Scanner { public int[] ReadSplitInt() { return ConvertAll(Console.ReadLine().Split(), int.Parse); } public long[] ReadSplitLong() { return ConvertAll(Console.ReadLine().Split(), long.Parse); } public double[] ReadSplit_Double() { return ConvertAll(Console.ReadLine().Split(), double.Parse); } } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { for (var i = 0; i < array.Length; i++) { array[i] = initialvalue; } } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } static public long LPow(int a, int b) { return (long)Pow(a, b); } } static public class CalcI { public static int Gcd(int a, int b) { if (a * b == 0) { return Max(a, b); } return a % b == 0 ? b : Gcd(b, a % b); } public static int Lcm(int a, int b) { int g = Gcd(a, b); return a / g * b; } public static int Ceil(int n, int div) { return (n + div - 1) / div; } } static public class CalcL { public static long Gcd(long a, long b) { if (a * b == 0) { return Max(a, b); } return a % b == 0 ? b : Gcd(b, a % b); } public static long Lcm(long a, long b) { long g = Gcd(a, b); return a / g * b; } public static long Ceil(long n, long div) { return (n + div - 1) / div; } } class Modulo { private int M; private readonly long[] m_facs; public long Mul(long a, long b) { return ((a * b) % M); } public Modulo(long n, int m) { M = m; m_facs = new long[n + 1]; m_facs[0] = 1; for (long i = 1; i <= n; ++i) { m_facs[i] = Mul(m_facs[i - 1], i); } } public long Fac(long n) { return m_facs[n]; } public long Pow(long a, long m) { switch (m) { case 0: return 1L; case 1: return a; default: long p1 = Pow(a, m / 2); long p2 = Mul(p1, p1); return ((m % 2) == 0) ? p2 : Mul(p2, a); } } public long Div(long a, long b) { return Mul(a, Pow(b, M - 2)); } public long Ncr(long n, long r) { if (n < r) { return 0; } if (n == r) { return 1; } long res = Fac(n); res = Div(res, Fac(r)); res = Div(res, Fac(n - r)); return res; } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Numerics; using static System.Math; using static System.Array; using static AtCoder.Tool; using static AtCoder.CalcL; namespace AtCoder { class AC { const int MOD = 1000000007; // const int MOD = 998244353; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dI = { 0, 1, 0, -1 }; static readonly int[] dJ = { 1, 0, -1, 0 }; static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>> G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); var cin = new Scanner(); int N = int.Parse(Console.ReadLine()); if (N == 1) { Console.WriteLine("First"); return; } for (var i = 0; i < N; i++) G.Add(new List<int>()); for (var i = 0; i < N - 1; i++) { var p = cin.ReadSplitInt(); int a = --p[0]; int b = --p[1]; G[a].Add(b); G[b].Add(a); } Func<int, int, int, int> dfs = null; var d = new int[N]; Initialize(ref d, 0); dfs = (v, prev, dist) => { d[v] = dist; foreach (var nx in G[v]) { if (nx == prev) continue; dfs(nx, v, dist + 1); } return 0; }; dfs(0, -1, 0); int mx = d.Max(); int st = -1; for (var i = 0; i < N; i++) { if (d[i] == mx) { st = i; break; } } Initialize(ref d, 0); dfs(st, -1, 0); int dia = d.Max(); // Console.WriteLine(dia); var dp = new bool[dia + 1]; dp[0] = true; dp[1] = false; for (var i = 2; i <= dia; i++) { dp[i] = (!dp[i - 1] || !dp[i - 2]); } // Console.WriteLine(string.Join(",", dp)); Console.WriteLine(dp[dia] ? "First" : "Second"); // Console.Out.Flush(); } struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } } public class UnionFind { private int[] parent; private int[] rank; private int[] size; public UnionFind(int n) { parent = new int[n]; rank = new int[n]; size = new int[n]; for (var i = 0; i < n; i++) { parent[i] = i; rank[i] = 0; size[i] = 1; } } public int Root(int x) { return parent[x] == x ? x : parent[x] = Root(parent[x]); } public bool SameRoot(int x, int y) { return Root(x) == Root(y); } public void Unite(int x, int y) { x = Root(x); y = Root(y); if (x == y) { return; } if (rank[x] < rank[y]) { parent[x] = y; size[y] += size[x]; size[x] = 0; } else { parent[y] = x; if (rank[x] == rank[y]) { rank[x]++; } size[x] += size[y]; size[y] = 0; } } public int SizeOf(int x) { return size[Root(x)]; } } public class Scanner { public int[] ReadSplitInt() { return ConvertAll(Console.ReadLine().Split(), int.Parse); } public long[] ReadSplitLong() { return ConvertAll(Console.ReadLine().Split(), long.Parse); } public double[] ReadSplit_Double() { return ConvertAll(Console.ReadLine().Split(), double.Parse); } } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { for (var i = 0; i < array.Length; i++) { array[i] = initialvalue; } } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } static public long LPow(int a, int b) { return (long)Pow(a, b); } } static public class CalcI { public static int Gcd(int a, int b) { if (a * b == 0) { return Max(a, b); } return a % b == 0 ? b : Gcd(b, a % b); } public static int Lcm(int a, int b) { int g = Gcd(a, b); return a / g * b; } public static int Ceil(int n, int div) { return (n + div - 1) / div; } } static public class CalcL { public static long Gcd(long a, long b) { if (a * b == 0) { return Max(a, b); } return a % b == 0 ? b : Gcd(b, a % b); } public static long Lcm(long a, long b) { long g = Gcd(a, b); return a / g * b; } public static long Ceil(long n, long div) { return (n + div - 1) / div; } } class Modulo { private int M; private readonly long[] m_facs; public long Mul(long a, long b) { return ((a * b) % M); } public Modulo(long n, int m) { M = m; m_facs = new long[n + 1]; m_facs[0] = 1; for (long i = 1; i <= n; ++i) { m_facs[i] = Mul(m_facs[i - 1], i); } } public long Fac(long n) { return m_facs[n]; } public long Pow(long a, long m) { switch (m) { case 0: return 1L; case 1: return a; default: long p1 = Pow(a, m / 2); long p2 = Mul(p1, p1); return ((m % 2) == 0) ? p2 : Mul(p2, a); } } public long Div(long a, long b) { return Mul(a, Pow(b, M - 2)); } public long Ncr(long n, long r) { if (n < r) { return 0; } if (n == r) { return 1; } long res = Fac(n); res = Div(res, Fac(r)); res = Div(res, Fac(n - r)); return res; } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
1,664
19
using System; using System.Collections.Generic; using System.Linq; using System.IO; using SB = System.Text.StringBuilder; // using System.Threading.Tasks; // using System.Text.RegularExpressions; // using System.Globalization; // using System.Diagnostics; using static System.Console; using System.Numerics; using static System.Math; using pair = Pair<int, int>; class Program { static void Main() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().solve(); Out.Flush(); } readonly Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑ readonly int mod = 1000000007; readonly int dom = 998244353; bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; } void solve() { var G = new Tree(); var T = G.Input(cin.nextint); var L = G.Diameter(T); if ((L + 2) % 3 == 0) { WriteLine("Second"); } else { WriteLine("First"); } } } class Tree { public List<int>[] Input(int n, int indexed = 1) { Scanner cin = new Scanner(); var ret = new List<int>[n]; for (int i = 0; i < n - 1; i++) { int a = cin.nextint - indexed; int b = cin.nextint - indexed; ret[a].Add(b); ret[b].Add(a); } return ret; } public int BFS(List<int>[] T, int s, out int[] dist) { int n = T.Length; dist = new int[n]; for (int i = 0; i < dist.Length; i++) dist[i] = -1; var Q = new Queue<int>(); dist[s] = 0; Q.Enqueue(s); int len = 0, id = s; while (Q.Count > 0) { var u = Q.Dequeue(); foreach (var v in T[u]) { if (dist[v] >= 0) continue; dist[v] = dist[u] + 1; if (len < dist[v]) { len = dist[v]; id = v; } Q.Enqueue(v); } } return id; } public int Diameter(List<int>[] T) { int[] dist; var far = BFS(T, BFS(T, 0, out dist), out dist); return dist[far]; } } static class Ex { public static void join<T>(this IEnumerable<T> values, string sep = " ") => WriteLine(string.Join(sep, values)); public static string concat<T>(this IEnumerable<T> values) => string.Concat(values); public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); } public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) < 0) low = mid + 1; else high = mid; } return low; } public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) <= 0) low = mid + 1; else high = mid; } return low; } } class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T f; public U s; public Pair(T f, U s) { this.f = f; this.s = s; } public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s); public override string ToString() => $"{f} {s}"; } class Scanner { string[] s; int i; readonly char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan => ReadLine().Split(); public int[] scanint => Array.ConvertAll(scan, int.Parse); public long[] scanlong => Array.ConvertAll(scan, long.Parse); public double[] scandouble => Array.ConvertAll(scan, double.Parse); public string next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next; } } public int nextint => int.Parse(next); public long nextlong => long.Parse(next); public double nextdouble => double.Parse(next); }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using SB = System.Text.StringBuilder; // using System.Threading.Tasks; // using System.Text.RegularExpressions; // using System.Globalization; // using System.Diagnostics; using static System.Console; using System.Numerics; using static System.Math; using pair = Pair<int, int>; class Program { static void Main() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().solve(); Out.Flush(); } readonly Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑ readonly int mod = 1000000007; readonly int dom = 998244353; bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; } void solve() { var G = new Tree(); var T = G.Input(cin.nextint); var L = G.Diameter(T); if ((L + 2) % 3 == 0) { WriteLine("Second"); } else { WriteLine("First"); } } } class Tree { public List<int>[] Input(int n, int indexed = 1) { Scanner cin = new Scanner(); var ret = new List<int>[n]; for (int i = 0; i < ret.Length; i++) ret[i] = new List<int>(); for (int i = 0; i < n - 1; i++) { int a = cin.nextint - indexed; int b = cin.nextint - indexed; ret[a].Add(b); ret[b].Add(a); } return ret; } public int BFS(List<int>[] T, int s, out int[] dist) { int n = T.Length; dist = new int[n]; for (int i = 0; i < dist.Length; i++) dist[i] = -1; var Q = new Queue<int>(); dist[s] = 0; Q.Enqueue(s); int len = 0, id = s; while (Q.Count > 0) { var u = Q.Dequeue(); foreach (var v in T[u]) { if (dist[v] >= 0) continue; dist[v] = dist[u] + 1; if (len < dist[v]) { len = dist[v]; id = v; } Q.Enqueue(v); } } return id; } public int Diameter(List<int>[] T) { int[] dist; var far = BFS(T, BFS(T, 0, out dist), out dist); return dist[far]; } } static class Ex { public static void join<T>(this IEnumerable<T> values, string sep = " ") => WriteLine(string.Join(sep, values)); public static string concat<T>(this IEnumerable<T> values) => string.Concat(values); public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); } public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) < 0) low = mid + 1; else high = mid; } return low; } public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) <= 0) low = mid + 1; else high = mid; } return low; } } class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T f; public U s; public Pair(T f, U s) { this.f = f; this.s = s; } public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s); public override string ToString() => $"{f} {s}"; } class Scanner { string[] s; int i; readonly char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan => ReadLine().Split(); public int[] scanint => Array.ConvertAll(scan, int.Parse); public long[] scanlong => Array.ConvertAll(scan, long.Parse); public double[] scandouble => Array.ConvertAll(scan, double.Parse); public string next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next; } } public int nextint => int.Parse(next); public long nextlong => long.Parse(next); public double nextdouble => double.Parse(next); }
[["+", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["+", 0, 7, 8, 1, 0, 11, 31, 204, 205, 22], ["+", 8, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 8, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 7, 8, 1, 0, 11, 12, 230, 0, 228], ["+", 8, 1, 0, 11, 12, 230, 39, 236, 141, 22], ["+", 0, 11, 12, 230, 39, 236, 237, 238, 0, 18], ["+", 0, 11, 12, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 11, 12, 230, 39, 236, 237, 238, 0, 47], ["+", 8, 1, 0, 11, 12, 230, 3, 4, 0, 24], ["+", 8, 1, 0, 11, 12, 230, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 7, 8, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18]]
8
1,239
29
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[,] A = new int[N, 2]; for (var i = 0; i < N - 1; i++) { string[] str = Console.ReadLine().Split(); A[i, 0] = int.Parse(str[0]); A[i, 1] = int.Parse(str[1]); } var list = new List<int>[N]; for (var i = 0; i < N; i++) { list[i] = new List<int>(); } for (var i = 0; i < N - 1; i++) { list[A[i, 0] - 1].Add(A[i, 1] - 1); list[A[i, 1] - 1].Add(A[i, 0] - 1); } var list1 = new List<int>(); list1.Add(0); int[] C = new int[N]; C[0] = 1; int maxi = -1; int max = 0; while (list1.Count > 0) { var list2 = new List<int>(list1); list1.Clear(); foreach (int a in list2) { foreach (int b in list[a]) { if (C[b] == 0) { C[b] = C[a] + 1; if (C[b] > max) { max = C[b]; maxi = b; } list1.Add(b); } } } } C = new int[N]; list1.Add(maxi); C[maxi] = 1; maxi = -1; max = 0; while (list1.Count > 0) { var list2 = new List<int>(list1); list1.Clear(); foreach (int a in list2) { foreach (int b in list[a]) { if (C[b] == 0) { C[b] = C[a] + 1; if (C[b] > max) { max = C[b]; maxi = b; } list1.Add(b); } } } } if (max % 3 == 2) { Console.WriteLine("Second"); } else { Console.WriteLine("First"); } } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); if (N == 1) { Console.WriteLine("First"); } else { int[,] A = new int[N, 2]; for (var i = 0; i < N - 1; i++) { string[] str = Console.ReadLine().Split(); A[i, 0] = int.Parse(str[0]); A[i, 1] = int.Parse(str[1]); } var list = new List<int>[N]; for (var i = 0; i < N; i++) { list[i] = new List<int>(); } for (var i = 0; i < N - 1; i++) { list[A[i, 0] - 1].Add(A[i, 1] - 1); list[A[i, 1] - 1].Add(A[i, 0] - 1); } var list1 = new List<int>(); list1.Add(0); int[] C = new int[N]; C[0] = 1; int maxi = -1; int max = 0; while (list1.Count > 0) { var list2 = new List<int>(list1); list1.Clear(); foreach (int a in list2) { foreach (int b in list[a]) { if (C[b] == 0) { C[b] = C[a] + 1; if (C[b] > max) { max = C[b]; maxi = b; } list1.Add(b); } } } } C = new int[N]; list1.Add(maxi); C[maxi] = 1; maxi = -1; max = 0; while (list1.Count > 0) { var list2 = new List<int>(list1); list1.Clear(); foreach (int a in list2) { foreach (int b in list[a]) { if (C[b] == 0) { C[b] = C[a] + 1; if (C[b] > max) { max = C[b]; maxi = b; } list1.Add(b); } } } } if (max % 3 == 2) { Console.WriteLine("Second"); } else { Console.WriteLine("First"); } } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 57, 75, 196, 0, 46]]
8
538
20
using System; using System.Linq; using System.Collections.Generic; using Debug = System.Diagnostics.Trace; using SB = System.Text.StringBuilder; using System.Numerics; using static System.Math; using Number = System.Int64; namespace Program { public class Solver { Random rnd = new Random(0); public void Solve() { var n = ri; var G = Enumerate(n, x => new List<int>()); foreach (var i in Rep(n - 1)) { var u = ri - 1; var v = ri - 1; G[u].Add(v); G[v].Add(u); } Func<int, int, KeyValuePair<int, int>> dfs = null; dfs = (prev, cur) => { var p = cur; var d = 0; foreach (var t in G[cur]) { if (t != prev) { var res = dfs(cur, t); if (res.Value + 1 > d) { p = t; d = res.Value + 1; } } } return new KeyValuePair<int, int>(p, d); }; var s = dfs(-1, 0).Key; var D = dfs(-1, s).Value + 1; Debug.WriteLine(D); var dp = new bool[n + 5]; dp[1] = true; dp[2] = false; for (int i = 3; i <= D; i++) { if (dp[i - 1] == false) dp[i] = true; if (dp[i - 2] == false) dp[i] = true; } if (dp[D]) Console.WriteLine("First"); else Console.WriteLine("Second"); } const long INF = 1L << 60; int ri => sc.Integer(); long rl => sc.Long(); double rd => sc.Double(); string rs => sc.Scan(); public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static IEnumerable<int> Rep(int n) => Enumerable.Range(0, n); static IEnumerable<int> RRep(int n) => Enumerable.Range(0, n).Reverse(); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < a.Length; ++i) a[i] = f(i); return a; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { Console.SetOut(new Program.IO.Printer( Console.OpenStandardOutput()) { AutoFlush = true }); var solver = new Program.Solver(); solver.Solve(); Console.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { public override IFormatProvider FormatProvider => CultureInfo.InvariantCulture; public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } } #endregion
using System; using System.Linq; using System.Collections.Generic; using Debug = System.Diagnostics.Trace; using SB = System.Text.StringBuilder; using System.Numerics; using static System.Math; using Number = System.Int64; namespace Program { public class Solver { Random rnd = new Random(0); public void Solve() { var n = ri; var G = Enumerate(n, x => new List<int>()); foreach (var i in Rep(n - 1)) { var u = ri - 1; var v = ri - 1; G[u].Add(v); G[v].Add(u); } Func<int, int, KeyValuePair<int, int>> dfs = null; dfs = (prev, cur) => { var p = cur; var d = 0; foreach (var t in G[cur]) { if (t != prev) { var res = dfs(cur, t); if (res.Value + 1 > d) { p = res.Key; d = res.Value + 1; } } } Debug.WriteLine($"{cur} {p} {d}"); return new KeyValuePair<int, int>(p, d); }; var s = dfs(-1, 0).Key; var D = dfs(-1, s).Value + 1; Debug.WriteLine(D); var dp = new bool[n + 5]; dp[1] = true; dp[2] = false; for (int i = 3; i <= D; i++) { if (dp[i - 1] == false) dp[i] = true; if (dp[i - 2] == false) dp[i] = true; } if (dp[D]) Console.WriteLine("First"); else Console.WriteLine("Second"); } const long INF = 1L << 60; int ri => sc.Integer(); long rl => sc.Long(); double rd => sc.Double(); string rs => sc.Scan(); public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static IEnumerable<int> Rep(int n) => Enumerable.Range(0, n); static IEnumerable<int> RRep(int n) => Enumerable.Range(0, n).Reverse(); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < a.Length; ++i) a[i] = f(i); return a; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { Console.SetOut(new Program.IO.Printer( Console.OpenStandardOutput()) { AutoFlush = true }); var solver = new Program.Solver(); solver.Solve(); Console.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { public override IFormatProvider FormatProvider => CultureInfo.InvariantCulture; public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } } #endregion
[["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 11, 12, 214, 141, 22], ["+", 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], ["+", 0, 213, 3, 4, 0, 28, 0, 283, 0, 295], ["+", 3, 4, 0, 28, 0, 283, 0, 284, 0, 45], ["+", 3, 4, 0, 28, 0, 283, 0, 284, 0, 22], ["+", 3, 4, 0, 28, 0, 283, 0, 284, 0, 46], ["+", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296], ["+", 0, 213, 3, 4, 0, 28, 0, 283, 0, 62], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 11, 12, 218, 8, 196, 0, 1, 0, 35]]
8
1,118
23
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; static class Program { const int mod = (int)1e9 + 7; static List<int>[] li; static bool[] b; static int kr = 0, kc = 0; static void Main() { Sc sc = new Sc(); int n = sc.I; li = new List<int>[n + 1]; b = new bool[n + 1]; for (int i = 1; i <= n; i++) { li[i] = new List<int>(); } for (int i = 0; i < n - 1; i++) { int[] e = sc.Ia; li[e[0]].Add(e[1]); li[e[1]].Add(e[0]); } Fu(1, 1, 0); b = new bool[n + 1]; kr = 0; Fu(kc, kc, 0); bool[] h = new bool[kr + 2]; h[1] = true; for (int i = 3; i <= kr + 1; i++) { if (!h[i - 1] || !h[i - 2]) { h[i] = true; } } Console.WriteLine("{0}", h[kr + 1] ? "First" : "Second"); } static void Fu(int a, int g, int k) { b[a] = true; if (kr < k) { kr = k; kc = a; } for (int i = 0; i < li[a].Count; i++) { if (!b[li[a][i]]) { Fu(li[a][i], g, k + 1); } } } } public class Sc { private string[] a; private int n = -1, m = 0; public int I { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(new string[] { " ", " ", " " }, StringSplitOptions.RemoveEmptyEntries); } n++; return int.Parse(a[n]); } } public long L { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(new string[] { " ", " ", " " }, StringSplitOptions.RemoveEmptyEntries); } n++; return long.Parse(a[n]); } } public double D { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(new string[] { " ", " ", " " }, StringSplitOptions.RemoveEmptyEntries); } n++; return double.Parse(a[n]); } } public string S { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(new string[] { " ", " ", " " }, StringSplitOptions.RemoveEmptyEntries); } n++; return a[n]; } } public int[] Ia { get { if (n != -1 && n != a.Length - 1) { m = n; n = -1; return Array.ConvertAll(a.Skip(m + 1).ToArray(), int.Parse); } return Array.ConvertAll( Console.ReadLine().Split(new string[] { " ", " ", " " }, StringSplitOptions.RemoveEmptyEntries), int.Parse); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0") .Split(new string[] { " ", " ", " " }, StringSplitOptions.RemoveEmptyEntries), int.Parse); } } public long[] La { get { return Array.ConvertAll( Console.ReadLine().Split(new string[] { " ", " ", " " }, StringSplitOptions.RemoveEmptyEntries), long.Parse); } } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0") .Split(new string[] { " ", " ", " " }, StringSplitOptions.RemoveEmptyEntries), long.Parse); } } public double[] Da { get { return Array.ConvertAll( Console.ReadLine().Split(new string[] { " ", " ", " " }, StringSplitOptions.RemoveEmptyEntries), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(new string[] { " ", " ", " " }, StringSplitOptions.RemoveEmptyEntries); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; static class Program { const int mod = (int)1e9 + 7; static List<int>[] li; static bool[] b; static int kr = 0, kc = 0; static void Main() { Sc sc = new Sc(); int n = sc.I; if (n == 1) { Console.WriteLine("First"); return; } li = new List<int>[n + 1]; b = new bool[n + 1]; for (int i = 1; i <= n; i++) { li[i] = new List<int>(); } for (int i = 0; i < n - 1; i++) { int[] e = sc.Ia; li[e[0]].Add(e[1]); li[e[1]].Add(e[0]); } Fu(1, 1, 0); b = new bool[n + 1]; kr = 0; Fu(kc, kc, 0); bool[] h = new bool[kr + 2]; h[1] = true; for (int i = 3; i <= kr + 1; i++) { if (!h[i - 1] || !h[i - 2]) { h[i] = true; } } Console.WriteLine("{0}", h[kr + 1] ? "First" : "Second"); } static void Fu(int a, int g, int k) { b[a] = true; if (kr < k) { kr = k; kc = a; } for (int i = 0; i < li[a].Count; i++) { if (!b[li[a][i]]) { Fu(li[a][i], g, k + 1); } } } } public class Sc { private string[] a; private int n = -1, m = 0; public int I { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(new string[] { " ", " ", " " }, StringSplitOptions.RemoveEmptyEntries); } n++; return int.Parse(a[n]); } } public long L { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(new string[] { " ", " ", " " }, StringSplitOptions.RemoveEmptyEntries); } n++; return long.Parse(a[n]); } } public double D { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(new string[] { " ", " ", " " }, StringSplitOptions.RemoveEmptyEntries); } n++; return double.Parse(a[n]); } } public string S { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(new string[] { " ", " ", " " }, StringSplitOptions.RemoveEmptyEntries); } n++; return a[n]; } } public int[] Ia { get { if (n != -1 && n != a.Length - 1) { m = n; n = -1; return Array.ConvertAll(a.Skip(m + 1).ToArray(), int.Parse); } return Array.ConvertAll( Console.ReadLine().Split(new string[] { " ", " ", " " }, StringSplitOptions.RemoveEmptyEntries), int.Parse); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0") .Split(new string[] { " ", " ", " " }, StringSplitOptions.RemoveEmptyEntries), int.Parse); } } public long[] La { get { return Array.ConvertAll( Console.ReadLine().Split(new string[] { " ", " ", " " }, StringSplitOptions.RemoveEmptyEntries), long.Parse); } } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0") .Split(new string[] { " ", " ", " " }, StringSplitOptions.RemoveEmptyEntries), long.Parse); } } public double[] Da { get { return Array.ConvertAll( Console.ReadLine().Split(new string[] { " ", " ", " " }, StringSplitOptions.RemoveEmptyEntries), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(new string[] { " ", " ", " " }, StringSplitOptions.RemoveEmptyEntries); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
1,103
19
using System; using System.Linq; using System.Collections.Generic; namespace Sample { class Sample { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] str = Console.ReadLine().Split(' '); int A = int.Parse(str[0]); int B = int.Parse(str[1]); int C = int.Parse(str[2]); Console.WriteLine(C / A * B); } } }
using System; using System.Linq; using System.Collections.Generic; namespace Sample { class Sample { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int A = int.Parse(str[0]); int B = int.Parse(str[1]); int C = int.Parse(str[2]); Console.WriteLine(C / A * B); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35]]
8
116
14
using System; class plogram { static void Main() { string[] array = Console.ReadLine().Split(' '); var A = double.Parse(array[0]); var B = double.Parse(array[1]); var T = double.Parse(array[2]); var sum = ((T + 0.5) / A) * B; Console.WriteLine(Math.Floor(sum)); } }
using System; class plogram { static void Main() { string[] array = Console.ReadLine().Split(' '); var A = int.Parse(array[0]); var B = int.Parse(array[1]); var T = int.Parse(array[2]); var sum = ((T) / A) * B; Console.WriteLine(sum); } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 31, 23, 0, 16, 31, 23, 0, 16, 17, 72], ["-", 31, 23, 0, 16, 31, 23, 0, 16, 12, 250], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
98
13
using System; public class Solution { public static void Main() { string line = Console.ReadLine(); string[] input = line.Split(' '); int A = Convert.ToInt32(input[0]); int B = Convert.ToInt32(input[1]); int T = Convert.ToInt32(input[2]); int num = Convert.ToInt32((T + 0.5) / A); Console.WriteLine(num * B); } }
using System; public class Solution { public static void Main() { string line = Console.ReadLine(); string[] input = line.Split(' '); int A = Convert.ToInt32(input[0]); int B = Convert.ToInt32(input[1]); int T = Convert.ToInt32(input[2]); Console.WriteLine((T / A) * B); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 17, 72], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 12, 250], ["-", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 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], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22]]
8
103
16
using System; class Program { static void Main(string[] args) { string[] tmp = Console.ReadLine().Split(' '); int a = int.Parse(tmp[0]); int b = int.Parse(tmp[1]); int c = int.Parse(tmp[2]); if (a < c && c < b) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
using System; class Program { static void Main(string[] args) { string[] tmp = Console.ReadLine().Split(' '); int a = int.Parse(tmp[0]); int b = int.Parse(tmp[1]); int c = int.Parse(tmp[2]); if ((a < c && c < b) || (b < c && c < a)) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["+", 15, 16, 31, 23, 0, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 17, 18], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 98], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 31, 22], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 17, 18], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25]]
8
108
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public const long Giri = 1000000007; public const long DpInf = 99999999999999; public static void Main(string[] args) { var n = Console.ReadLine().ToInt(); var s = Console.ReadLine(); bool all = true; long black = 0; for (int i = 0; i < n; i++) { if (s[i] == '.') black++; if (s[0] != s[i]) all = false; } if (all) { Console.WriteLine(0); return; } long min = n; long rw = 0; for (int i = 0; i < n; i++) { if (s[i] == '#') rw++; else black--; min = Math.Min(min, black + rw); } Console.WriteLine(min); } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str, int offset = 0) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset; return r; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public const long Giri = 1000000007; public const long DpInf = 99999999999999; public static void Main(string[] args) { var n = Console.ReadLine().ToInt(); var s = Console.ReadLine(); n = s.Length; bool all = true; long black = 0; for (int i = 0; i < n; i++) { if (s[i] == '.') black++; if (s[0] != s[i]) all = false; } if (all) { Console.WriteLine(0); return; } long min = n * 2; long rw = 0; for (int i = 0; i < n; i++) { min = Math.Min(min, black + rw); if (s[i] == '#') rw++; else black--; } min = Math.Min(min, black + rw); Console.WriteLine(min); } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str, int offset = 0) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset; return r; } }
[["+", 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, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 11, 12, 214, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
402
23
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Hello { static public int mod = 1000000007; public static void Main() { // 方針 // 左から数えて初めて黒が出る場所から右の黒全部か白全部変える -> WA // 左から黒の枚数、右から白の枚数を数えて、ある境界線より左は黒、右は白を変える int num = rint(); string st = rstr(); int[] countb = new int[num]; int[] countw = new int[num]; for (int i = 0; i < num; i++) { if (st[i] == '#') { countb[i]++; } else { countw[i]++; } } for (int i = 1; i < num; i++) { countb[i] += countb[i - 1]; countw[num - i - 1] += countw[num - i]; } int min = 99999999; for (int i = 0; i <= num; i++) { if (i == 0) { min = Min(min, countw[i]); } else if (i == num) { min = Min(min, countb[i - 1]); } else { min = Min(min, countw[i] + countb[i - 1]); } } WriteLine(string.Join(" ", countb)); WriteLine(string.Join(" ", countw)); WriteLine(min); } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(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 int square2(long a,long b,long m){var list = new List<int>();int // temp = 1;long n2 = a;list.Add(1);int count = 1;while(temp < // b){list.Add((int)n2);temp*=2;count++;n2 = n2*n2%m;}long ret = 1;while(b > // 0){if(temp <= b){b -= temp;ret = // ret*list[count]%1000000007;}count--;temp/=2;}return(int)ret;} 各種読取 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 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 int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } 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] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } 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); } } //知見 // (string) hogestr -> (char[]) hoge // char hoge = hogestr.ToCharArray(); // (char[]) hoge -> (string) hogestr // string hoge = new string(hoge); // Hashtable × Dictionary ○ // Dictionary hoge<string,int> // hoge.ContainsKey(string) -> return boolean // hoge[string] -> return int // hoge[int] -> CE // Dictionary hoge<int1,int2> // hoge<int1,int2>: hoge[int1] -> return int2 // KeyValuePair<int,int> k <-> k.Key == int1 / k.Value == int2 // SortedDictionary() > SortedList() ??? // キュー -> 幅優先 ??? // var queue = new Queue<int>(); queue.Enqueue() queue.Dequeue() // スタック -> 深さ優先 ??? // var stack = new Stack<int>(); stack.Push(hoge) stack.Pop() stackPeek() // stack.Count // if (list?.Count > 0) リストが空でもnullでもない // ソート // list.Sort(StringComparer.Ordinal); listの(辞書順?)ソート // StringComparer.Ordinal とは // 出力 // foreach(var a int list){ WriteLine(a); } より // WriteLine(string.Join("\n", list)); が速い // var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false}; // Console.SetOut(sw); // foreach(var k in list[num-1]){ // WriteLine(k); // } // Console.Out.Flush();
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Hello { static public int mod = 1000000007; public static void Main() { // 方針 // 左から数えて初めて黒が出る場所から右の黒全部か白全部変える -> WA // 左から黒の枚数、右から白の枚数を数えて、ある境界線より左は黒、右は白を変える int num = rint(); string st = rstr(); int[] countb = new int[num]; int[] countw = new int[num]; for (int i = 0; i < num; i++) { if (st[i] == '#') { countb[i]++; } else { countw[i]++; } } for (int i = 1; i < num; i++) { countb[i] += countb[i - 1]; countw[num - i - 1] += countw[num - i]; } int min = 99999999; for (int i = 0; i <= num; i++) { if (i == 0) { min = Min(min, countw[i]); } else if (i == num) { min = Min(min, countb[i - 1]); } else { min = Min(min, countw[i] + countb[i - 1]); } } // WriteLine(string.Join(" ",countb)); // WriteLine(string.Join(" ",countw)); WriteLine(min); } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(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 int square2(long a,long b,long m){var list = new List<int>();int // temp = 1;long n2 = a;list.Add(1);int count = 1;while(temp < // b){list.Add((int)n2);temp*=2;count++;n2 = n2*n2%m;}long ret = 1;while(b > // 0){if(temp <= b){b -= temp;ret = // ret*list[count]%1000000007;}count--;temp/=2;}return(int)ret;} 各種読取 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 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 int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } 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] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } 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); } } //知見 // (string) hogestr -> (char[]) hoge // char hoge = hogestr.ToCharArray(); // (char[]) hoge -> (string) hogestr // string hoge = new string(hoge); // Hashtable × Dictionary ○ // Dictionary hoge<string,int> // hoge.ContainsKey(string) -> return boolean // hoge[string] -> return int // hoge[int] -> CE // Dictionary hoge<int1,int2> // hoge<int1,int2>: hoge[int1] -> return int2 // KeyValuePair<int,int> k <-> k.Key == int1 / k.Value == int2 // SortedDictionary() > SortedList() ??? // キュー -> 幅優先 ??? // var queue = new Queue<int>(); queue.Enqueue() queue.Dequeue() // スタック -> 深さ優先 ??? // var stack = new Stack<int>(); stack.Push(hoge) stack.Pop() stackPeek() // stack.Count // if (list?.Count > 0) リストが空でもnullでもない // ソート // list.Sort(StringComparer.Ordinal); listの(辞書順?)ソート // StringComparer.Ordinal とは // 出力 // foreach(var a int list){ WriteLine(a); } より // WriteLine(string.Join("\n", list)); が速い // var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false}; // Console.SetOut(sw); // foreach(var k in list[num-1]){ // WriteLine(k); // } // Console.Out.Flush();
[["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24]]
8
1,054
28
using System; using System.Linq; class C { static void Main() { Console.ReadLine(); var s = Console.ReadLine(); var m = s.Count(c => c == '.'); Console.WriteLine(s.Min(c => m += c == '.' ? -1 : 1)); } }
using System; using System.Linq; class C { static void Main() { Console.ReadLine(); var s = Console.ReadLine(); var m = s.Count(c => c == '.'); Console.WriteLine(Math.Min(m, s.Min(c => m += c == '.' ? -1 : 1))); } }
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
75
7
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { string input = Console.ReadLine(); int N = int.Parse(input); input = Console.ReadLine(); char[] S = input.ToCharArray(); int white_all = 0; int white = 0; int black = 0; for (int i = 0; i < N; i++) { if (S[i] == '.') { white_all++; } } int ans = white_all; int counter = 0; if (white_all == S.Length || white_all == 0) ans = 0; else { for (int i = 0; i < N; i++) { if (S[i] == '#') { black++; } else { white++; } counter = black + white; if (counter < ans) { ans = counter; } } } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { string input = Console.ReadLine(); int N = int.Parse(input); input = Console.ReadLine(); char[] S = input.ToCharArray(); int white_all = 0; int black = 0; for (int i = 0; i < N; i++) { if (S[i] == '.') { white_all++; } } int ans = white_all; int counter = 0; int white = white_all; if (white_all == S.Length || white_all == 0) ans = 0; else { for (int i = 0; i < N; i++) { if (S[i] == '#') { black++; } else { white--; } counter = black + white; if (counter < ans) { ans = counter; } } } Console.WriteLine(ans); } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["-", 0, 57, 75, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 68]]
8
207
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace TenkaPBC2019C2 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); //石の数N個 string S = Console.ReadLine(); //文字列 .白 #黒 int ans = N; int black = 0; int white = S.Replace("#", "").Length; //.の数を数えてみる if ((white == 0) || (white == N)) //.がひとつもない、または全部.なら何もしなくてよい。 { Console.WriteLine(0); } else { for (int i = 0; i < N; i++) { int counter = 0; if (S.Substring(i, 1) == "#") { black++; } else { white--; } counter = black + white; if (counter < ans) { ans = counter; } } Console.WriteLine(ans); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace TenkaPBC2019C2 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); //石の数N個 string S = Console.ReadLine(); //文字列 .白 #黒 int black = 0; int white = S.Replace("#", "").Length; //.の数を数えてみる int ans = white; if ((white == 0) || (white == N)) //.がひとつもない、または全部.なら何もしなくてよい。 { Console.WriteLine(0); } else { for (int i = 0; i < N; i++) { int counter = 0; if (S.Substring(i, 1) == "#") { black++; } else { white--; } counter = black + white; if (counter < ans) { ans = counter; } } Console.WriteLine(ans); } } } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22]]
8
198
32
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace TenkaPBC2019C2 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); //石の数N個 string S = Console.ReadLine(); //文字列 .白 #黒 int ans = N; int black = 0; int white = S.Replace("#", "").Length; //.の数を数えてみる if ((white == 0) || (white == N)) //.がひとつもない、または全部.なら何もしなくてよい。 { Console.WriteLine(0); } else { for (int i = 0; i < N; i++) { int counter = 0; if (S.Substring(i, 1) == "#") { black++; } else { white--; } counter = black + white; if (counter < ans) { ans = counter; } } Console.WriteLine(ans); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace TenkaPBC2019C2 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); //石の数N個 string S = Console.ReadLine(); //文字列 .白 #黒 int black = 0; int white = S.Replace("#", "").Length; //.の数を数えてみる int ans = white; for (int i = 0; i < N; i++) { int counter = 0; if (S.Substring(i, 1) == "#") { black++; } else { white--; } counter = black + white; if (counter < ans) { ans = counter; } } Console.WriteLine(ans); } } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["-", 0, 57, 15, 16, 31, 23, 0, 16, 31, 22], ["-", 0, 57, 15, 16, 31, 23, 0, 16, 17, 60], ["-", 0, 57, 15, 16, 31, 23, 0, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["-", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 57, 15, 16, 12, 23, 0, 16, 17, 60], ["-", 0, 57, 15, 16, 12, 23, 0, 16, 12, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
198
32
using System; using System.Linq; namespace AtCoder2 { class Program { static void Main(string[] args) { checked { Console.ReadLine(); var s = Console.ReadLine(); var white = s.Select(c => c == '.' ? 1 : 0).ToList(); { var sum = 0; for (int n = white.Count - 1; n >= 0; n--) { sum += white[n]; white[n] = sum; } } var black = s.Select(c => c == '#' ? 1 : 0).ToList(); { var sum = 0; for (int n = 0; n < black.Count; n++) { sum += black[n]; black[n] = sum; } } white.RemoveAt(0); white.Add(0); var res = white.Zip(black, (w, b) => w + b).Min(); Console.WriteLine(res); } } } }
using System; using System.Linq; namespace AtCoder2 { class Program { static void Main(string[] args) { checked { Console.ReadLine(); var s = Console.ReadLine(); var white = s.Select(c => c == '.' ? 1 : 0).ToList(); { var sum = 0; for (int n = white.Count - 1; n >= 0; n--) { sum += white[n]; white[n] = sum; } } var black = s.Select(c => c == '#' ? 1 : 0).ToList(); { var sum = 0; for (int n = 0; n < black.Count; n++) { sum += black[n]; black[n] = sum; } } white.RemoveAt(0); white.Add(0); black.RemoveAt(black.Count - 1); black.Insert(0, 0); var res = white.Zip(black, (w, b) => w + b).Min(); Console.WriteLine(res); } } } }
[["+", 0, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 287, 0, 196, 0, 1, 0, 35], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 196, 0, 1, 0, 213, 3, 4, 0, 21]]
8
218
20
using System; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string S = Console.ReadLine(); int LW = 0; int LB = 0; int RW = 0; int RB = 0; // 初期化 for (int i = 0; i < N; i++) { if (S[i] == '.') { RW++; } else { RB++; } } int min = -1; for (int i = 0; i < N; i++) { if (S[i] == '.') { LW++; RW--; } else { LB++; RB--; } if (min < 0 || LB + RW < min) { min = LB + RW; } } Console.WriteLine(min); } }
using System; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string S = Console.ReadLine(); int LW = 0; int LB = 0; int RW = 0; int RB = 0; // 初期化 for (int i = 0; i < N; i++) { if (S[i] == '.') { RW++; } else { RB++; } } int min = LB + RW; for (int i = 0; i < N; i++) { if (S[i] == '.') { LW++; RW--; } else { LB++; RB--; } if (LB + RW < min) { min = LB + RW; } } Console.WriteLine(min); } }
[["-", 0, 198, 0, 200, 0, 212, 0, 241, 0, 33], ["-", 0, 198, 0, 200, 0, 212, 0, 241, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106]]
8
177
9