buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; class Program { const int MOD = 1000000007; static void Main(string[] args) { new Program().Solve(); } void Solve() { Scanner cin = new Scanner(); int n = cin.NextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = cin.NextInt(); } int max = a.Max(); int min = a.Min(); int maxIndex = Array.IndexOf(a, max); int minIndex = Array.LastIndexOf(a, min); // if max num is the same as min num, min // index is also the same max index. var others = a.Where((num, i) => i != maxIndex && i != minIndex).ToArray(); int result = max - min + others.Sum(Math.Abs); var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Console.WriteLine(result); int tmpMin = min; foreach (var num in others.Where(e => e > 0)) { Console.WriteLine("{0} {1}", tmpMin, num); // Remarks: order as x - y tmpMin -= num; } int tmpMax = max; foreach (var num in others.Where(e => e < 0)) { Console.WriteLine("{0} {1}", tmpMax, num); // Remarks: order as x - y tmpMax -= num; } Console.WriteLine("{0} {1}", tmpMax, tmpMin); // Remarks: x - y == result -> true. Console.Out.Flush(); } } 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 char[] ArrayChar() { return Next().ToCharArray(); } 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; } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; class Program { const int MOD = 1000000007; static void Main(string[] args) { new Program().Solve(); } void Solve() { Scanner cin = new Scanner(); int n = cin.NextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = cin.NextInt(); } int max = a.Max(); int min = a.Min(); int maxIndex = Array.IndexOf(a, max); int minIndex = Array.LastIndexOf(a, min); // if max num is the same as min num, min // index is also the same max index. var others = a.Where((num, i) => i != maxIndex && i != minIndex).ToArray(); int result = max - min + others.Sum(Math.Abs); var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Console.WriteLine(result); int tmpMin = min; foreach (var num in others.Where(e => e >= 0)) { Console.WriteLine("{0} {1}", tmpMin, num); // Remarks: order as x - y tmpMin -= num; } int tmpMax = max; foreach (var num in others.Where(e => e < 0)) { Console.WriteLine("{0} {1}", tmpMax, num); // Remarks: order as x - y tmpMax -= num; } Console.WriteLine("{0} {1}", tmpMax, tmpMin); // Remarks: x - y == result -> true. Console.Out.Flush(); } } 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 char[] ArrayChar() { return Next().ToCharArray(); } 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; } }
[["-", 3, 4, 0, 28, 0, 218, 8, 16, 17, 47], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 20]]
8
718
2
using System; using System.Collections.Generic; using System.IO; namespace I_am_the_brown_coder { class Inonoa { static void Main() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); long n = long.Parse(Console.ReadLine()); string[] sa = Console.ReadLine().Split(); long[] a = new long[n]; long mn = -1000000; long minindex = -1; for (long i = 0; i < n; i++) { a[i] = long.Parse(sa[i]); } long[,] ans = new long[n - 1, 2]; long index = 0; Array.Sort(a); for (long i = 0; i < n; i++) { if (a[i] <= 0 && a[i] > mn) { mn = a[i]; minindex = i; } } if (minindex == -1) { mn = a[0]; minindex = 0; } for (long i = minindex + 1; i < n - 1; i++) { ans[index, 0] = a[minindex]; ans[index, 1] = a[i]; a[minindex] -= a[i]; index++; } if (minindex < n - 1) { ans[index, 0] = a[n - 1]; ans[index, 1] = a[minindex]; index++; a[minindex] -= a[n - 1]; a[minindex] *= -1; } for (long i = minindex - 1; i > -1; i--) { ans[index, 0] = a[minindex]; ans[index, 1] = a[i]; a[minindex] -= a[i]; index++; } Console.WriteLine(a[minindex]); for (long i = 0; i < n - 1; i++) { Console.Write(ans[i, 0]); Console.Write(" "); Console.WriteLine(ans[i, 1]); } Console.Out.Flush(); } } }
using System; using System.Collections.Generic; using System.IO; namespace I_am_the_brown_coder { class Inonoa { static void Main() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); long n = long.Parse(Console.ReadLine()); string[] sa = Console.ReadLine().Split(); long[] a = new long[n]; long mn = -1000000; long minindex = -1; for (long i = 0; i < n; i++) { a[i] = long.Parse(sa[i]); } long[,] ans = new long[n - 1, 2]; long index = 0; Array.Sort(a); for (long i = 0; i < n; i++) { if (a[i] <= 0 && a[i] >= mn) { mn = a[i]; minindex = i; } } if (minindex == -1) { mn = a[0]; minindex = 0; } for (long i = minindex + 1; i < n - 1; i++) { ans[index, 0] = a[minindex]; ans[index, 1] = a[i]; a[minindex] -= a[i]; index++; } if (minindex < n - 1) { ans[index, 0] = a[n - 1]; ans[index, 1] = a[minindex]; index++; a[minindex] -= a[n - 1]; a[minindex] *= -1; } for (long i = minindex - 1; i > -1; i--) { ans[index, 0] = a[minindex]; ans[index, 1] = a[i]; a[minindex] -= a[i]; index++; } Console.WriteLine(a[minindex]); for (long i = 0; i < n - 1; i++) { Console.Write(ans[i, 0]); Console.Write(" "); Console.WriteLine(ans[i, 1]); } Console.Out.Flush(); } } }
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20]]
8
472
2
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Numerics; using System.Threading; using System.Runtime.CompilerServices; using System.Diagnostics; using static System.Math; using static System.Array; using static AtCoder.Cout; using static AtCoder.Tool; using static AtCoder.ModInt; namespace AtCoder { class AC { const int MOD = 1000000007; // const int MOD = 998244353; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 3; const double EPS = 1e-8; static readonly int[] dI = { 0, 1, 0, -1, 1, -1, -1, 1 }; static readonly int[] dJ = { 1, 0, -1, 0, 1, 1, -1, -1 }; static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); var th = new Thread(Run, 1 << 26); th.Start(); th.Join(); // Run(); Console.Out.Flush(); } static void Run() { int Testcase = 1; // Testcase = Cin.Int; for (var _ = 0; _ < Testcase; _++) Solve(); } static void Solve() { int N = Cin.Int; var a = Cin.ReadSplitInt; var b = Cin.ReadSplitInt; var g = b[0] - a[0]; var s = b[1] - a[1]; var c = b[2] - a[2]; var dp = new long[N + 1]; for (var i = 1; i <= N; i++) { dp[i] = Max(dp[i], dp[i - 1]); if (i - a[0] >= 0) dp[i] = Max(dp[i], dp[i - a[0]] + b[0]); if (i - a[1] >= 0) dp[i] = Max(dp[i], dp[i - a[1]] + b[1]); if (i - a[2] >= 0) dp[i] = Max(dp[i], dp[i - a[2]] + b[2]); } N = (int)dp[N]; dp = new long[N + 1]; for (var i = 1; i <= N; i++) { dp[i] = Max(dp[i], dp[i - 1]); if (i - b[0] >= 0) dp[i] = Max(dp[i], dp[i - b[0]] + a[0]); if (i - b[1] >= 0) dp[i] = Max(dp[i], dp[i - b[1]] + a[1]); if (i - b[2] >= 0) dp[i] = Max(dp[i], dp[i - b[2]] + a[2]); } OutL(dp[N]); } public 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; } } } struct ModInt { public long value; private const int MOD = 1000000007; // private const int MOD = 998244353; public ModInt(long value) { this.value = value; } public static implicit operator ModInt(long a) { var ret = a % MOD; return new ModInt(ret < 0 ? (ret + MOD) : ret); } public static ModInt operator +(ModInt a, ModInt b) => (a.value + b.value); public static ModInt operator -(ModInt a, ModInt b) => (a.value - b.value); public static ModInt operator *(ModInt a, ModInt b) => (a.value * b.value); public static ModInt operator /(ModInt a, ModInt b) => a * Modpow(b, MOD - 2); public static ModInt operator <<(ModInt a, int n) => (a.value << n); public static ModInt operator>>(ModInt a, int n) => (a.value >> n); public static ModInt operator ++(ModInt a) => a.value + 1; public static ModInt operator --(ModInt a) => a.value - 1; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Modpow(ModInt a, long n) { if (n < 0) return Modpow(Modpow(a, -n), MOD - 2); var k = a; ModInt ret = 1; while (n > 0) { if ((n & 1) != 0) ret *= k; k *= k; n >>= 1; } return ret; } private static readonly List<long> Factorials = new List<long>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Fac(long n) { for (var i = Factorials.Count(); i <= n; i++) { Factorials.Add((Factorials[i - 1] * i) % MOD); } return Factorials[(int)n]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt nCr(long n, long r) { if (n < 0 || r < 0) return 0; return n < r ? 0 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(ModInt a) => (int)a.value; } public class Rolling_Hash { const ulong m30 = (1UL << 30) - 1; const ulong m31 = (1UL << 31) - 1; const ulong MOD = (1UL << 61) - 1; const ulong Pl = (MOD << 1) << 1; private uint B; private string S; ulong[] hash; ulong[] pw; public Rolling_Hash(string str) { S = str; B = (uint) new Random().Next(1 << 12 + 1, int.MaxValue); int L = S.Length; hash = new ulong[L + 1]; pw = new ulong[L + 1]; hash[0] = 0; pw[0] = 1; for (var i = 0; i < L; i++) { hash[i + 1] = CalcMod(Mul(hash[i], B) + S[i]); pw[i + 1] = CalcMod(Mul(pw[i], B)); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public ulong GetHashValue(int idx) => hash[idx]; [MethodImpl(MethodImplOptions.AggressiveInlining)] // segment [l,r] public ulong Hash_fold(int l, int r) => CalcMod(Pl + hash[r + 1] - Mul(hash[l], pw[r - l + 1])); [MethodImpl( MethodImplOptions.AggressiveInlining)] // segment[start,start+len-1] public ulong Hash_sub(int start, int len) => CalcMod(Pl + hash[start + len] - Mul(hash[start], pw[len])); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ulong[] GetHashArray() => hash; [MethodImpl(MethodImplOptions.AggressiveInlining)] ulong Mul(ulong a, ulong b) { ulong au = a >> 31; ulong ad = a & m31; ulong bu = b >> 31; ulong bd = b & m31; ulong mid = ad * bu + au * bd; ulong midu = mid >> 30; ulong midd = mid & m30; return au * bu * 2 + midu + (midd << 31) + ad * bd; } [MethodImpl(MethodImplOptions.AggressiveInlining)] ulong CalcMod(ulong x) { ulong xu = x >> 61; ulong xd = x & MOD; ulong res = xu + xd; if (res >= MOD) res -= MOD; return res; } } public class Priority_Queue<T> { private List<T> Q; private readonly Comparison<T> Func_Compare; public Priority_Queue(Comparison<T> comp) { Func_Compare = comp; Q = new List<T>(); } private void PushHeap(List<T> list, T item) { int n = list.Count(); list.Add(item); while (n != 0) { int pIndex = (n - 1) / 2; if (Func_Compare(list[n], list[pIndex]) < 0) { Swap(Q, n, pIndex); } else { break; } n = pIndex; } } private void PopHeap(List<T> list) { int n = list.Count() - 1; list[0] = list[n]; list.RemoveAt(n); int cur = 0; int comp; while (2 * cur + 1 <= n - 1) { int c1 = 2 * cur + 1; int c2 = 2 * (cur + 1); if (c1 == n - 1) { comp = c1; } else { comp = Func_Compare(list[c1], list[c2]) < 0 ? c1 : c2; } if (Func_Compare(list[cur], list[comp]) > 0) { Swap(Q, cur, comp); } else { break; } cur = comp; } } private void Swap(List<T> list, int a, int b) { T keep = list[a]; list[a] = list[b]; list[b] = keep; } public void Enqueue(T value) { PushHeap(Q, value); } public T Dequeue() { T ret = Q[0]; PopHeap(Q); return ret; } public T Peek() { return Q[0]; } public int Count() { return Q.Count(); } public bool Any() { return Q.Any(); } } public class SegmentTree<T> { // 1-indexed type int n; T[] Tree; Func<T, T, T> f; T ex; int L; [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegmentTree(int size, Func<T, T, T> fun, T exvalue) { ex = exvalue; f = fun; n = 1; while (n < size) n <<= 1; Tree = new T[n << 1]; L = (n << 1) - 1; for (var i = 0; i <= L; i++) Tree[i] = ex; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegmentTree(int size, Func<T, T, T> fun, T exvalue, T[] initial) { ex = exvalue; n = 1; while (n < size) n <<= 1; f = fun; Tree = new T[n << 1]; L = (n << 1) - 1; for (var i = 0; i <= L; i++) Tree[i] = (n <= i && i <= n + initial.Length - 1) ? initial[i - n] : ex; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Set_All() { for (var i = n - 1; i >= 1; i--) Tree[i] = f(Tree[i << 1], Tree[(i << 1) | 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Assign(int idx, T nxt) => Tree[idx + n] = nxt; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(int idx) { int now = idx + n; while (now > 1) { now >>= 1; Tree[now] = f(Tree[now << 1], Tree[now << 1 | 1]); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Query_Update(int idx, T nxt) { Assign(idx, nxt); Update(idx); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Query_Update_func(int idx, T y) { Assign(idx, f(Peek(idx), y)); Update(idx); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Query_Fold(int l, int r) { int L = n + l; int R = n + r; T vL = ex, vR = ex; while (L < R) { if (L % 2 == 1) { vL = f(vL, Tree[L]); L++; } if (R % 2 == 1) { vR = f(Tree[R - 1], vR); R--; } L >>= 1; R >>= 1; } return f(vL, vR); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Peek(int idx) => Tree[idx + n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Display(int len) { for (var i = 0; i < len; i++) Console.Write($"{Tree[i + n]} "); Console.WriteLine(); } } 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)]; } } static class Cin { public static string[] ReadSplit => Console.ReadLine().Split(); public static int[] ReadSplitInt => ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] ReadSplitLong => ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] ReadSplit_Double => ConvertAll(Console.ReadLine().Split(), double.Parse); public static string Str => Console.ReadLine(); public static int Int => int.Parse(Console.ReadLine()); public static long Long => long.Parse(Console.ReadLine()); public static double Double => double.Parse(Console.ReadLine()); public static T Conv<T>(string input) { if (typeof(T).Equals(typeof(ModInt))) { return (T)(dynamic)(long.Parse(input)); } return (T)Convert.ChangeType(input, typeof(T)); } public static void Scanf<T>(out T a) => a = Conv<T>(Console.ReadLine()); public static void Scanf<T, U>(out T a, out U b) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); } public static void Scanf<T, U, V>(out T a, out U b, out V c) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); } public static void Scanf<T, U, V, W>(out T a, out U b, out V c, out W d) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); } public static void Scanf<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); e = Conv<X>(q[4]); } } static class Cout { public static void OutL(object s) => Console.WriteLine(s); public static void Out_Sep<T>(IEnumerable<T> s) => Console.WriteLine(string.Join(" ", s)); public static void Out_Sep<T>(IEnumerable<T> s, string sep) => Console.WriteLine(string.Join($"{sep}", s)); public static void Out_Sep(params object[] s) => Console.WriteLine(string.Join(" ", s)); public static void Out_One(object s) => Console.Write($"{s} "); public static void Out_One(object s, string sep) => Console.Write($"{s}{sep}"); public static void Endl() => Console.WriteLine(); } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { array = ConvertAll(array, x => 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 Gcd(long a, long b) { if (a == 0 || b == 0) return Max(a, b); return a % b == 0 ? b : Gcd(b, a % b); } static public long LPow(int a, int b) => (long)Pow(a, b); static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0; static public int Sig(long a) => a == 0 ? 0 : (int)(a / Abs(a)); } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Numerics; using System.Threading; using System.Runtime.CompilerServices; using System.Diagnostics; using static System.Math; using static System.Array; using static AtCoder.Cout; using static AtCoder.Tool; using static AtCoder.ModInt; namespace AtCoder { class AC { const int MOD = 1000000007; // const int MOD = 998244353; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 3; const double EPS = 1e-8; static readonly int[] dI = { 0, 1, 0, -1, 1, -1, -1, 1 }; static readonly int[] dJ = { 1, 0, -1, 0, 1, 1, -1, -1 }; static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); var th = new Thread(Run, 1 << 26); th.Start(); th.Join(); // Run(); Console.Out.Flush(); } static void Run() { int Testcase = 1; // Testcase = Cin.Int; for (var _ = 0; _ < Testcase; _++) Solve(); } static void Solve() { int N = Cin.Int; var a = Cin.ReadSplitInt; var b = Cin.ReadSplitInt; var g = b[0] - a[0]; var s = b[1] - a[1]; var c = b[2] - a[2]; var dp = new long[N + 1]; for (var i = 1; i <= N; i++) { dp[i] = Max(dp[i], dp[i - 1] + 1); if (i - a[0] >= 0) dp[i] = Max(dp[i], dp[i - a[0]] + b[0]); if (i - a[1] >= 0) dp[i] = Max(dp[i], dp[i - a[1]] + b[1]); if (i - a[2] >= 0) dp[i] = Max(dp[i], dp[i - a[2]] + b[2]); } N = (int)dp[N]; dp = new long[N + 1]; for (var i = 1; i <= N; i++) { dp[i] = Max(dp[i], dp[i - 1] + 1); if (i - b[0] >= 0) dp[i] = Max(dp[i], dp[i - b[0]] + a[0]); if (i - b[1] >= 0) dp[i] = Max(dp[i], dp[i - b[1]] + a[1]); if (i - b[2] >= 0) dp[i] = Max(dp[i], dp[i - b[2]] + a[2]); } OutL(dp[N]); } public 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; } } } struct ModInt { public long value; private const int MOD = 1000000007; // private const int MOD = 998244353; public ModInt(long value) { this.value = value; } public static implicit operator ModInt(long a) { var ret = a % MOD; return new ModInt(ret < 0 ? (ret + MOD) : ret); } public static ModInt operator +(ModInt a, ModInt b) => (a.value + b.value); public static ModInt operator -(ModInt a, ModInt b) => (a.value - b.value); public static ModInt operator *(ModInt a, ModInt b) => (a.value * b.value); public static ModInt operator /(ModInt a, ModInt b) => a * Modpow(b, MOD - 2); public static ModInt operator <<(ModInt a, int n) => (a.value << n); public static ModInt operator>>(ModInt a, int n) => (a.value >> n); public static ModInt operator ++(ModInt a) => a.value + 1; public static ModInt operator --(ModInt a) => a.value - 1; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Modpow(ModInt a, long n) { if (n < 0) return Modpow(Modpow(a, -n), MOD - 2); var k = a; ModInt ret = 1; while (n > 0) { if ((n & 1) != 0) ret *= k; k *= k; n >>= 1; } return ret; } private static readonly List<long> Factorials = new List<long>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Fac(long n) { for (var i = Factorials.Count(); i <= n; i++) { Factorials.Add((Factorials[i - 1] * i) % MOD); } return Factorials[(int)n]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt nCr(long n, long r) { if (n < 0 || r < 0) return 0; return n < r ? 0 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(ModInt a) => (int)a.value; } public class Rolling_Hash { const ulong m30 = (1UL << 30) - 1; const ulong m31 = (1UL << 31) - 1; const ulong MOD = (1UL << 61) - 1; const ulong Pl = (MOD << 1) << 1; private uint B; private string S; ulong[] hash; ulong[] pw; public Rolling_Hash(string str) { S = str; B = (uint) new Random().Next(1 << 12 + 1, int.MaxValue); int L = S.Length; hash = new ulong[L + 1]; pw = new ulong[L + 1]; hash[0] = 0; pw[0] = 1; for (var i = 0; i < L; i++) { hash[i + 1] = CalcMod(Mul(hash[i], B) + S[i]); pw[i + 1] = CalcMod(Mul(pw[i], B)); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public ulong GetHashValue(int idx) => hash[idx]; [MethodImpl(MethodImplOptions.AggressiveInlining)] // segment [l,r] public ulong Hash_fold(int l, int r) => CalcMod(Pl + hash[r + 1] - Mul(hash[l], pw[r - l + 1])); [MethodImpl( MethodImplOptions.AggressiveInlining)] // segment[start,start+len-1] public ulong Hash_sub(int start, int len) => CalcMod(Pl + hash[start + len] - Mul(hash[start], pw[len])); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ulong[] GetHashArray() => hash; [MethodImpl(MethodImplOptions.AggressiveInlining)] ulong Mul(ulong a, ulong b) { ulong au = a >> 31; ulong ad = a & m31; ulong bu = b >> 31; ulong bd = b & m31; ulong mid = ad * bu + au * bd; ulong midu = mid >> 30; ulong midd = mid & m30; return au * bu * 2 + midu + (midd << 31) + ad * bd; } [MethodImpl(MethodImplOptions.AggressiveInlining)] ulong CalcMod(ulong x) { ulong xu = x >> 61; ulong xd = x & MOD; ulong res = xu + xd; if (res >= MOD) res -= MOD; return res; } } public class Priority_Queue<T> { private List<T> Q; private readonly Comparison<T> Func_Compare; public Priority_Queue(Comparison<T> comp) { Func_Compare = comp; Q = new List<T>(); } private void PushHeap(List<T> list, T item) { int n = list.Count(); list.Add(item); while (n != 0) { int pIndex = (n - 1) / 2; if (Func_Compare(list[n], list[pIndex]) < 0) { Swap(Q, n, pIndex); } else { break; } n = pIndex; } } private void PopHeap(List<T> list) { int n = list.Count() - 1; list[0] = list[n]; list.RemoveAt(n); int cur = 0; int comp; while (2 * cur + 1 <= n - 1) { int c1 = 2 * cur + 1; int c2 = 2 * (cur + 1); if (c1 == n - 1) { comp = c1; } else { comp = Func_Compare(list[c1], list[c2]) < 0 ? c1 : c2; } if (Func_Compare(list[cur], list[comp]) > 0) { Swap(Q, cur, comp); } else { break; } cur = comp; } } private void Swap(List<T> list, int a, int b) { T keep = list[a]; list[a] = list[b]; list[b] = keep; } public void Enqueue(T value) { PushHeap(Q, value); } public T Dequeue() { T ret = Q[0]; PopHeap(Q); return ret; } public T Peek() { return Q[0]; } public int Count() { return Q.Count(); } public bool Any() { return Q.Any(); } } public class SegmentTree<T> { // 1-indexed type int n; T[] Tree; Func<T, T, T> f; T ex; int L; [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegmentTree(int size, Func<T, T, T> fun, T exvalue) { ex = exvalue; f = fun; n = 1; while (n < size) n <<= 1; Tree = new T[n << 1]; L = (n << 1) - 1; for (var i = 0; i <= L; i++) Tree[i] = ex; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegmentTree(int size, Func<T, T, T> fun, T exvalue, T[] initial) { ex = exvalue; n = 1; while (n < size) n <<= 1; f = fun; Tree = new T[n << 1]; L = (n << 1) - 1; for (var i = 0; i <= L; i++) Tree[i] = (n <= i && i <= n + initial.Length - 1) ? initial[i - n] : ex; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Set_All() { for (var i = n - 1; i >= 1; i--) Tree[i] = f(Tree[i << 1], Tree[(i << 1) | 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Assign(int idx, T nxt) => Tree[idx + n] = nxt; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(int idx) { int now = idx + n; while (now > 1) { now >>= 1; Tree[now] = f(Tree[now << 1], Tree[now << 1 | 1]); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Query_Update(int idx, T nxt) { Assign(idx, nxt); Update(idx); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Query_Update_func(int idx, T y) { Assign(idx, f(Peek(idx), y)); Update(idx); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Query_Fold(int l, int r) { int L = n + l; int R = n + r; T vL = ex, vR = ex; while (L < R) { if (L % 2 == 1) { vL = f(vL, Tree[L]); L++; } if (R % 2 == 1) { vR = f(Tree[R - 1], vR); R--; } L >>= 1; R >>= 1; } return f(vL, vR); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Peek(int idx) => Tree[idx + n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Display(int len) { for (var i = 0; i < len; i++) Console.Write($"{Tree[i + n]} "); Console.WriteLine(); } } 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)]; } } static class Cin { public static string[] ReadSplit => Console.ReadLine().Split(); public static int[] ReadSplitInt => ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] ReadSplitLong => ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] ReadSplit_Double => ConvertAll(Console.ReadLine().Split(), double.Parse); public static string Str => Console.ReadLine(); public static int Int => int.Parse(Console.ReadLine()); public static long Long => long.Parse(Console.ReadLine()); public static double Double => double.Parse(Console.ReadLine()); public static T Conv<T>(string input) { if (typeof(T).Equals(typeof(ModInt))) { return (T)(dynamic)(long.Parse(input)); } return (T)Convert.ChangeType(input, typeof(T)); } public static void Scanf<T>(out T a) => a = Conv<T>(Console.ReadLine()); public static void Scanf<T, U>(out T a, out U b) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); } public static void Scanf<T, U, V>(out T a, out U b, out V c) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); } public static void Scanf<T, U, V, W>(out T a, out U b, out V c, out W d) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); } public static void Scanf<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); e = Conv<X>(q[4]); } } static class Cout { public static void OutL(object s) => Console.WriteLine(s); public static void Out_Sep<T>(IEnumerable<T> s) => Console.WriteLine(string.Join(" ", s)); public static void Out_Sep<T>(IEnumerable<T> s, string sep) => Console.WriteLine(string.Join($"{sep}", s)); public static void Out_Sep(params object[] s) => Console.WriteLine(string.Join(" ", s)); public static void Out_One(object s) => Console.Write($"{s} "); public static void Out_One(object s, string sep) => Console.Write($"{s}{sep}"); public static void Endl() => Console.WriteLine(); } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { array = ConvertAll(array, x => 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 Gcd(long a, long b) { if (a == 0 || b == 0) return Max(a, b); return a % b == 0 ? b : Gcd(b, a % b); } static public long LPow(int a, int b) => (long)Pow(a, b); static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0; static public int Sig(long a) => a == 0 ? 0 : (int)(a / Abs(a)); } }
[["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
4,054
4
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 { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public long NapSac(long N, int[] buyrate, int[] sellrate) { long[] DP = new long[N + 1]; for (long i = 0; i <= N - 1; i++) { DP[i] = i; } for (long i = 0; i <= N - 1; i++) { for (int j = 0; j < 3; j++) { if (buyrate[j] >= sellrate[j]) { continue; } if (i + buyrate[j] > N) { continue; } DP[i + buyrate[j]] = Max(DP[i + buyrate[j]], DP[i] + sellrate[j]); } } return DP.Max(); } public void Solve(ConsoleInput cin) { var N = cin.ReadLong; int[] Arate = cin.ReadIntArray(3); int[] Brate = cin.ReadIntArray(3); var donguriAB = NapSac(N, Arate, Brate); var ans = NapSac(donguriAB, Brate, Arate); 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; } } }
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 { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public long NapSac(long N, int[] buyrate, int[] sellrate) { long[] DP = new long[N + 1]; for (long i = 0; i <= N; i++) { DP[i] = i; } for (long i = 0; i <= N - 1; i++) { for (int j = 0; j < 3; j++) { if (buyrate[j] >= sellrate[j]) { continue; } if (i + buyrate[j] > N) { continue; } DP[i + buyrate[j]] = Max(DP[i + buyrate[j]], DP[i] + sellrate[j]); } } return DP.Max(); } public void Solve(ConsoleInput cin) { var N = cin.ReadLong; int[] Arate = cin.ReadIntArray(3); int[] Brate = cin.ReadIntArray(3); var donguriAB = NapSac(N, Arate, Brate); var ans = NapSac(donguriAB, Brate, Arate); 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; } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
646
2
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] s1 = Console.ReadLine().Split(' '); int ga = int.Parse(s1[0]), sa = int.Parse(s1[1]), ba = int.Parse(s1[2]); string[] s2 = Console.ReadLine().Split(' '); int gb = int.Parse(s2[0]), sb = int.Parse(s2[1]), bb = int.Parse(s2[2]); long donguri = 0; for (int i = 0; i * ga <= n; i++) { if (ga >= gb && i > 0) break; for (int j = 0; i * ga + j * sa <= n; j++) { if (sa >= sb && j > 0) break; int k = 0; if (ba < bb) k = (n - ga * i - sa * j) / ba; donguri = Math.Max(donguri, (gb - ga) * i + (sb - sa) * j + (bb - ba) * k); } } n += (int)donguri; Console.Error.WriteLine(n); donguri = 0; if (n > 5000) for (long i = 0; i * gb <= n; i++) { if (gb >= ga && i > 0) break; if (1.0 * ga / gb <= 1.0 * sa / sb && i > sb) break; for (long j = 0; i * gb + j * sb <= n; j++) { if (sb >= sa && j > 0) break; if (1.0 * ga / gb >= 1.0 * sa / sb && j > gb) break; long k = 0; if (bb < ba) k = (n - gb * i - sb * j) / bb; donguri = Math.Max(donguri, (ga - gb) * i + (sa - sb) * j + (ba - bb) * k); } } Console.WriteLine((long)n + donguri); } } // mcs Main.cs // mono Main.exe
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] s1 = Console.ReadLine().Split(' '); int ga = int.Parse(s1[0]), sa = int.Parse(s1[1]), ba = int.Parse(s1[2]); string[] s2 = Console.ReadLine().Split(' '); int gb = int.Parse(s2[0]), sb = int.Parse(s2[1]), bb = int.Parse(s2[2]); long donguri = 0; for (int i = 0; i * ga <= n; i++) { if (ga >= gb && i > 0) break; for (int j = 0; i * ga + j * sa <= n; j++) { if (sa >= sb && j > 0) break; int k = 0; if (ba < bb) k = (n - ga * i - sa * j) / ba; donguri = Math.Max(donguri, (gb - ga) * i + (sb - sa) * j + (bb - ba) * k); } } n += (int)donguri; Console.Error.WriteLine(n); donguri = 0; for (long i = 0; i * gb <= n; i++) { if (gb >= ga && i > 0) break; if (1.0 * ga / gb <= 1.0 * sa / sb && i > sb) break; for (long j = 0; i * gb + j * sb <= n; j++) { if (sb >= sa && j > 0) break; if (1.0 * ga / gb >= 1.0 * sa / sb && j > gb) break; // Console.Error.WriteLine(i + " " + j); long k = 0; if (bb < ba) k = (n - gb * i - sb * j) / bb; donguri = Math.Max(donguri, (ga - gb) * i + (sa - sb) * j + (ba - bb) * k); } } Console.WriteLine((long)n + donguri); } } // mcs Main.cs // mono Main.exe
[["-", 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, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25]]
8
487
6
using System; namespace newEx { class Program { static void Main(string[] args) { string[] l = Console.ReadLine().Split(' '); int p = int.Parse(l[0]); int q = int.Parse(l[1]); int r = int.Parse(l[2]); Console.WriteLine(Solve(p, q, r)); } public static int Solve(int p, int q, int r) { int ret = p + r; int ret2 = p + q; //修正200630 int ret3 = r + q; //修正200630 // ret = 2; // ret2 = 3; // ret3 = 1; if (ret < ret2 && ret < ret3) //修正200630 { // Console.WriteLine("最短距離:"+ p+r +"時間"); return ret; } else if (ret2 < ret && ret2 < ret3) //修正200630 { // Console.WriteLine("最短距離:" + p+q + "時間"); return ret2; //修正200630 } else // else if (ret3 < ret && ret3 < ret2) //修正200630 { // Console.WriteLine("最短距離:" + r+q + "時間"); return ret3; //修正200630 } } } }
using System; namespace newEx { class Program { static void Main(string[] args) { string[] l = Console.ReadLine().Split(' '); int p = int.Parse(l[0]); int q = int.Parse(l[1]); int r = int.Parse(l[2]); Console.WriteLine(Solve(p, q, r)); } public static int Solve(int p, int q, int r) { int ret = p + r; int ret2 = p + q; //修正200630 int ret3 = r + q; //修正200630 // ret = 2; // ret2 = 3; // ret3 = 1; if (ret <= ret2 && ret <= ret3) //修正200630 { // Console.WriteLine("最短距離:"+ p+r +"時間"); return ret; } else if (ret2 <= ret && ret2 <= ret3) //修正200630 { // Console.WriteLine("最短距離:" + p+q + "時間"); return ret2; //修正200630 } else // else if (ret3 < ret && ret3 < ret2) //修正200630 { // Console.WriteLine("最短距離:" + r+q + "時間"); return ret3; //修正200630 } } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["-", 0, 57, 75, 57, 15, 16, 31, 16, 17, 18], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 17, 19], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 17, 18], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 19]]
8
180
8
using System; using System.Linq; namespace ABC129A { class Program { static void Main(string[] args) { int[] PQR = CIN.IntArray(); Console.WriteLine(PQR.Sum() - PQR.Min()); } } internal static class CIN { public static string String() { return Console.ReadLine(); } public static int Int() { return int.Parse(Console.ReadLine()); } public static int[] IntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long Long() { return long.Parse(Console.ReadLine()); } public static long[] LongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static double[] DoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } }
using System; using System.Linq; namespace ABC129A { class Program { static void Main(string[] args) { int[] PQR = CIN.IntArray(); Console.WriteLine(PQR.Sum() - PQR.Max()); } } internal static class CIN { public static string String() { return Console.ReadLine(); } public static int Int() { return int.Parse(Console.ReadLine()); } public static int[] IntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long Long() { return long.Parse(Console.ReadLine()); } public static long[] LongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static double[] DoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } }
[["-", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22]]
8
221
2
using System; class Qsort { public static void Main() { string[] str = Console.ReadLine().Split(' '); long p = long.Parse(str[0]); long q = long.Parse(str[1]); long r = long.Parse(str[2]); if (p > q && p > r) Console.WriteLine(q + r); else if (q > p && q > r) Console.WriteLine(p + r); else Console.WriteLine(p + q); } }
using System; class Qsort { public static void Main() { string[] str = Console.ReadLine().Split(' '); long p = long.Parse(str[0]); long q = long.Parse(str[1]); long r = long.Parse(str[2]); if (p >= q && p >= r) Console.WriteLine(q + r); else if (q >= p && q >= r) Console.WriteLine(p + r); else Console.WriteLine(p + q); } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20], ["-", 0, 57, 75, 57, 15, 16, 31, 16, 17, 47], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 17, 20], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 17, 47], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 20]]
8
121
8
using System; class Program { static void Main(string[] args) { string[] astr = Console.ReadLine().Split(' '); int a = int.Parse(astr[0]); int b = int.Parse(astr[1]); int c = int.Parse(astr[2]); int d = 0; int e = 0; int f = 0; int rtn = 0; int rtn1 = 0; int rtn2 = 0; // A + B c d = a + b; e = c + b; f = c + a; int[] ar1 = new int[3] { d, e, f }; for (int i = 0; i < 3; i++) { if (rtn >= ar1[i]) { rtn = ar1[i]; } } Console.WriteLine(rtn); } }
using System; class Program { static void Main(string[] args) { string[] astr = Console.ReadLine().Split(' '); int a = int.Parse(astr[0]); int b = int.Parse(astr[1]); int c = int.Parse(astr[2]); int d = 0; int e = 0; int f = 0; int rtn = 9999999; int rtn1 = 0; int rtn2 = 0; // A + B c d = a + b; e = c + b; f = c + a; int[] ar1 = new int[3] { d, e, f }; for (int i = 0; i < 3; i++) { if (rtn >= ar1[i]) { rtn = ar1[i]; } } Console.WriteLine(rtn); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
183
2
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static void Main() { string[] input = Console.ReadLine().Split(' '); int p = int.Parse(input[0]); int q = int.Parse(input[1]); int r = int.Parse(input[1]); int answer = Math.Min(p + q, p + r); answer = Math.Min(answer, q + r); Console.WriteLine(answer); } }
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static void Main() { string[] input = Console.ReadLine().Split(' '); int p = int.Parse(input[0]); int q = int.Parse(input[1]); int r = int.Parse(input[2]); int answer = Math.Min(p + q, p + r); answer = Math.Min(answer, q + r); Console.WriteLine(answer); } }
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
8
126
2
using System; namespace ConsoleApp1 { class Class1 { static void Main(string[] args) { string S = Console.ReadLine(); string[] PQR = S.Split(' '); int P = int.Parse(PQR[0]); int Q = int.Parse(PQR[1]); int R = int.Parse(PQR[2]); int PQ = P + Q; int QR = Q + R; int PR = P + R; if (PQ < QR && PQ < PR) { Console.WriteLine(PQ); } else if (QR < PQ && QR < PR) { Console.WriteLine(QR); } else { Console.WriteLine(PR); } } } }
using System; namespace ConsoleApp1 { class Class1 { static void Main(string[] args) { string S = Console.ReadLine(); string[] PQR = S.Split(' '); int P = int.Parse(PQR[0]); int Q = int.Parse(PQR[1]); int R = int.Parse(PQR[2]); int PQ = P + Q; int QR = Q + R; int PR = P + R; if (PQ <= QR && PQ <= PR) { Console.WriteLine(PQ); } else if (QR <= PQ && QR <= PR) { Console.WriteLine(QR); } else { Console.WriteLine(PR); } } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["-", 0, 57, 75, 57, 15, 16, 31, 16, 17, 18], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 17, 19], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 17, 18], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 19]]
8
154
8
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 { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { // 解答はココに書く // 入力受け取り List<int> intList = cin.ReadIntArray(3).ToList(); WriteLine(intList[0] + intList[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; } } }
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 { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { // 解答はココに書く // 入力受け取り List<int> intList = cin.ReadIntArray(3).ToList(); intList.Sort(); WriteLine(intList[0] + intList[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; } } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
456
6
using System; using System.Linq; public class Test { public static void Main() { // your code goes here var a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); int p = a[0]; int q = a[1]; int r = a[2]; int[] c = new int[3] { p + q, q + r, r + p }; int lowest = 101; for (int b = 0; b != 3; b++) { if (c[b] <= lowest) { lowest = c[b]; } } Console.WriteLine(lowest); } }
using System; using System.Linq; public class Test { public static void Main() { // your code goes here var a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); int p = a[0]; int q = a[1]; int r = a[2]; int[] c = new int[3] { p + q, q + r, r + p }; int lowest = 1000; for (int b = 0; b != 3; b++) { if (c[b] <= lowest) { lowest = c[b]; } } Console.WriteLine(lowest); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
145
2
using System; using System.Linq; using System.Collections.Generic; using System.IO; using System.Text; namespace program { class Program { static void Main() { int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); Console.WriteLine($"{input.Sum() - input.Min()}"); Console.ReadKey(); } } }
using System; using System.Linq; using System.Collections.Generic; using System.IO; using System.Text; namespace program { class Program { static void Main() { int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); Console.WriteLine($"{input.Sum() - input.Max()}"); Console.ReadKey(); } } }
[["-", 0, 284, 0, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 284, 0, 16, 12, 213, 63, 214, 141, 22]]
8
101
2
using System; using System.Linq; using System.Collections.Generic; using System.Text; using static System.Console; using static System.Math; class Program { static void Main(string[] args) { int[] PQR = ReadLineParseIntArray(); int P = PQR[0]; int Q = PQR[1]; int R = PQR[2]; int ans = int.MaxValue; ans = Min(P + Q, ans); ans = Min(P + R, ans); ans = Min(Q + P, ans); WriteLine(ans); } static int[] ReadLineParseIntArray() => ReadLine().Split(' ').Select(int.Parse).ToArray(); }
using System; using System.Linq; using System.Collections.Generic; using System.Text; using static System.Console; using static System.Math; class Program { static void Main(string[] args) { int[] PQR = ReadLineParseIntArray(); int P = PQR[0]; int Q = PQR[1]; int R = PQR[2]; int ans = int.MaxValue; ans = Min(P + Q, ans); ans = Min(P + R, ans); ans = Min(Q + R, ans); WriteLine(ans); } static int[] ReadLineParseIntArray() => ReadLine().Split(' ').Select(int.Parse).ToArray(); }
[["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
155
2
using System; using System.Collections.Generic; using System.Linq; public class Program { static void Main(string[] args) { var array = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); if (array[0] >= array[1]) { Console.WriteLine(10); } Console.WriteLine(0); } }
using System; using System.Collections.Generic; using System.Linq; public class Program { static void Main(string[] args) { var array = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); if (array[0] >= array[1]) { Console.WriteLine(10); } else { Console.WriteLine(0); } } }
[["+", 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
86
3
using System; namespace ConsoleApplication1 { class Program { const long M = 10 ^ 9 + 7; static void Main(string[] args) { string[] inputNum = Console.ReadLine().Split(' '); int X = int.Parse(inputNum[0]); int A = int.Parse(inputNum[1]); if (X > A) { Console.WriteLine("0"); } else { Console.WriteLine("10"); } } } }
using System; namespace ConsoleApplication1 { class Program { const long M = 10 ^ 9 + 7; static void Main(string[] args) { string[] inputNum = Console.ReadLine().Split(' '); int X = int.Parse(inputNum[0]); int A = int.Parse(inputNum[1]); if (X < A) { Console.WriteLine("0"); } else { Console.WriteLine("10"); } } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18]]
8
105
2
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int X = int.Parse(input[0]); int A = int.Parse(input[1]); if (X > A) { Console.WriteLine("0"); } else { Console.WriteLine("10"); } } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int X = int.Parse(input[0]); int A = int.Parse(input[1]); if (X < A) { Console.WriteLine("0"); } else { Console.WriteLine("10"); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18]]
8
98
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public static void Main(string[] args) { string[] b = Input(); int x = int.Parse(b[0]); int a = int.Parse(b[0]); Console.WriteLine(x < a ? "0" : "10"); } 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)); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public static void Main(string[] args) { string[] b = Input(); int x = int.Parse(b[0]); int a = int.Parse(b[1]); Console.WriteLine(x < a ? "0" : "10"); } 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)); } }
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
8
148
2
using System; class Prog { static void Main() { int[] di = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int[] ls = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int n = di[0]; int x = di[1]; int l = 0; int k = 1; for (int i = 0; i < n; i++) { l += ls[i]; k++; if (l > n) { k -= 1; break; } } Console.WriteLine(k); } }
using System; class Prog { static void Main() { int[] di = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int[] ls = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int n = di[0]; int x = di[1]; int l = 0; int k = 1; for (int i = 0; i < n; i++) { l += ls[i]; k++; if (l > x) { k -= 1; break; } } Console.WriteLine(k); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22]]
8
141
2
using System; namespace Sample { class Sample { static void Main(string[] args) { string[] str1 = Console.ReadLine().Split(' '); string[] str2 = Console.ReadLine().Split(' '); int N = int.Parse(str1[0]); long X = long.Parse(str1[1]); int d = 0; int ans = 1; for (int i = 0; i <= N; i++) { d += int.Parse(str2[i - 1]); if (d > X) { break; } ans++; } Console.WriteLine(ans); } } }
using System; namespace Sample { class Sample { static void Main(string[] args) { string[] str1 = Console.ReadLine().Split(' '); string[] str2 = Console.ReadLine().Split(' '); int N = int.Parse(str1[0]); long X = long.Parse(str1[1]); int d = 0; int ans = 1; for (int i = 0; i < N; i++) { d += int.Parse(str2[i]); if (d > X) { break; } ans++; } Console.WriteLine(ans); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
144
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class390 { static void Main() { var NX = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = NX[0], X = NX[1]; var L = Console.ReadLine().Split().Select(int.Parse).ToArray(); var D = new int[N + 1]; for (int i = 0; i < N; i++) { D[i + 1] = D[i] + L[i]; } int count = 0; for (int i = 0; i < N; i++) { if (D[i] <= X) count++; else break; } Console.WriteLine(count); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class390 { static void Main() { var NX = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = NX[0], X = NX[1]; var L = Console.ReadLine().Split().Select(int.Parse).ToArray(); var D = new int[N + 1]; for (int i = 0; i < N; i++) { D[i + 1] = D[i] + L[i]; } int count = 0; for (int i = 0; i < N + 1; i++) { if (D[i] <= X) count++; else break; } Console.WriteLine(count); } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
192
2
using Yorukatsu029.Questions; using Yorukatsu029.Extensions; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace Yorukatsu029.Questions { /// <summary> /// ABC130 B /// </summary> public class QuestionA : AtCoderQuestionBase { public override IEnumerable<object> Solve(TextReader inputStream) { var nx = inputStream.ReadIntArray(); var n = nx[0]; var x = nx[1]; var l = inputStream.ReadIntArray(); var totalDistance = 0; for (int i = 0; i < l.Length; i++) { totalDistance += l[i]; if (totalDistance > x) { yield return i + 1; yield break; } } } } } namespace Yorukatsu029 { class Program { static void Main(string[] args) { IAtCoderQuestion question = new QuestionA(); // 問題に合わせて書き換え var answers = question.Solve(Console.In); foreach (var answer in answers) { Console.WriteLine(answer); } } } } #region Base Classes namespace Yorukatsu029.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 Yorukatsu029.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 Yorukatsu029.Questions; using Yorukatsu029.Extensions; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace Yorukatsu029.Questions { /// <summary> /// ABC130 B /// </summary> public class QuestionA : AtCoderQuestionBase { public override IEnumerable<object> Solve(TextReader inputStream) { var nx = inputStream.ReadIntArray(); var n = nx[0]; var x = nx[1]; var l = inputStream.ReadIntArray(); var totalDistance = 0; for (int i = 0; i < l.Length; i++) { totalDistance += l[i]; if (totalDistance > x) { yield return i + 1; yield break; } } yield return n + 1; } } } namespace Yorukatsu029 { class Program { static void Main(string[] args) { IAtCoderQuestion question = new QuestionA(); // 問題に合わせて書き換え var answers = question.Solve(Console.In); foreach (var answer in answers) { Console.WriteLine(answer); } } } } #region Base Classes namespace Yorukatsu029.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 Yorukatsu029.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
[["+", 8, 201, 0, 195, 8, 196, 0, 285, 0, 286], ["+", 8, 201, 0, 195, 8, 196, 0, 285, 0, 38], ["+", 0, 195, 8, 196, 0, 285, 0, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 285, 0, 16, 17, 72], ["+", 0, 195, 8, 196, 0, 285, 0, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 285, 0, 35]]
8
538
6
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int[] nx = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] l = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] d = new int[nx[0] + 1]; d[0] = 0; for (int i = 1; i < nx[0]; i++) { d[i] = d[i - 1] + l[i - 1]; } int res = 0; for (int i = 0; i < d.Length; i++) { if (d[i] <= nx[1]) res++; } Console.WriteLine(res); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int[] nx = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] l = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] d = new int[nx[0] + 1]; d[0] = 0; for (int i = 1; i < nx[0] + 1; i++) { d[i] = d[i - 1] + l[i - 1]; } int res = 0; for (int i = 0; i < d.Length; i++) { if (d[i] <= nx[1]) res++; } Console.WriteLine(res); } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
197
2
using System; using System.Collections.Generic; using System.Linq; namespace B_Balance { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); var n = int.Parse(input[0]); var x = int.Parse(input[1]); var d = new List<int> { 0 }; var l = new List<int>(); input = Console.ReadLine().Split(' '); for (var i = 0; i < n; i++) { l.Add(int.Parse(input[i])); } for (var i = 1; i < n; i++) { d.Add(d[i - 1] + l[i - 1]); } var quary = d.Where(z => z <= x).ToList(); Console.WriteLine(quary.Count); } } }
using System; using System.Collections.Generic; using System.Linq; namespace B_Balance { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); var n = int.Parse(input[0]); var x = int.Parse(input[1]); var d = new List<int> { 0 }; var l = new List<int>(); input = Console.ReadLine().Split(' '); for (var i = 0; i < n; i++) { l.Add(int.Parse(input[i])); } for (var i = 1; i <= n; i++) { d.Add(d[i - 1] + l[i - 1]); } var quary = d.Where(z => z <= x).ToList(); Console.WriteLine(quary.Count); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
207
2
using System; class Qsort { public static void Main() { string[] str = Console.ReadLine().Split(' '); long n = long.Parse(str[0]); long x = long.Parse(str[1]); string[] str0 = Console.ReadLine().Split(' '); long sum = 0; long count = 1; for (int i = 0; i < n; i++) { long l = long.Parse(str0[i + 1]); sum += l; if (sum > x) { break; } count++; } Console.WriteLine(count); } }
using System; class Qsort { public static void Main() { string[] str = Console.ReadLine().Split(' '); long n = long.Parse(str[0]); long x = long.Parse(str[1]); string[] str0 = Console.ReadLine().Split(' '); long sum = 0; long count = 1; for (int i = 0; i < n; i++) { long l = long.Parse(str0[i]); sum += l; if (sum > x) { break; } count++; } Console.WriteLine(count); } }
[["-", 0, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
142
2
using System; using System.Linq; namespace atcoder { class Program { static void Main(string[] args) { var a = Console.ReadLine().Split(' '); int n = int.Parse(a[0]); int x = int.Parse(a[1]); var tmp = Console.ReadLine().Split(' '); int[] l = tmp.Select(s => int.Parse(s)).ToArray(); int bound = 0; int cnt = 1; for (int i = 0; i < n + 1; i++) { bound = bound + l[i]; if (bound <= x) { cnt++; } else { break; } } Console.WriteLine(cnt); } } }
using System; using System.Linq; namespace atcoder { class Program { static void Main(string[] args) { var a = Console.ReadLine().Split(' '); int n = int.Parse(a[0]); int x = int.Parse(a[1]); var tmp = Console.ReadLine().Split(' '); int[] l = tmp.Select(s => int.Parse(s)).ToArray(); int bound = 0; int cnt = 1; for (int i = 0; i < n; i++) { bound = bound + l[i]; if (bound <= x) { cnt++; } else { break; } } Console.WriteLine(cnt); } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
168
2
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCorder { class Program { static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; var X = cin.ReadInt; var L = cin.ReadIntArray(N); var ans = 1; var total = 0; while (total + L[ans - 1] <= X) { total += L[ans - 1]; ans++; } 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; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCorder { class Program { static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; var X = cin.ReadInt; var L = cin.ReadIntArray(N); var ans = 1; var total = 0; while (ans <= N && total + L[ans - 1] <= X) { total += L[ans - 1]; ans++; } 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; } } }
[["+", 8, 196, 0, 52, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 52, 15, 16, 31, 16, 17, 19], ["+", 8, 196, 0, 52, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 98]]
8
488
4
using System; using System.Collections.Generic; using System.Collections; using System.Linq; namespace ProjectContest { class Test { static void Main() { var nx = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt32); int n = nx[0], x = nx[1]; var L = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt32).ToList(); int kq = 1; L.Insert(0, 0); for (int i = 1; i < n; i++) { L[i] = L[i] + L[i - 1]; if (L[i] <= x) kq++; else break; } Console.WriteLine(kq); } } }
using System; using System.Collections.Generic; using System.Collections; using System.Linq; namespace ProjectContest { class Test { static void Main() { var nx = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt32); int n = nx[0], x = nx[1]; var L = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt32).ToList(); int kq = 1; L.Insert(0, 0); for (int i = 1; i < n + 1; i++) { L[i] = L[i] + L[i - 1]; if (L[i] <= x) kq++; else break; } Console.WriteLine(kq); } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
167
2
using System; using System.Linq; using System.Collections.Generic; public class Hello { public static void Main(string[] args) { // 自分の得意な言語で // Let's チャレンジ!! int count = 0; var dList = new List<int>(); var arg1 = System.Console.ReadLine(); string[] valueNX = arg1.Split(' '); var arg2 = System.Console.ReadLine(); string[] valueL = arg2.Split(' '); for (int i = 0; i < Int32.Parse(valueNX[0]); i++) { if (i == 0) { dList.Add(0); } else { dList.Add(dList[i - 1] + Int32.Parse(valueL[i])); } if (dList[i] <= Int32.Parse(valueNX[1])) { count = count + 1; } } System.Console.WriteLine(count); } }
using System; using System.Linq; using System.Collections.Generic; public class Hello { public static void Main(string[] args) { // 自分の得意な言語で // Let's チャレンジ!! int count = 0; var dList = new List<int>(); var arg1 = System.Console.ReadLine(); string[] valueNX = arg1.Split(' '); var arg2 = System.Console.ReadLine(); string[] valueL = arg2.Split(' '); for (int i = 0; i <= Int32.Parse(valueNX[0]); i++) { if (i == 0) { dList.Add(0); } else { dList.Add(dList[i - 1] + Int32.Parse(valueL[i - 1])); } if (dList[i] < Int32.Parse(valueNX[1]) + 1) { count = count + 1; } } System.Console.WriteLine(count); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
198
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Q2 { class Program { static void Main(string[] args) { string line = Console.ReadLine(); string[] strs = line.Split(' '); int N = int.Parse(strs[0]); int X = int.Parse(strs[1]); line = Console.ReadLine(); strs = line.Split(' '); int sum = 0; int count = 0; for (int i = 0; i < N; i++) { sum += int.Parse(strs[i]); if (sum <= X) count++; } Console.WriteLine(count); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Q2 { class Program { static void Main(string[] args) { string line = Console.ReadLine(); string[] strs = line.Split(' '); int N = int.Parse(strs[0]); int X = int.Parse(strs[1]); line = Console.ReadLine(); strs = line.Split(' '); int sum = 0; int count = 1; for (int i = 0; i < N; i++) { sum += int.Parse(strs[i]); if (sum <= X) count++; } Console.WriteLine(count); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
168
2
using System; using System.Collections.Generic; using static AtCoderer.Exter; using static System.Math; using System.Linq; namespace AtCoderer { public class App { public static void Solve() { var va = readarr[1]; int sum = 0, c = 0; foreach (var l in readarr) { sum += l; if (sum <= va) c++; } Console.WriteLine(c); } public static void Main(string[] args) { Solve(); Console.ReadKey(); } } public static class Exter { 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 void EnumArr<t>(this IEnumerable<t> v) { Console.WriteLine(string.Join(",", v)); } public static string ToString(this IEnumerable<char> v) { return string.Join(",", v); } public static int[] readarr { get { return Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); } } public class UnionFind { private int[] Parent; private int GetRoot(int v) { if (Parent[v] < 0) return v; else return Parent[v] = GetRoot(Parent[v]); } public UnionFind(int size) { Parent = new int[size]; for (int i = 0; i < size; i++) Parent[i] = -1; } public bool AreGrouped(int a, int b) { return GetRoot(a) == GetRoot(b); } public void Connect(int a, int b) { a = GetRoot(a); b = GetRoot(b); if (a == b) return; if (Parent[b] < Parent[a]) { Parent[b] += Parent[a]; Parent[a] = b; } else { Parent[a] += Parent[b]; Parent[b] = a; } } public int GetGroupSize(int a) { return -Parent[GetRoot(a)]; } } } }
using System; using System.Collections.Generic; using static AtCoderer.Exter; using static System.Math; using System.Linq; namespace AtCoderer { public class App { public static void Solve() { var va = readarr[1]; int sum = 0, c = 1; foreach (var l in readarr) { sum += l; if (sum <= va) c++; } Console.WriteLine(c); } public static void Main(string[] args) { Solve(); Console.ReadKey(); } } public static class Exter { 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 void EnumArr<t>(this IEnumerable<t> v) { Console.WriteLine(string.Join(",", v)); } public static string ToString(this IEnumerable<char> v) { return string.Join(",", v); } public static int[] readarr { get { return Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); } } public class UnionFind { private int[] Parent; private int GetRoot(int v) { if (Parent[v] < 0) return v; else return Parent[v] = GetRoot(Parent[v]); } public UnionFind(int size) { Parent = new int[size]; for (int i = 0; i < size; i++) Parent[i] = -1; } public bool AreGrouped(int a, int b) { return GetRoot(a) == GetRoot(b); } public void Connect(int a, int b) { a = GetRoot(a); b = GetRoot(b); if (a == b) return; if (Parent[b] < Parent[a]) { Parent[b] += Parent[a]; Parent[a] = b; } else { Parent[a] += Parent[b]; Parent[b] = a; } } public int GetGroupSize(int a) { return -Parent[GetRoot(a)]; } } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
556
2
using System; namespace AtCoderABC130B { class Program { static void Main(string[] args) { int ans = 1; string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); int X = int.Parse(s[1]); s = Console.ReadLine().Split(' '); int D = 0; for (int i = 0; i < N + 1; i++) { D += int.Parse(s[i]); if (D > X) break; ans++; } Console.WriteLine(ans.ToString()); } } }
using System; namespace AtCoderABC130B { class Program { static void Main(string[] args) { int ans = 1; string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); int X = int.Parse(s[1]); s = Console.ReadLine().Split(' '); int D = 0; for (int i = 0; i < N; i++) { D += int.Parse(s[i]); if (D > X) break; ans++; } Console.WriteLine(ans.ToString()); } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
143
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC130B { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(); int N = int.Parse(input[0]); int X = int.Parse(input[1]); string[] input2 = Console.ReadLine().Split(); int[] L = new int[N + 1]; L[0] = 0; for (int i = 1; i <= N; i++) { L[i] = int.Parse(input2[i - 1]); } //累積を計算して、座標を求める  int[] D = new int[N + 1]; D[0] = 0; int count = 0; for (int i = 1; i <= N; i++) { D[i] = D[i - 1] + L[i - 1]; if (D[i] <= X) { count++; //もし座標がX以下だったらカウントを1増やす } else { break; //もし座標がXを超えたら終わる } } Console.WriteLine(count); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC130B { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(); int N = int.Parse(input[0]); int X = int.Parse(input[1]); string[] input2 = Console.ReadLine().Split(); int[] L = new int[N + 1]; L[0] = 0; for (int i = 1; i <= N; i++) { L[i] = int.Parse(input2[i - 1]); } //累積を計算して、座標を求める // Dは2~(N+1)まで計算される int[] D = new int[N + 2]; D[0] = 0; int count = 0; for (int i = 1; i <= N + 1; i++) { D[i] = D[i - 1] + L[i - 1]; if (D[i] <= X) { count++; //もし座標がX以下だったらカウントを1増やす } else { break; //もし座標がXを超えたら終わる } } Console.WriteLine(count); } } }
[["-", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
244
4
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var sum = 0; int i = 0; List<int> L = new List<int>(); string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int X = int.Parse(input[1]); string[] str = Console.ReadLine().Split(' '); foreach (string s in str) { if (sum > X) { break; } else if (sum == X) { L.Add(int.Parse(s)); sum += int.Parse(s); i += 1; break; } else if (sum < X) { L.Add(int.Parse(s)); sum += L[i]; i += 1; } } if (sum < X) { Console.WriteLine(i + 1); } else if (sum == X) { Console.WriteLine(i); } else if (sum > X) { Console.WriteLine(i); } } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var sum = 0; int i = 0; List<int> L = new List<int>(); string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int X = int.Parse(input[1]); string[] str = Console.ReadLine().Split(' '); foreach (string s in str) { if (sum > X) { break; } else if (sum == X) { L.Add(int.Parse(s)); sum += int.Parse(s); i += 1; break; } else if (sum < X) { L.Add(int.Parse(s)); sum += L[i]; i += 1; } } if (sum < X) { Console.WriteLine(i + 1); } else if (sum == X) { Console.WriteLine(i + 1); } else if (sum > X) { Console.WriteLine(i); } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
252
2
using System; namespace atcoder1 { class problem2 { public static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int N, X; N = int.Parse(input[0]); X = int.Parse(input[1]); string[] L = Console.ReadLine().Split(' '); int[] l = new int[L.Length]; for (int i = 0; i < L.Length; i++) { l[i] = int.Parse(L[i]); } int d = 0; int counter = 0; for (int i = 0; i < N + 1; i++) { if (i > 0) { d = d + l[i - 1]; } if (d > X) { break; } else { counter = i; } } Console.WriteLine(counter); } } }
using System; namespace atcoder1 { class problem2 { public static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int N, X; N = int.Parse(input[0]); X = int.Parse(input[1]); string[] L = Console.ReadLine().Split(' '); int[] l = new int[L.Length]; for (int i = 0; i < L.Length; i++) { l[i] = int.Parse(L[i]); } int d = 0; int counter = 0; for (int i = 0; i < N + 1; i++) { if (i > 0) { d = d + l[i - 1]; } if (d > X) { break; } else { counter = i; } } Console.WriteLine(counter + 1); } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
205
2
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 { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { // 解答はココに書く // 入力 var fIntArr = cin.ReadIntArray(2); var n = fIntArr[0]; var x = fIntArr[1]; var lList = cin.ReadIntArray(n).ToList(); var point = 0; var result = 1; for (int i = 1; i < n + 1; i++) { point += lList[i - 1]; if (point > x) { result += i - 1; break; } } WriteLine(result); } } 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 AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { // 解答はココに書く // 入力 var fIntArr = cin.ReadIntArray(2); var n = fIntArr[0]; var x = fIntArr[1]; var lList = cin.ReadIntArray(n).ToList(); var point = 0; var result = 1; for (int i = 1; i < n + 1; i++) { point += lList[i - 1]; if (point <= x) { result += 1; } } WriteLine(result); } } 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, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94]]
8
524
6
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder_B { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' ').Select(y => int.Parse(y)); var x = input.Skip(1).First(); var l = Console.ReadLine().Split(' ').Select(y => int.Parse(y)).ToArray(); var ans = Enumerable.Repeat(l, l.Length) .Select((y, i) => y.Take(i)) .TakeWhile((y, i) => y.Sum() <= x) .Count(); Console.WriteLine(ans); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder_B { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' ').Select(y => int.Parse(y)); var x = input.Skip(1).First(); var l = Console.ReadLine().Split(' ').Select(y => int.Parse(y)).ToArray(); var ans = Enumerable.Repeat(l, l.Length) .Select((y, i) => y.Take(i + 1)) .TakeWhile((y, i) => y.Sum() <= x) .Count() + 1; Console.WriteLine(ans); } } }
[["+", 8, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 8, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
183
4
using System; using System.Collections.Generic; using System.IO; using System.Linq; using Extensions; using static System.Math; using static Extensions.MathExtension; using static Extensions.ConsoleInputExtension; using static Extensions.ConsoleOutputExtension; class Solver { public void Solve() { // Solve Code Here int N = Cin, X = Cin; var L = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var D = new int[N + 1]; for (int i = 0; i < N; i++) D[i + 1] = D[i] + L[i]; int count = 1; while (count < N && D[count] <= X) { count++; } Coutln(count); } // Other Functions Here } class EntryPoint { static void Main(string[] args) { new Solver().Solve(); Flush(); } } class PriorityQueue<T> { private readonly List<Tuple<int, T>> _list = new List<Tuple<int, T>>(); public PriorityQueue() {} public void Push(T item, int priority) { var itemIndex = _list.Count; _list.Add(Tuple.Create(priority, item)); int parentIndex; while ((parentIndex = GetParentIndex(itemIndex)) != -1 && priority > _list[parentIndex].Item1) { Swap(itemIndex, parentIndex); itemIndex = parentIndex; } } private int GetParentIndex(int index) { if (index == 0) return -1; return ((index + 1) >> 1) - 1; } private Tuple<int, int> GetChildrenIndex(int index) { var item2 = (index + 1) << 1; var item1 = item2 - 1; return item2 >= _list.Count ? null : Tuple.Create(item1, item2); } public T Pop() { var item = _list[0].Item2; Tuple<int, int> childrenIndex; int index = 0; while ((childrenIndex = GetChildrenIndex(index)) != null) { if (_list[childrenIndex.Item1].Item1 > _list[childrenIndex.Item2].Item1) _list[index] = _list[childrenIndex.Item1]; else _list[index] = _list[childrenIndex.Item2]; } return item; } public T Peek() { return _list[0].Item2; } private void Swap(int index1, int index2) { var tmp = _list[index1]; _list[index1] = _list[index2]; _list[index2] = tmp; } } struct Rational { private long _numerator; private long _denominator; public long Numerator => _numerator; public long Denominator => _denominator; public Rational(long numerator, long denominator) { var gcd = GCD(numerator, denominator); _numerator = numerator / gcd; _denominator = denominator / gcd; } public static Rational operator +(Rational a, Rational b) { return new Rational(a._numerator * b._denominator + b._numerator * a._denominator, a._denominator * b._denominator); } public static Rational operator -(Rational a, Rational b) { return new Rational(a._numerator * b._denominator - b._numerator * a._denominator, a._denominator * b._denominator); } public static Rational operator *(Rational a, Rational b) { return new Rational(a._numerator * b._numerator, a._denominator * b._denominator); } public static Rational operator /(Rational a, Rational b) { return new Rational(a._numerator * b._denominator, a._denominator * b._numerator); } public static explicit operator Rational(int i) { return new Rational(i, 1); } public static explicit operator Rational(long l) { return new Rational(l, 1); } public static explicit operator Rational(double d) { long denominator = 1; while (d % 1 != 0) { denominator *= 2; d *= 2; } return new Rational((long)d, denominator); } public static explicit operator Rational(float f) { long denominator = 1; while (f % 1 != 0) { denominator *= 2; f *= 2; } return new Rational((long)f, denominator); } } class UnionFind { private readonly int[] _array; public UnionFind(int N) { _array = new int[N]; for (int i = 0; i < N; i++) { _array[i] = i; } } public int GetRootNode(int n) { if (_array[n] == n) return n; return _array[n] = GetRootNode(_array[n]); } public void UnionGroup(int a, int b) { var rootA = GetRootNode(a); var rootB = GetRootNode(b); if (rootA == rootB) return; _array[rootA] = rootB; } public bool IsSameGroup(int a, int b) => GetRootNode(a) == GetRootNode(b); public bool IsRoot(int n) => _array[n] == n; } namespace Extensions { public class ConsoleInputExtension { private static readonly ConsoleInputExtension _cin = new ConsoleInputExtension(); public static ConsoleInputExtension Cin => _cin; private static readonly Queue<string> _inputQueue = new Queue<string>(); private ConsoleInputExtension() {} public static implicit operator string(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return _inputQueue.Dequeue(); } public static implicit operator int(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return int.Parse(_inputQueue.Dequeue()); } public static implicit operator long(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return long.Parse(_inputQueue.Dequeue()); } public static implicit operator float(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return float.Parse(_inputQueue.Dequeue()); } public static implicit operator double(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return double.Parse(_inputQueue.Dequeue()); } } public static class ConsoleOutputExtension { private static StreamWriter _writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public static void Cout(object o) { _writer.Write(o); } public static void CoutF(object o) { _writer.Write(o); _writer.Flush(); } public static void Coutln(object o) { _writer.WriteLine(o); } public static void CoutlnF(object o) { _writer.WriteLine(o); _writer.Flush(); } public static void Flush() { _writer.Flush(); } } public static class MathExtension { //最小公倍数 public static int LCM(int num1, int num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } public static long LCM(long num1, long num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } //最大公約数 public static int GCD(int num1, int num2) { int a = Math.Max(num1, num2); int b = Math.Min(num1, num2); int mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } public static long GCD(long num1, long num2) { long a = Math.Max(num1, num2); long b = Math.Min(num1, num2); long mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } } public static class EnumerableExtension { public delegate void Function<in T>(T val); public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function) { foreach (var x in enumerable) { function(x); } } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using Extensions; using static System.Math; using static Extensions.MathExtension; using static Extensions.ConsoleInputExtension; using static Extensions.ConsoleOutputExtension; class Solver { public void Solve() { // Solve Code Here int N = Cin, X = Cin; var L = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var D = new int[N + 1]; for (int i = 0; i < N; i++) D[i + 1] = D[i] + L[i]; int count = 1; while (count < N + 1 && D[count] <= X) { count++; } Coutln(count); } // Other Functions Here } class EntryPoint { static void Main(string[] args) { new Solver().Solve(); Flush(); } } class PriorityQueue<T> { private readonly List<Tuple<int, T>> _list = new List<Tuple<int, T>>(); public PriorityQueue() {} public void Push(T item, int priority) { var itemIndex = _list.Count; _list.Add(Tuple.Create(priority, item)); int parentIndex; while ((parentIndex = GetParentIndex(itemIndex)) != -1 && priority > _list[parentIndex].Item1) { Swap(itemIndex, parentIndex); itemIndex = parentIndex; } } private int GetParentIndex(int index) { if (index == 0) return -1; return ((index + 1) >> 1) - 1; } private Tuple<int, int> GetChildrenIndex(int index) { var item2 = (index + 1) << 1; var item1 = item2 - 1; return item2 >= _list.Count ? null : Tuple.Create(item1, item2); } public T Pop() { var item = _list[0].Item2; Tuple<int, int> childrenIndex; int index = 0; while ((childrenIndex = GetChildrenIndex(index)) != null) { if (_list[childrenIndex.Item1].Item1 > _list[childrenIndex.Item2].Item1) _list[index] = _list[childrenIndex.Item1]; else _list[index] = _list[childrenIndex.Item2]; } return item; } public T Peek() { return _list[0].Item2; } private void Swap(int index1, int index2) { var tmp = _list[index1]; _list[index1] = _list[index2]; _list[index2] = tmp; } } struct Rational { private long _numerator; private long _denominator; public long Numerator => _numerator; public long Denominator => _denominator; public Rational(long numerator, long denominator) { var gcd = GCD(numerator, denominator); _numerator = numerator / gcd; _denominator = denominator / gcd; } public static Rational operator +(Rational a, Rational b) { return new Rational(a._numerator * b._denominator + b._numerator * a._denominator, a._denominator * b._denominator); } public static Rational operator -(Rational a, Rational b) { return new Rational(a._numerator * b._denominator - b._numerator * a._denominator, a._denominator * b._denominator); } public static Rational operator *(Rational a, Rational b) { return new Rational(a._numerator * b._numerator, a._denominator * b._denominator); } public static Rational operator /(Rational a, Rational b) { return new Rational(a._numerator * b._denominator, a._denominator * b._numerator); } public static explicit operator Rational(int i) { return new Rational(i, 1); } public static explicit operator Rational(long l) { return new Rational(l, 1); } public static explicit operator Rational(double d) { long denominator = 1; while (d % 1 != 0) { denominator *= 2; d *= 2; } return new Rational((long)d, denominator); } public static explicit operator Rational(float f) { long denominator = 1; while (f % 1 != 0) { denominator *= 2; f *= 2; } return new Rational((long)f, denominator); } } class UnionFind { private readonly int[] _array; public UnionFind(int N) { _array = new int[N]; for (int i = 0; i < N; i++) { _array[i] = i; } } public int GetRootNode(int n) { if (_array[n] == n) return n; return _array[n] = GetRootNode(_array[n]); } public void UnionGroup(int a, int b) { var rootA = GetRootNode(a); var rootB = GetRootNode(b); if (rootA == rootB) return; _array[rootA] = rootB; } public bool IsSameGroup(int a, int b) => GetRootNode(a) == GetRootNode(b); public bool IsRoot(int n) => _array[n] == n; } namespace Extensions { public class ConsoleInputExtension { private static readonly ConsoleInputExtension _cin = new ConsoleInputExtension(); public static ConsoleInputExtension Cin => _cin; private static readonly Queue<string> _inputQueue = new Queue<string>(); private ConsoleInputExtension() {} public static implicit operator string(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return _inputQueue.Dequeue(); } public static implicit operator int(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return int.Parse(_inputQueue.Dequeue()); } public static implicit operator long(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return long.Parse(_inputQueue.Dequeue()); } public static implicit operator float(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return float.Parse(_inputQueue.Dequeue()); } public static implicit operator double(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return double.Parse(_inputQueue.Dequeue()); } } public static class ConsoleOutputExtension { private static StreamWriter _writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public static void Cout(object o) { _writer.Write(o); } public static void CoutF(object o) { _writer.Write(o); _writer.Flush(); } public static void Coutln(object o) { _writer.WriteLine(o); } public static void CoutlnF(object o) { _writer.WriteLine(o); _writer.Flush(); } public static void Flush() { _writer.Flush(); } } public static class MathExtension { //最小公倍数 public static int LCM(int num1, int num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } public static long LCM(long num1, long num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } //最大公約数 public static int GCD(int num1, int num2) { int a = Math.Max(num1, num2); int b = Math.Min(num1, num2); int mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } public static long GCD(long num1, long num2) { long a = Math.Max(num1, num2); long b = Math.Min(num1, num2); long mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } } public static class EnumerableExtension { public delegate void Function<in T>(T val); public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function) { foreach (var x in enumerable) { function(x); } } } }
[["+", 0, 52, 15, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 52, 15, 16, 31, 16, 12, 16, 12, 203]]
8
1,744
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace B { class Program { static void Main(string[] args) { int[] vs = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int n = vs[0]; int x = vs[1]; int sum = 0; vs = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int cnt = 0; for (int i = 0; i < n; i++) { sum += vs[i]; if (sum > x) { cnt = i; break; } } Console.WriteLine(cnt + 1); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace B { class Program { static void Main(string[] args) { int[] vs = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int n = vs[0]; int x = vs[1]; int sum = 0; vs = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int cnt = 0; for (int i = 0; i < n; i++) { sum += vs[i]; if (sum <= x) { cnt++; } else { break; } } Console.WriteLine(cnt + 1); } } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 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
183
8
using System; public class Program { public static void Main() { var input = Console.ReadLine(); var split1 = input.Split(' '); var count = int.Parse(split1[0]); var cap = int.Parse(split1[1]); int current = 0; int result = 0; int target = 0; var split = Console.ReadLine().Split(' '); foreach (var tgt in split) { target = int.Parse(tgt); current += target; if (current > cap) { break; } result++; } Console.WriteLine(result); // nsole.WriteLine("Hello World"); } }
using System; public class Program { public static void Main() { var input = Console.ReadLine(); var split1 = input.Split(' '); var count = int.Parse(split1[0]); var cap = int.Parse(split1[1]); int current = 0; int result = 1; int target = 0; var split = Console.ReadLine().Split(' '); foreach (var tgt in split) { target = int.Parse(tgt); current += target; if (current > cap) { break; } result++; } Console.WriteLine(result); // nsole.WriteLine("Hello World"); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
137
2
using System; using System.Collections.Generic; using System.Linq; public class Program { static void Main(string[] args) { var array = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var jumpArray = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var count = 1; var total = 0; for (int i = 0; i < array[1]; i++) { total += jumpArray[i]; if (total <= array[1]) { count++; } } Console.WriteLine(count); } }
using System; using System.Collections.Generic; using System.Linq; public class Program { static void Main(string[] args) { var array = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var jumpArray = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var count = 1; var total = 0; for (int i = 0; i < array[0]; i++) { total += jumpArray[i]; if (total <= array[1]) { count++; } } Console.WriteLine(count); } }
[["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
8
142
2
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var vals = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList(); int N = vals[0]; int X = vals[1]; int cnt = 1; int d = 0; var L = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList(); for (int i = 1; i < N; i++) { d += L[i]; if (d > X) break; cnt++; } Console.WriteLine(cnt); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var vals = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList(); int N = vals[0]; int X = vals[1]; int cnt = 1; int d = 0; var L = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList(); for (int i = 0; i < N; i++) { d += L[i]; if (d > X) break; cnt++; } Console.WriteLine(cnt); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
155
2
using System; using System.Collections.Generic; using System.Linq; class ABC130B { public static void Main() { var NX = Console.ReadLine().Split(' ').Select(int.Parse); var Ln = Console.ReadLine().Split(' ').Select(int.Parse); var count = 1; var sum = 0; foreach (var l in Ln) { sum += l; if (sum >= NX.ElementAt(1)) { break; } count++; } Console.WriteLine(count); } }
using System; using System.Collections.Generic; using System.Linq; class ABC130B { public static void Main() { var NX = Console.ReadLine().Split(' ').Select(int.Parse); var Ln = Console.ReadLine().Split(' ').Select(int.Parse); var count = 1; var sum = 0; foreach (var l in Ln) { sum += l; if (sum > NX.ElementAt(1)) { break; } count++; } Console.WriteLine(count); } }
[["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 47]]
8
121
2
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 { const int MOD = 1000000007; 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 x = cin.ReadInt; var l = cin.ReadIntArray(n); var line = 0; var ans = 1; for (int i = 1; i < n; i++) { line += l[i - 1]; if (line <= x) { 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; } } } }
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 { const int MOD = 1000000007; 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 x = cin.ReadInt; var l = cin.ReadIntArray(n); var line = 0; var ans = 1; for (int i = 0; i < n; i++) { line += l[i]; if (line <= x) { 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; } } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
607
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC130A { class Program { static void Main(string[] args) { var nx = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var n = nx[0]; var x = nx[1]; var l = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var d = 0; var result = 0; for (var i = 1; i < n + 1; i++) { d = d + l[i - 1]; if (d > x) { result = i; break; } } Console.WriteLine(result); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC130A { class Program { static void Main(string[] args) { var nx = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var n = nx[0]; var x = nx[1]; var l = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var d = 0; var result = n + 1; for (var i = 1; i < n + 1; i++) { d = d + l[i - 1]; if (d > x) { result = i; break; } } Console.WriteLine(result); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 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, 203]]
8
176
4
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace ABC130B { class Program { static void Solve(Input input) { var n = input.NextInt(); var x = input.NextInt(); var l = input.NextInt(n); var pos = 0; for (int i = 1; i < n; i++) { pos = pos + l[i - 1]; if (pos > x) { Console.WriteLine(i); return; } } Console.WriteLine(l.Length + 1); } #region Competitive Template static readonly int MOD = (int)1e9 + 7; public static void Main(string[] args) { // 出力が少ないときはこれをセットする方が時間かかるけれど // その場合は出力がボトルネックになっていないので、まあ良しとする var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // input.SetText(""); Solve(input); Console.Out.Flush(); } class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する // スペース単独指定の方がもちろん早い static readonly char[] separator = { ' ', '\r', '\n' }; Queue<string> q { get; set; } StreamReader sr; /// <summary> /// 特定のファイルから読み出したい場合はpath指定する /// </summary> /// <param name="path"></param> public Input(string path = "") { q = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } return true; } /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> bool read() { var s = sr.ReadLine(); if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public string Next() { if (!q.Any()) { if (!read()) { return ""; } } return q.Dequeue(); } /// <summary> /// 指定個数queueにたまるまでenqueueし続ける /// </summary> /// <param name="n"></param> /// <returns></returns> bool accumulate(int n) { while (q.Count() < n) { if (!read()) return false; } return true; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); /// <summary> /// n個の要素をparseして、それぞれにoffsetをaddした配列を返す /// </summary> /// <typeparam name="T"></typeparam> /// <param name="n"></param> /// <param name="offset"></param> /// <param name="parse"></param> /// <param name="add"></param> /// <returns></returns> T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(q.Dequeue()), offset); return a; } public string[] Next(int n) => NextT(n, "", x => x, (x, y) => x); public int[] NextInt(int n, int offset = 0) => NextT(n, offset, int.Parse, (x, y) => x + y); public long[] NextLong(int n, long offset = 0) => NextT(n, offset, long.Parse, (x, y) => x + y); public double[] NextDouble(int n, double offset = 0.0) => NextT(n, offset, double.Parse, (x, y) => x + y); } static class Utils { public static void Print<T>(IEnumerable<T> ie, string sep = " ") => Console.WriteLine(string.Join(sep, ie)); public static void Print<T>(params T[] objs) => Print(objs); public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); public static void Swap<T>(ref T x, ref T y) where T : struct { var t = x; x = y; y = t; } public static void Swap<T>(IList<T> list, int i, int j) where T : struct { var t = list[i]; list[i] = list[j]; list[j] = t; } /// <summary> /// vでfillされたT[d1][d2]配列を作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="v"></param> /// <returns></returns> public static T[][] Create2DArray<T>(int d1, int d2, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(v, d2).ToArray()) .ToArray(); } /// <summary> /// vでfillされたT[d1][d2][d3]配列を作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="d3"></param> /// <param name="v"></param> /// <returns></returns> public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(0, d2) .Select(__ => Enumerable.Repeat(v, d3).ToArray()) .ToArray()) .ToArray(); } } #endregion } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace ABC130B { class Program { static void Solve(Input input) { var n = input.NextInt(); var x = input.NextInt(); var l = input.NextInt(n); var pos = 0; for (int i = 1; i <= n; i++) { pos = pos + l[i - 1]; if (pos > x) { Console.WriteLine(i); return; } } Console.WriteLine(l.Length + 1); } #region Competitive Template static readonly int MOD = (int)1e9 + 7; public static void Main(string[] args) { // 出力が少ないときはこれをセットする方が時間かかるけれど // その場合は出力がボトルネックになっていないので、まあ良しとする var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // input.SetText(""); Solve(input); Console.Out.Flush(); } class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する // スペース単独指定の方がもちろん早い static readonly char[] separator = { ' ', '\r', '\n' }; Queue<string> q { get; set; } StreamReader sr; /// <summary> /// 特定のファイルから読み出したい場合はpath指定する /// </summary> /// <param name="path"></param> public Input(string path = "") { q = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } return true; } /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> bool read() { var s = sr.ReadLine(); if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public string Next() { if (!q.Any()) { if (!read()) { return ""; } } return q.Dequeue(); } /// <summary> /// 指定個数queueにたまるまでenqueueし続ける /// </summary> /// <param name="n"></param> /// <returns></returns> bool accumulate(int n) { while (q.Count() < n) { if (!read()) return false; } return true; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); /// <summary> /// n個の要素をparseして、それぞれにoffsetをaddした配列を返す /// </summary> /// <typeparam name="T"></typeparam> /// <param name="n"></param> /// <param name="offset"></param> /// <param name="parse"></param> /// <param name="add"></param> /// <returns></returns> T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(q.Dequeue()), offset); return a; } public string[] Next(int n) => NextT(n, "", x => x, (x, y) => x); public int[] NextInt(int n, int offset = 0) => NextT(n, offset, int.Parse, (x, y) => x + y); public long[] NextLong(int n, long offset = 0) => NextT(n, offset, long.Parse, (x, y) => x + y); public double[] NextDouble(int n, double offset = 0.0) => NextT(n, offset, double.Parse, (x, y) => x + y); } static class Utils { public static void Print<T>(IEnumerable<T> ie, string sep = " ") => Console.WriteLine(string.Join(sep, ie)); public static void Print<T>(params T[] objs) => Print(objs); public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); public static void Swap<T>(ref T x, ref T y) where T : struct { var t = x; x = y; y = t; } public static void Swap<T>(IList<T> list, int i, int j) where T : struct { var t = list[i]; list[i] = list[j]; list[j] = t; } /// <summary> /// vでfillされたT[d1][d2]配列を作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="v"></param> /// <returns></returns> public static T[][] Create2DArray<T>(int d1, int d2, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(v, d2).ToArray()) .ToArray(); } /// <summary> /// vでfillされたT[d1][d2][d3]配列を作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="d3"></param> /// <param name="v"></param> /// <returns></returns> public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(0, d2) .Select(__ => Enumerable.Repeat(v, d3).ToArray()) .ToArray()) .ToArray(); } } #endregion } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
1,202
2
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass : Scanner { static void Main() { var (W, H, x, y) = ReadStream<double, double, double, double>(); var ans = (W + H) / 2; if (W / 2 == x && H / 2 == y) { WriteLine($"{ans} {1}"); } else { WriteLine($"{ans} {0}"); } } } class Scanner { public static int RInt() => int.Parse(Console.ReadLine()); public static long RLong() => long.Parse(Console.ReadLine()); public static string RString() => Console.ReadLine(); public static double RDouble() => double.Parse(Console.ReadLine()); public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); public static string[] RStrings() => Console.ReadLine().Split(); // public static string[] RStrings(Func<string, string> func) => // Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadStream<T1>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); return r1; } public static (T1, T2) ReadStream<T1, T2>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); return (r1, r2); } public static (T1, T2, T3) ReadStream<T1, T2, T3>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); return (r1, r2, r3); } public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[3], typeof(T4)); return (r1, r2, r3, r4); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass : Scanner { static void Main() { var (W, H, x, y) = ReadStream<double, double, double, double>(); var ans = (W * H) / 2; if (W / 2 == x && H / 2 == y) { WriteLine($"{ans} {1}"); } else { WriteLine($"{ans} {0}"); } } } class Scanner { public static int RInt() => int.Parse(Console.ReadLine()); public static long RLong() => long.Parse(Console.ReadLine()); public static string RString() => Console.ReadLine(); public static double RDouble() => double.Parse(Console.ReadLine()); public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); public static string[] RStrings() => Console.ReadLine().Split(); // public static string[] RStrings(Func<string, string> func) => // Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadStream<T1>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); return r1; } public static (T1, T2) ReadStream<T1, T2>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); return (r1, r2); } public static (T1, T2, T3) ReadStream<T1, T2, T3>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); return (r1, r2, r3); } public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[3], typeof(T4)); return (r1, r2, r3, r4); } }
[["-", 0, 212, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 17, 48]]
8
743
2
using System; using System.Collections.Generic; using System.Linq; using static System.Console; class Program { static void Main(string[] args) { var WHxy = ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray(); var (W, H) = (WHxy[0], WHxy[1]); var (x, y) = (WHxy[2], WHxy[3]); var area = ((double)W * H) / 2.0; var isMultiple = (W == x * 2 || H == y * 2) ? 1 : 0; WriteLine($"{area} {isMultiple}"); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; class Program { static void Main(string[] args) { var WHxy = ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray(); var (W, H) = (WHxy[0], WHxy[1]); var (x, y) = (WHxy[2], WHxy[3]); var area = ((double)W * H) / 2.0; var isMultiple = (W == x * 2 && H == y * 2) ? 1 : 0; WriteLine($"{area} {isMultiple}"); } }
[["-", 0, 212, 0, 41, 15, 23, 0, 16, 17, 106], ["+", 0, 212, 0, 41, 15, 23, 0, 16, 17, 98]]
8
152
2
using System; namespace C { class Program { static void Main(string[] args) { string[] In = Console.ReadLine().Split(' '); long w = int.Parse(In[0]); long h = int.Parse(In[1]); long x = int.Parse(In[2]); long y = int.Parse(In[3]); int v = (h * x == w * y) ? 1 : 0; Console.WriteLine((double)w * h / 2 + " " + v); } } }
using System; namespace C { class Program { static void Main(string[] args) { string[] In = Console.ReadLine().Split(' '); long w = int.Parse(In[0]); long h = int.Parse(In[1]); long x = int.Parse(In[2]); long y = int.Parse(In[3]); int v = (2 * x == w && 2 * y == h) ? 1 : 0; Console.WriteLine((double)w * h / 2 + " " + v); } } }
[["-", 0, 41, 15, 23, 0, 16, 31, 16, 31, 22], ["+", 15, 23, 0, 16, 31, 16, 31, 16, 31, 203], ["+", 0, 212, 0, 41, 15, 23, 0, 16, 17, 98], ["+", 15, 23, 0, 16, 12, 16, 31, 16, 31, 203], ["+", 0, 41, 15, 23, 0, 16, 12, 16, 17, 60], ["+", 0, 41, 15, 23, 0, 16, 12, 16, 12, 22]]
8
129
6
using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Numerics; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Xml.Schema; using static System.Console; namespace ConsoleApp2 { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<int> Slist() { return new List<int>(ReadLine().Split().Select(int.Parse)); } static void Main(string[] args) { var WHxy = Sarray(); var W = WHxy[0]; var H = WHxy[1]; var x = WHxy[2]; var y = WHxy[3]; var ans = W * H / 2; var ans2 = W / 2 == x && H / 2 == y ? 1 : 0; WriteLine($"{ans} {ans2}"); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Numerics; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Xml.Schema; using static System.Console; namespace ConsoleApp2 { class Program { static public double[] Sarray() { return ReadLine().Split().Select(double.Parse).ToArray(); } static public List<int> Slist() { return new List<int>(ReadLine().Split().Select(int.Parse)); } static void Main(string[] args) { var WHxy = Sarray(); var W = WHxy[0]; var H = WHxy[1]; var x = WHxy[2]; var y = WHxy[3]; var ans = W * H / 2; var ans2 = W / 2 == x && H / 2 == y ? 1 : 0; WriteLine($"{ans} {ans2}"); } } }
[["-", 0, 235, 8, 201, 0, 195, 39, 224, 39, 199], ["+", 0, 235, 8, 201, 0, 195, 39, 224, 39, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199]]
8
223
4
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; namespace Atcoder { class Program { static void Main(string[] args) { try { Solve.Answer(); } catch (Exception ex) { WriteLine(ex.ToString()); } } } public class Solve { public static void Answer() { var whxy = IO.ReadSplitInt; var w = whxy[0]; var h = whxy[1]; var x = whxy[2]; var y = whxy[3]; double s_half = (double)w * h / 2; int isHukusu = 0; if (w % 2 == 0 && h % 2 == 0) { if (x == w % 2 && y == h % 2) { isHukusu = 1; } } IO.OutJoinSpace(new double[] { s_half, isHukusu }); } public class IO { #region Input public static string ReadString => ReadLine(); public static int ReadInt => int.Parse(ReadLine()); public static long ReadLong => long.Parse(ReadLine()); public static double ReadDouble => double.Parse(ReadLine()); public static List<string> ReadSplitString => ReadLine().Split().ToList(); public static List<int> ReadSplitInt => ReadLine().Split().Select(s => int.Parse(s)).ToList(); public static List<long> ReadSplitLong => ReadLine().Split().Select(s => long.Parse(s)).ToList(); public static List<double> ReadSplitdouble => ReadLine().Split().Select(s => double.Parse(s)).ToList(); #endregion #region Output public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list)); public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No"); #endregion } public class Mod { #region // 割る数の定義 private readonly static long M = 1000000007; // 足し算 public static long Add(long a, long b) => (a * b) % M; // 引き算 public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M; // 掛け算 public static long Multi(long a, long b) => (a * b) % M; #endregion } public class Scanner { #region public string Str => Console.ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); // public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); // public int[] ArrInt1D(int n) => Create(n, () => Int); // public long[] ArrLong1D(int n) => Create(n, () => Long); // public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); // public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] // インライン化を推奨する public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } #endregion } public static long GCD(long x, long y) { #region if (x < y) { var tmp = x; x = y; y = tmp; } while (true) { if (x % y == 0) { return y; } else { var tmp = x; x = y; y = tmp % y; } } #endregion } public static long Choice2(long n) { #region if (n <= 1) return 0; if (n == 2) return 1; else return n * (n - 1) / 2; #endregion } } }
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; namespace Atcoder { class Program { static void Main(string[] args) { try { Solve.Answer(); } catch (Exception ex) { WriteLine(ex.ToString()); } } } public class Solve { public static void Answer() { var whxy = IO.ReadSplitInt; var w = whxy[0]; var h = whxy[1]; var x = whxy[2]; var y = whxy[3]; double s_half = (double)w * h / 2; int isHukusu = 0; if (w % 2 == 0 && h % 2 == 0) { if (x == w / 2 && y == h / 2) { isHukusu = 1; } } IO.OutJoinSpace(new double[] { s_half, isHukusu }); } public class IO { #region Input public static string ReadString => ReadLine(); public static int ReadInt => int.Parse(ReadLine()); public static long ReadLong => long.Parse(ReadLine()); public static double ReadDouble => double.Parse(ReadLine()); public static List<string> ReadSplitString => ReadLine().Split().ToList(); public static List<int> ReadSplitInt => ReadLine().Split().Select(s => int.Parse(s)).ToList(); public static List<long> ReadSplitLong => ReadLine().Split().Select(s => long.Parse(s)).ToList(); public static List<double> ReadSplitdouble => ReadLine().Split().Select(s => double.Parse(s)).ToList(); #endregion #region Output public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list)); public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No"); #endregion } public class Mod { #region // 割る数の定義 private readonly static long M = 1000000007; // 足し算 public static long Add(long a, long b) => (a * b) % M; // 引き算 public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M; // 掛け算 public static long Multi(long a, long b) => (a * b) % M; #endregion } public class Scanner { #region public string Str => Console.ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); // public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); // public int[] ArrInt1D(int n) => Create(n, () => Int); // public long[] ArrLong1D(int n) => Create(n, () => Long); // public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); // public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] // インライン化を推奨する public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } #endregion } public static long GCD(long x, long y) { #region if (x < y) { var tmp = x; x = y; y = tmp; } while (true) { if (x % y == 0) { return y; } else { var tmp = x; x = y; y = tmp % y; } } #endregion } public static long Choice2(long n) { #region if (n <= 1) return 0; if (n == 2) return 1; else return n * (n - 1) / 2; #endregion } } }
[["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 109], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 85], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 17, 109], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 85]]
8
1,136
4
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; namespace AtCoder { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static void Main(string[] args) { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); var WHxy = Sarray(); var W = WHxy[0]; var H = WHxy[1]; var x = WHxy[2]; var y = WHxy[3]; var men = H * W / 2.0; var num = (2 * x == H && 2 * y == W) ? 1 : 0; WriteLine($"{men} {num}"); // Out.Flush(); } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; namespace AtCoder { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static void Main(string[] args) { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); var WHxy = Sarray(); var W = WHxy[0]; var H = WHxy[1]; var x = WHxy[2]; var y = WHxy[3]; var men = H * W / 2.0; var num = (2 * x == W && 2 * y == H) ? 1 : 0; WriteLine($"{men} {num}"); // Out.Flush(); } } }
[["-", 0, 41, 15, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 41, 15, 23, 0, 16, 31, 16, 12, 22], ["-", 0, 41, 15, 23, 0, 16, 12, 16, 12, 22], ["+", 0, 41, 15, 23, 0, 16, 12, 16, 12, 22]]
8
201
4
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 whxy = Console.ReadLine().Split().Select(long.Parse).ToArray(); double maxarea = whxy[0] * whxy[1] / 2; int judge = 0; if (whxy[2] + whxy[2] == whxy[0] && whxy[3] + whxy[3] == whxy[1]) judge = 1; Console.WriteLine(maxarea + " " + judge); } 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 whxy = Console.ReadLine().Split().Select(long.Parse).ToArray(); double maxarea = (double)whxy[0] * whxy[1] / 2; int judge = 0; if (whxy[2] + whxy[2] == whxy[0] && whxy[3] + whxy[3] == whxy[1]) judge = 1; Console.WriteLine(maxarea + " " + judge); } 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); } } }
[["+", 0, 212, 0, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 212, 0, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 212, 0, 16, 31, 16, 31, 74, 0, 25]]
8
376
3
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; using Pair = System.Tuple<long, long>; /// <summary> /// https://atcoder.jp/contests/abc130 /// 2020/02/04 /// </summary> namespace ABC130 { public class Program { public static void Main(string[] args) { // A(); 3m // B(); 14m C(); // D(); // E(); // F(); } public static void F() {} public static void E() {} public static void D() {} public static void C() { long W = rl; long H = rl; long x = rl; long y = rl; string ans = (W * H / 2).ToString() + " "; if (W / 2 == x && H / 2 == y) { ans += "1"; } else { ans += "0"; } Console.WriteLine(ans); } public static void B() { long N = rl; long M = rl; long[] A = rla; long l = 0; for (int i = 0; i < N; i++) { l += A[i]; if (l > M) { Console.WriteLine(i + 1); return; } } Console.WriteLine(N + 1); } public static void A() { long X = rl; long A = rl; if (X < A) Console.WriteLine("0"); else Console.WriteLine("10"); } } } namespace Ha2ne2Util { public static class Cin { private static string[] Tokens { get; set; } private static int Pointer { get; set; } public static string Next() { if (Tokens == null || Tokens.Length <= Pointer) { Tokens = Console.ReadLine().Split(' '); Pointer = 0; } return Tokens[Pointer++]; } public static int ReadInt() { return int.Parse(Next()); } public static long rl => ReadLong(); public static long[] rla => ReadLongArray(); public static double rd => ReadDouble(); public static double[] rda => ReadDoubleArray(); public static long ReadLong() { return long.Parse(Next()); } public static double ReadDouble() { return double.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 double[] ReadDoubleArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static void ReadArrays(out long[] a, out long[] b, long N) { a = new long[N]; b = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); } } public static void ReadArrays(out long[] a, out long[] b, out long[] c, long N) { a = new long[N]; b = new long[N]; c = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); c[i] = ReadLong(); } } 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[] SortDecend<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 long ModAdd(long a, long b) { long res = a + b; if (res >= MOD) return res % MOD; return res; } public static long ModMul(long a, long b) { long res = a * b; if (res >= MOD) return res % MOD; return res; } public static void ModAddEqual(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; } public static void FillArray<T>(T[] array, T value) { int max = array.Length; for (int i = 0; i < max; i++) { array[i] = value; } } public static void FillArray<T>(T[,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { array[i, j] = value; } } } public static void FillArray<T>(T[,,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); int max2 = array.GetLength(2); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { for (int k = 0; k < max2; k++) { array[i, j, k] = value; } } } } } /// <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; using Pair = System.Tuple<long, long>; /// <summary> /// https://atcoder.jp/contests/abc130 /// 2020/02/04 /// </summary> namespace ABC130 { public class Program { public static void Main(string[] args) { // A(); 3m // B(); 14m C(); // D(); // E(); // F(); } public static void F() {} public static void E() {} public static void D() {} public static void C() { long W = rl; long H = rl; long x = rl; long y = rl; string ans = (W * H / 2.0).ToString() + " "; if (W / 2.0 == x && H / 2.0 == y) { ans += "1"; } else { ans += "0"; } Console.WriteLine(ans); } public static void B() { long N = rl; long M = rl; long[] A = rla; long l = 0; for (int i = 0; i < N; i++) { l += A[i]; if (l > M) { Console.WriteLine(i + 1); return; } } Console.WriteLine(N + 1); } public static void A() { long X = rl; long A = rl; if (X < A) Console.WriteLine("0"); else Console.WriteLine("10"); } } } namespace Ha2ne2Util { public static class Cin { private static string[] Tokens { get; set; } private static int Pointer { get; set; } public static string Next() { if (Tokens == null || Tokens.Length <= Pointer) { Tokens = Console.ReadLine().Split(' '); Pointer = 0; } return Tokens[Pointer++]; } public static int ReadInt() { return int.Parse(Next()); } public static long rl => ReadLong(); public static long[] rla => ReadLongArray(); public static double rd => ReadDouble(); public static double[] rda => ReadDoubleArray(); public static long ReadLong() { return long.Parse(Next()); } public static double ReadDouble() { return double.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 double[] ReadDoubleArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static void ReadArrays(out long[] a, out long[] b, long N) { a = new long[N]; b = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); } } public static void ReadArrays(out long[] a, out long[] b, out long[] c, long N) { a = new long[N]; b = new long[N]; c = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); c[i] = ReadLong(); } } 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[] SortDecend<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 long ModAdd(long a, long b) { long res = a + b; if (res >= MOD) return res % MOD; return res; } public static long ModMul(long a, long b) { long res = a * b; if (res >= MOD) return res % MOD; return res; } public static void ModAddEqual(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; } public static void FillArray<T>(T[] array, T value) { int max = array.Length; for (int i = 0; i < max; i++) { array[i] = value; } } public static void FillArray<T>(T[,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { array[i, j] = value; } } } public static void FillArray<T>(T[,,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); int max2 = array.GetLength(2); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { for (int k = 0; k < max2; k++) { array[i, j, k] = value; } } } } } /// <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; } } }
[["-", 31, 213, 63, 214, 205, 23, 0, 16, 12, 203], ["+", 31, 213, 63, 214, 205, 23, 0, 16, 12, 250], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 250], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 250]]
8
3,482
6
using System; using System.Linq; namespace CSharp { class Program { static void Main() { var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var W = input[0]; var H = input[1]; var x = input[2]; var y = input[3]; Console.WriteLine($"{W * H / 2.0} {(2 * x == W && 2 * y == H ? 0 : 1)}"); } } }
using System; using System.Linq; namespace CSharp { class Program { static void Main() { var input = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var W = input[0]; var H = input[1]; var x = input[2]; var y = input[3]; Console.WriteLine($"{W * H / 2.0} {(2 * x == W && 2 * y == H ? 1 : 0)}"); } } }
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 283, 0, 284, 0, 23, 0, 41, 64, 203], ["-", 0, 283, 0, 284, 0, 23, 0, 41, 0, 102], ["+", 0, 283, 0, 284, 0, 23, 0, 41, 0, 102], ["+", 0, 283, 0, 284, 0, 23, 0, 41, 75, 203]]
8
117
6
using System; class Program { static void Main() { string[] input = Console.ReadLine().Split(' '); long W = long.Parse(input[0]); long H = long.Parse(input[1]); long x = long.Parse(input[2]); long y = long.Parse(input[3]); double area = W / 2 * H; string multi = "0"; if (W == x * 2 && H == y * 2) multi = "1"; Console.WriteLine(area.ToString() + " " + multi); } }
using System; class Program { static void Main() { string[] input = Console.ReadLine().Split(' '); long W = long.Parse(input[0]); long H = long.Parse(input[1]); long x = long.Parse(input[2]); long y = long.Parse(input[3]); double area = (double)W / 2 * (double)H; string multi = "0"; if (W == x * 2 && H == y * 2) multi = "1"; Console.WriteLine(area.ToString() + " " + multi); } }
[["+", 0, 212, 0, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 212, 0, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 212, 0, 16, 31, 16, 31, 74, 0, 25], ["+", 0, 200, 0, 212, 0, 16, 12, 74, 0, 24], ["+", 0, 200, 0, 212, 0, 16, 12, 74, 39, 199], ["+", 0, 200, 0, 212, 0, 16, 12, 74, 0, 25]]
8
137
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Console; class Program { static void Main(string[] args) { new Program().Calc(); } Scanner cin; public Program() {} 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 Calc() { cin = new Scanner(); long W = cin.nextLong(); long H = cin.nextLong(); long X = cin.nextLong(); long Y = cin.nextLong(); double ans = W * H / 2.0; bool flag = (W / 2 == X && H / 2 == Y); WriteLine("{0} {1}", ans, flag ? "1" : "0"); } } public static class StringExtension { public static char GetChar1(this string str, int indexOneBase) { return str[indexOneBase - 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; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Console; class Program { static void Main(string[] args) { new Program().Calc(); } Scanner cin; public Program() {} 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 Calc() { cin = new Scanner(); long W = cin.nextLong(); long H = cin.nextLong(); long X = cin.nextLong(); long Y = cin.nextLong(); double ans = W * H / 2.0; bool flag = (W / 2.0 == X && H / 2.0 == Y); WriteLine("{0} {1}", ans, flag ? "1" : "0"); } } public static class StringExtension { public static char GetChar1(this string str, int indexOneBase) { return str[indexOneBase - 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; } }
[["-", 0, 23, 0, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 23, 0, 16, 31, 16, 31, 16, 12, 250], ["-", 0, 23, 0, 16, 12, 16, 31, 16, 12, 203], ["+", 0, 23, 0, 16, 12, 16, 31, 16, 12, 250]]
8
628
4
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace AtCoder { class Program { static void Main(string[] args) { var cin = new Scanner(); var W = cin.nextLong(); var H = cin.nextLong(); var x = cin.nextLong(); var y = cin.nextLong(); var ans = (W * H) / 2; var ans2 = ""; if (x + x == W && y + y == H) { ans2 = "1"; } else { ans2 = "0"; } Console.WriteLine(ans + " " + ans2); } // 最小公倍数 static long Lcm(long a, long b) { return a * (b / Gcd(a, b)); } // 最大公約数 static long Gcd(long a, long b) { if (a < b) return Gcd(b, a); long d = 0; do { d = a % b; a = b; b = d; } while (d != 0); return a; } } class Point { public int x { get; set; } public int y { get; set; } } 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; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace AtCoder { class Program { static void Main(string[] args) { var cin = new Scanner(); var W = cin.nextLong(); var H = cin.nextLong(); var x = cin.nextLong(); var y = cin.nextLong(); var ans = (W * H) / 2.0; var ans2 = ""; if (x + x == W && y + y == H) { ans2 = "1"; } else { ans2 = "0"; } Console.WriteLine(ans + " " + ans2); } // 最小公倍数 static long Lcm(long a, long b) { return a * (b / Gcd(a, b)); } // 最大公約数 static long Gcd(long a, long b) { if (a < b) return Gcd(b, a); long d = 0; do { d = a % b; a = b; b = d; } while (d != 0); return a; } } class Point { public int x { get; set; } public int y { get; set; } } 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; } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 250]]
8
602
2
using Atcoder; using System; using System.Collections.Generic; using System.ComponentModel.Design; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { var first = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var W = first[0]; var H = first[1]; var x = first[2]; var y = first[3]; double minArea = W * H / 2; var isMulti = (W / 2 == x) && (H / 2 == y); if (isMulti) { Console.Write(minArea.ToString() + " 1"); } else { Console.Write(minArea.ToString() + " 0"); } } // static void Main(string[] args) //{ // var temp = new Atcoder.ABC129.B(); // temp.Run(); //} } // var N = int.Parse(Console.ReadLine()); // var S = Console.ReadLine(); // var K = Console.ReadLine().Split(' '); // var N = int.Parse((K[0])); // var M = int.Parse((K[1])); // var firstLine = Console.ReadLine().Split(' ').Select(int.Parse); }
using Atcoder; using System; using System.Collections.Generic; using System.ComponentModel.Design; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { var first = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); double W = first[0]; double H = first[1]; var x = first[2]; var y = first[3]; double minArea = W * H / 2; var isMulti = (W / 2 == x) && (H / 2 == y); if (isMulti) { Console.Write(minArea.ToString() + " 1"); } else { Console.Write(minArea.ToString() + " 0"); } } // static void Main(string[] args) //{ // var temp = new Atcoder.ABC129.B(); // temp.Run(); //} } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
193
4
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { // W H x y var Array = Console.ReadLine().Split().Select(z => long.Parse(z)).ToArray(); long W = Array[0]; long H = Array[1]; long x = Array[2]; long y = Array[3]; int Result = 0; double Area = W * H / 2; if (x * 2 == W && y * 2 == H) Result = 1; Console.WriteLine($"{Area} {Result}"); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { // W H x y var Array = Console.ReadLine().Split().Select(z => long.Parse(z)).ToArray(); long W = Array[0]; long H = Array[1]; long x = Array[2]; long y = Array[3]; int Result = 0; double Area = (double)W * H / 2; if (x * 2 == W && y * 2 == H) Result = 1; Console.WriteLine($"{Area} {Result}"); } }
[["+", 0, 212, 0, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 212, 0, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 212, 0, 16, 31, 16, 31, 74, 0, 25]]
8
139
3
using System; using System.Linq; namespace ABC130_C { class Program { static void Main(string[] args) { var line = Console.ReadLine().Split().Select(double.Parse).ToArray(); var W = line[0]; var H = line[1]; var x = line[2]; var y = line[3]; var flag = 2 * x == W && 2 * y == H; Console.WriteLine($"{W * H * 0.5} {flag}"); } } }
using System; using System.Linq; namespace ABC130_C { class Program { static void Main(string[] args) { var line = Console.ReadLine().Split().Select(double.Parse).ToArray(); var W = line[0]; var H = line[1]; var x = line[2]; var y = line[3]; var flag = 2 * x == W && 2 * y == H ? 1 : 0; Console.WriteLine($"{W * H * 0.5} {flag}"); } } }
[["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 64, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 75, 203]]
8
117
4
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(); long W = long.Parse(str[0]); long H = long.Parse(str[1]); long X = long.Parse(str[2]); long Y = long.Parse(str[3]); long ans = W * H / 2; long t = 0; if (X * 2 == W && Y * 2 == H) { t = 1; } Console.WriteLine(ans + " " + t); } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(); double W = double.Parse(str[0]); double H = double.Parse(str[1]); long X = long.Parse(str[2]); long Y = long.Parse(str[3]); double ans = W * H / 2; long t = 0; if (X * 2 == W && Y * 2 == H) { t = 1; } Console.WriteLine(ans + " " + t); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
139
10
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Competitive { internal class Solution { public long MOD = 1000000007; public void Run() { long W, H, X, Y; { var line = Input.ReadLongArray(); W = line[0]; H = line[1]; X = line[2]; Y = line[3]; } long A = W * H / 2; int R = ((X * 2 == W) && (Y * 2 == H) ? 1 : 0); Console.WriteLine($"{A} {R}"); } } // libs ---------- // common ---------- internal static class Input { public static string ReadString() { string line = Console.ReadLine(); return line; } public static int ReadInt() { string line = Console.ReadLine(); return int.Parse(line); } public static int[] ReadIntArray() { string line = Console.ReadLine(); return line.Split(' ').Select(int.Parse).ToArray(); } public static long ReadLong() { string line = Console.ReadLine(); return long.Parse(line); } public static long[] ReadLongArray() { string line = Console.ReadLine(); return line.Split(' ').Select(long.Parse).ToArray(); } public static double[] ReadDoubleArray() { string line = Console.ReadLine(); return line.Split(' ').Select(double.Parse).ToArray(); } } internal class Program { public static void Main(string[] args) { var s = new Solution(); s.Run(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Competitive { internal class Solution { public long MOD = 1000000007; public void Run() { long W, H, X, Y; { var line = Input.ReadLongArray(); W = line[0]; H = line[1]; X = line[2]; Y = line[3]; } double A = W * H / 2.0; int R = ((X * 2 == W) && (Y * 2 == H) ? 1 : 0); Console.WriteLine($"{A} {R}"); } } // libs ---------- // common ---------- internal static class Input { public static string ReadString() { string line = Console.ReadLine(); return line; } public static int ReadInt() { string line = Console.ReadLine(); return int.Parse(line); } public static int[] ReadIntArray() { string line = Console.ReadLine(); return line.Split(' ').Select(int.Parse).ToArray(); } public static long ReadLong() { string line = Console.ReadLine(); return long.Parse(line); } public static long[] ReadLongArray() { string line = Console.ReadLine(); return line.Split(' ').Select(long.Parse).ToArray(); } public static double[] ReadDoubleArray() { string line = Console.ReadLine(); return line.Split(' ').Select(double.Parse).ToArray(); } } internal class Program { public static void Main(string[] args) { var s = new Solution(); s.Run(); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 250]]
8
368
4
using System; using System.Collections.Generic; using System.Linq; namespace C_ABC130 { class MainClass { static long[] s; public static void Main(string[] args) { s = Array.ConvertAll(Console.ReadLine().Split().ToArray(), long.Parse); double ans = (double)(s[0]) * (double)(s[1]) / 2; int ans2 = 0; if (s[2] == s[0] / 2 && s[3] == s[1] / 2) { ans2 = 1; } Console.WriteLine("{0} {1}", ans, ans2); } } }
using System; using System.Collections.Generic; using System.Linq; namespace C_ABC130 { class MainClass { static long[] s; public static void Main(string[] args) { s = Array.ConvertAll(Console.ReadLine().Split().ToArray(), long.Parse); double ans = (double)(s[0]) * (double)(s[1]) / 2; int ans2 = 0; if (s[2] == (double)s[0] / 2 && s[3] == (double)s[1] / 2) { ans2 = 1; } Console.WriteLine("{0} {1}", ans, ans2); } } }
[["+", 15, 16, 31, 16, 12, 16, 31, 74, 0, 24], ["+", 15, 16, 31, 16, 12, 16, 31, 74, 39, 199], ["+", 15, 16, 31, 16, 12, 16, 31, 74, 0, 25], ["+", 15, 16, 12, 16, 12, 16, 31, 74, 0, 24], ["+", 15, 16, 12, 16, 12, 16, 31, 74, 39, 199], ["+", 15, 16, 12, 16, 12, 16, 31, 74, 0, 25]]
8
141
6
using System; class c { static void Main() { var inp = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); double ans = inp[0] * inp[1] / 2; int ans2 = 0; if (inp[0] / 2 == inp[2] && inp[1] / 2 == inp[3]) ans2 = 1; Console.WriteLine("{0} {1}", ans, ans2); } }
using System; class c { static void Main() { var inp = Array.ConvertAll(Console.ReadLine().Split(), double.Parse); double ans = inp[0] * inp[1] / 2; int ans2 = 0; if (inp[0] / 2 == inp[2] && inp[1] / 2 == inp[3]) ans2 = 1; Console.WriteLine("{0} {1}", ans, ans2); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199]]
8
99
2
#if true //#if false #define UTAKA_DEBUG #endif using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using System.IO; namespace UtakaApp { public partial class Program { public const string ContestName = "abc130"; public const string ProblemName = "E"; public static void Main(string[] args) { #if UTAKA_LOCAL //#if false new TestCaseCheckerForAtCoder().TestProblems(); #else var console = new MyConsole(); new Program().Solve(System.Console.In, console); console.Flush(); #endif var sw = new StreamWriter( System.Console.OpenStandardOutput()) { AutoFlush = false }; } public void Solve(TextReader textReader, IConsole console) { var cin = new ConsoleInput(textReader, ' '); int N = cin.ReadInt; int M = cin.ReadInt; int[] S = cin.ReadIntArray(N); int[] T = cin.ReadIntArray(M); long[,] dp = new long[N + 1, M + 1]; long[,] sums = new long[N + 1, M + 1]; dp[0, 0] = 1; sums[0, 0] = 1; for (int i = 1; i <= N; i++) { sums[i, 0] = 1; } for (int j = 1; j <= M; j++) { sums[0, j] = 1; } for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) { if (S[i - 1] == T[j - 1]) { dp[i, j] = sums[i - 1, j - 1]; sums[i, j] = sums[i - 1, j] + sums[i, j - 1] - sums[i - 1, j - 1] + dp[i, j]; while (sums[i, j] < 0) sums[i, j] += ModLarge; sums[i, j] %= ModLarge; } } } console.WriteLine(sums[N, M].ToString()); } } public partial class Program { public const int ModLarge = 1000000007; void Swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } } public class ConsoleInput { private readonly TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(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 => _stream.ReadLine(); public int ReadInt => int.Parse(Read); public long ReadLong => long.Parse(Read); public double ReadDouble => 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 interface IConsole { void Flush(); void Write(string str); void WriteLine(string str); } public class MyConsole : IConsole { public MyConsole() { var sw = new StreamWriter( System.Console.OpenStandardOutput()) { AutoFlush = false }; System.Console.SetOut(sw); } public void Flush() { System.Console.Out.Flush(); } public void Write(string str) { System.Console.Write(str); } public void WriteLine(string str) { System.Console.WriteLine(str); } } #if UTAKA_LOCAL public class DebugConsole : IConsole { private StringBuilder mSb; public DebugConsole() { mSb = new StringBuilder(); } public void Flush() { // 何もしない } public void Write(string str) { mSb.Append(str); } public void WriteLine(string str) { mSb.AppendLine(str); } public string GetAllOutput() { return mSb.ToString(); } } #endif #if UTAKA_LOCAL public class TestCaseCheckerForAtCoder { private string DirectoryPath => $"../../../../{Program.ContestName}/{Program.ProblemName}"; private string GetInputFilePath(int testCaseNumber) { // return $"{DirectoryPath}/sample-{testCaseNumber}.in"; return $"{DirectoryPath}/in_{testCaseNumber}.txt"; } private string GetOutputFilePath(int testCaseNumber) { // return $"{DirectoryPath}/sample-{testCaseNumber}.out"; return $"{DirectoryPath}/out_{testCaseNumber}.txt"; } public bool TestProblem(int testCaseNumber) { var inputFilePath = GetInputFilePath(testCaseNumber); var outputFilePath = GetOutputFilePath(testCaseNumber); TextReader inputStream = new StreamReader(inputFilePath); var debugConsoleWriter = new DebugConsole(); new Program().Solve(inputStream, debugConsoleWriter); var output = debugConsoleWriter.GetAllOutput(); TextReader outputStream = new StreamReader(outputFilePath); var outputAnswer = outputStream.ReadToEnd(); Dbg.WriteLine(output); Dbg.WriteLine(outputAnswer); var isCorrect = output == outputAnswer; return isCorrect; } public void TestProblems() { var isSuccessAll = true; var testCaseNumber = 1; while (true) { var inputFileName = GetInputFilePath(testCaseNumber); if (!File.Exists(inputFileName)) { break; } System.Console.WriteLine( $"TestCase {testCaseNumber} ====================================================="); var result = TestProblem(testCaseNumber); if (result) { System.Console.WriteLine($"Success"); } else { isSuccessAll = false; System.Console.WriteLine($"Failure *****"); } testCaseNumber++; } if (isSuccessAll) { System.Console.WriteLine($"!!!!!!!!! All Success !!!!!!!!!"); } } } #endif #if UTAKA_LOCAL public static class Dbg { public static void WriteLine(string str) { System.Console.WriteLine(str); } public static void Write(string str) { System.Console.Write(str); } } #else public static class Dbg { public static void WriteLine(string str) {} public static void Write(string str) {} } #endif }
#if true //#if false #define UTAKA_DEBUG #endif using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using System.IO; namespace UtakaApp { public partial class Program { public const string ContestName = "abc130"; public const string ProblemName = "E"; public static void Main(string[] args) { #if UTAKA_LOCAL //#if false new TestCaseCheckerForAtCoder().TestProblems(); #else var console = new MyConsole(); new Program().Solve(System.Console.In, console); console.Flush(); #endif var sw = new StreamWriter( System.Console.OpenStandardOutput()) { AutoFlush = false }; } public void Solve(TextReader textReader, IConsole console) { var cin = new ConsoleInput(textReader, ' '); int N = cin.ReadInt; int M = cin.ReadInt; int[] S = cin.ReadIntArray(N); int[] T = cin.ReadIntArray(M); long[,] dp = new long[N + 1, M + 1]; long[,] sums = new long[N + 1, M + 1]; dp[0, 0] = 1; sums[0, 0] = 1; for (int i = 1; i <= N; i++) { sums[i, 0] = 1; } for (int j = 1; j <= M; j++) { sums[0, j] = 1; } for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) { if (S[i - 1] == T[j - 1]) { dp[i, j] = sums[i - 1, j - 1]; } sums[i, j] = sums[i - 1, j] + sums[i, j - 1] - sums[i - 1, j - 1] + dp[i, j]; while (sums[i, j] < 0) sums[i, j] += ModLarge; sums[i, j] %= ModLarge; } } console.WriteLine(sums[N, M].ToString()); } } public partial class Program { public const int ModLarge = 1000000007; void Swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } } public class ConsoleInput { private readonly TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(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 => _stream.ReadLine(); public int ReadInt => int.Parse(Read); public long ReadLong => long.Parse(Read); public double ReadDouble => 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 interface IConsole { void Flush(); void Write(string str); void WriteLine(string str); } public class MyConsole : IConsole { public MyConsole() { var sw = new StreamWriter( System.Console.OpenStandardOutput()) { AutoFlush = false }; System.Console.SetOut(sw); } public void Flush() { System.Console.Out.Flush(); } public void Write(string str) { System.Console.Write(str); } public void WriteLine(string str) { System.Console.WriteLine(str); } } #if UTAKA_LOCAL public class DebugConsole : IConsole { private StringBuilder mSb; public DebugConsole() { mSb = new StringBuilder(); } public void Flush() { // 何もしない } public void Write(string str) { mSb.Append(str); } public void WriteLine(string str) { mSb.AppendLine(str); } public string GetAllOutput() { return mSb.ToString(); } } #endif #if UTAKA_LOCAL public class TestCaseCheckerForAtCoder { private string DirectoryPath => $"../../../../{Program.ContestName}/{Program.ProblemName}"; private string GetInputFilePath(int testCaseNumber) { // return $"{DirectoryPath}/sample-{testCaseNumber}.in"; return $"{DirectoryPath}/in_{testCaseNumber}.txt"; } private string GetOutputFilePath(int testCaseNumber) { // return $"{DirectoryPath}/sample-{testCaseNumber}.out"; return $"{DirectoryPath}/out_{testCaseNumber}.txt"; } public bool TestProblem(int testCaseNumber) { var inputFilePath = GetInputFilePath(testCaseNumber); var outputFilePath = GetOutputFilePath(testCaseNumber); TextReader inputStream = new StreamReader(inputFilePath); var debugConsoleWriter = new DebugConsole(); new Program().Solve(inputStream, debugConsoleWriter); var output = debugConsoleWriter.GetAllOutput(); TextReader outputStream = new StreamReader(outputFilePath); var outputAnswer = outputStream.ReadToEnd(); Dbg.WriteLine(output); Dbg.WriteLine(outputAnswer); var isCorrect = output == outputAnswer; return isCorrect; } public void TestProblems() { var isSuccessAll = true; var testCaseNumber = 1; while (true) { var inputFileName = GetInputFilePath(testCaseNumber); if (!File.Exists(inputFileName)) { break; } System.Console.WriteLine( $"TestCase {testCaseNumber} ====================================================="); var result = TestProblem(testCaseNumber); if (result) { System.Console.WriteLine($"Success"); } else { isSuccessAll = false; System.Console.WriteLine($"Failure *****"); } testCaseNumber++; } if (isSuccessAll) { System.Console.WriteLine($"!!!!!!!!! All Success !!!!!!!!!"); } } } #endif #if UTAKA_LOCAL public static class Dbg { public static void WriteLine(string str) { System.Console.WriteLine(str); } public static void Write(string str) { System.Console.Write(str); } } #else public static class Dbg { public static void WriteLine(string str) {} public static void Write(string str) {} } #endif }
[["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
1,402
2
using System; using System.Linq; using System.Collections.Generic; namespace Contest { class Program { static void Main(string[] args) { ABC130.F(); } class ABC130 { public static void A() { Console.WriteLine(Read.Int() < Read.Int() ? 0 : 10); } public static void B() { var N = Read.Int(); var X = Read.Int(); var L = Read.LongN(); var D = Util.ASum(L); Console.WriteLine(D.Count(x => x <= X)); } public static void C() { var W = Read.Long(); var H = Read.Long(); var x = Read.Long(); var y = Read.Long(); bool isCenter = W == x * 2 && H == y * 2; Console.WriteLine("{0} {1}", 1.0 * H * W / 2, isCenter ? 1 : 0); } public static void D() { var N = Read.Int(); var K = Read.Long(); var A = Read.LongN(); long count = 0; int right = 0; long total = 0; for (int left = 0; left < N; ++left) { while (right < N && total + A[right] < K) { total += A[right]; right++; } count += right - left; if (left == right) { right++; } else { total -= A[left]; } } Console.WriteLine((long)N * (N + 1) / 2 - count); } public static void E() { var N = Read.Int(); var M = Read.Int(); var S = Read.IntN(); var T = Read.IntN(); var dp1 = new long[N + 1, M + 1]; var dp2 = new long[N + 1, M + 1]; for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) { dp1[i + 1, j + 1] = S[i] == T[j] ? dp2[i, j] + 1 : 0; dp2[i + 1, j + 1] = (dp2[i + 1, j] + dp2[i, j + 1] - dp2[i, j] + dp1[i + 1, j + 1]) % Util.P; } } Console.WriteLine(dp2[N, M] + 1); } public static void F() { var N = Read.Int(); // List<double> X = new List<double>(); // List<double> Y = new List<double>(); // List<string> D = new List<string>(); // for(int i = 0; i < N; ++i) //{ // var s = Read.StrN(); // X.Add(Convert.ToDouble(s[0])); // Y.Add(Convert.ToDouble(s[1])); // D.Add(s[2]); //} double maxX_UD = Double.MinValue, minX_UD = Double.MaxValue, maxX_L = Double.MinValue, minX_L = Double.MaxValue, maxX_R = Double.MinValue, minX_R = Double.MaxValue; double maxY_LR = Double.MinValue, minY_LR = Double.MaxValue, maxY_D = Double.MinValue, minY_D = Double.MaxValue, maxY_U = Double.MinValue, minY_U = Double.MaxValue; for (int i = 0; i < N; ++i) { var s = Read.StrN(); var x = Convert.ToDouble(s[0]); var y = Convert.ToDouble(s[1]); switch (s[2]) { case "U": maxX_UD = Math.Max(maxX_UD, x); minX_UD = Math.Min(minX_UD, x); maxY_U = Math.Max(maxY_U, y); minY_U = Math.Max(minY_U, y); break; case "D": maxX_UD = Math.Max(maxX_UD, x); minX_UD = Math.Min(minX_UD, x); maxY_D = Math.Max(maxY_D, y); minY_D = Math.Max(minY_D, y); break; case "L": maxX_L = Math.Max(maxX_L, x); minX_L = Math.Min(minX_L, x); maxY_LR = Math.Max(maxY_LR, y); minY_LR = Math.Min(minY_LR, y); break; case "R": maxX_R = Math.Max(maxX_R, x); minX_R = Math.Min(minX_R, x); maxY_LR = Math.Max(maxY_LR, y); minY_LR = Math.Min(minY_LR, y); break; } } List<double> candidate = new List<double>(); candidate.Add(0); candidate.Add(maxX_L - maxX_UD); candidate.Add(maxX_L - minX_UD); candidate.Add(minX_L - maxX_UD); candidate.Add(minX_L - minX_UD); candidate.Add(maxX_UD - maxX_R); candidate.Add(minX_UD - maxX_R); candidate.Add(maxX_UD - minX_R); candidate.Add(minX_UD - minX_R); candidate.Add((maxX_L - maxX_R) / 2); candidate.Add((minX_L - minX_R) / 2); candidate.Add(maxY_D - maxY_LR); candidate.Add(maxY_D - minY_LR); candidate.Add(minY_D - maxY_LR); candidate.Add(minY_D - minY_LR); candidate.Add(maxY_LR - maxY_U); candidate.Add(minY_LR - maxY_U); candidate.Add(maxY_LR - minY_U); candidate.Add(minY_LR - minY_U); candidate.Add((maxY_D - maxY_U) / 2); candidate.Add((minY_D - minY_U) / 2); candidate = candidate.Distinct().Where(x => x >= 0 && x < 1e9).ToList(); double min = Double.MaxValue; foreach (var t in candidate) { double maxX = Math.Max(maxX_UD, Math.Max(maxX_L - t, maxX_R + t)); double minX = Math.Min(minX_UD, Math.Min(minX_L - t, minX_R + t)); double maxY = Math.Max(maxY_LR, Math.Max(maxY_D - t, maxY_U + t)); double minY = Math.Min(minY_LR, Math.Min(minY_D - t, minY_U + t)); double v = (maxX - minX) * (maxY - minY); min = Math.Min(min, v); } Console.WriteLine(min); } } class Util { public static readonly long P = 1000000007; public static long[] ASum(long[] array) { var res = new long[array.Length + 1]; for (int i = 0; i < array.Length; ++i) { res[i + 1] = res[i] + array[i]; } return res; } } static class Read { static Queue<string> queue = new Queue<string>(); static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } } public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); } public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); } public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); } public static int[] IntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } public static long[] LongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } public static string[] StrN() { return Console.ReadLine().Split(' '); } public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } public static long[,] LongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = Read.LongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M) { Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new Dictionary<int, long>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1], ab[2]); dict[ab[1]].Add(ab[0], ab[2]); } return dict; } } } }
using System; using System.Linq; using System.Collections.Generic; namespace Contest { class Program { static void Main(string[] args) { ABC130.F(); } class ABC130 { public static void A() { Console.WriteLine(Read.Int() < Read.Int() ? 0 : 10); } public static void B() { var N = Read.Int(); var X = Read.Int(); var L = Read.LongN(); var D = Util.ASum(L); Console.WriteLine(D.Count(x => x <= X)); } public static void C() { var W = Read.Long(); var H = Read.Long(); var x = Read.Long(); var y = Read.Long(); bool isCenter = W == x * 2 && H == y * 2; Console.WriteLine("{0} {1}", 1.0 * H * W / 2, isCenter ? 1 : 0); } public static void D() { var N = Read.Int(); var K = Read.Long(); var A = Read.LongN(); long count = 0; int right = 0; long total = 0; for (int left = 0; left < N; ++left) { while (right < N && total + A[right] < K) { total += A[right]; right++; } count += right - left; if (left == right) { right++; } else { total -= A[left]; } } Console.WriteLine((long)N * (N + 1) / 2 - count); } public static void E() { var N = Read.Int(); var M = Read.Int(); var S = Read.IntN(); var T = Read.IntN(); var dp1 = new long[N + 1, M + 1]; var dp2 = new long[N + 1, M + 1]; for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) { dp1[i + 1, j + 1] = S[i] == T[j] ? dp2[i, j] + 1 : 0; dp2[i + 1, j + 1] = (dp2[i + 1, j] + dp2[i, j + 1] - dp2[i, j] + dp1[i + 1, j + 1] + Util.P) % Util.P; } } Console.WriteLine(dp2[N, M] + 1); } public static void F() { var N = Read.Int(); double maxX_UD = Double.MinValue, minX_UD = Double.MaxValue, maxX_L = Double.MinValue, minX_L = Double.MaxValue, maxX_R = Double.MinValue, minX_R = Double.MaxValue; double maxY_LR = Double.MinValue, minY_LR = Double.MaxValue, maxY_D = Double.MinValue, minY_D = Double.MaxValue, maxY_U = Double.MinValue, minY_U = Double.MaxValue; for (int i = 0; i < N; ++i) { var s = Read.StrN(); var x = Convert.ToDouble(s[0]); var y = Convert.ToDouble(s[1]); switch (s[2]) { case "U": maxX_UD = Math.Max(maxX_UD, x); minX_UD = Math.Min(minX_UD, x); maxY_U = Math.Max(maxY_U, y); minY_U = Math.Min(minY_U, y); break; case "D": maxX_UD = Math.Max(maxX_UD, x); minX_UD = Math.Min(minX_UD, x); maxY_D = Math.Max(maxY_D, y); minY_D = Math.Min(minY_D, y); break; case "L": maxX_L = Math.Max(maxX_L, x); minX_L = Math.Min(minX_L, x); maxY_LR = Math.Max(maxY_LR, y); minY_LR = Math.Min(minY_LR, y); break; case "R": maxX_R = Math.Max(maxX_R, x); minX_R = Math.Min(minX_R, x); maxY_LR = Math.Max(maxY_LR, y); minY_LR = Math.Min(minY_LR, y); break; } } List<double> candidate = new List<double>(); candidate.Add(0); candidate.Add(maxX_L - maxX_UD); candidate.Add(maxX_L - minX_UD); candidate.Add(minX_L - maxX_UD); candidate.Add(minX_L - minX_UD); candidate.Add(maxX_UD - maxX_R); candidate.Add(minX_UD - maxX_R); candidate.Add(maxX_UD - minX_R); candidate.Add(minX_UD - minX_R); candidate.Add((maxX_L - maxX_R) / 2); candidate.Add((minX_L - minX_R) / 2); candidate.Add(maxY_D - maxY_LR); candidate.Add(maxY_D - minY_LR); candidate.Add(minY_D - maxY_LR); candidate.Add(minY_D - minY_LR); candidate.Add(maxY_LR - maxY_U); candidate.Add(minY_LR - maxY_U); candidate.Add(maxY_LR - minY_U); candidate.Add(minY_LR - minY_U); candidate.Add((maxY_D - maxY_U) / 2); candidate.Add((minY_D - minY_U) / 2); candidate = candidate.Distinct().Where(x => x >= 0 && x < 1e9).ToList(); double min = Double.MaxValue; foreach (var t in candidate) { double maxX = Math.Max(maxX_UD, Math.Max(maxX_L - t, maxX_R + t)); double minX = Math.Min(minX_UD, Math.Min(minX_L - t, minX_R + t)); double maxY = Math.Max(maxY_LR, Math.Max(maxY_D - t, maxY_U + t)); double minY = Math.Min(minY_LR, Math.Min(minY_D - t, minY_U + t)); double v = (maxX - minX) * (maxY - minY); min = Math.Min(min, v); } Console.WriteLine(min); } } class Util { public static readonly long P = 1000000007; public static long[] ASum(long[] array) { var res = new long[array.Length + 1]; for (int i = 0; i < array.Length; ++i) { res[i + 1] = res[i] + array[i]; } return res; } } static class Read { static Queue<string> queue = new Queue<string>(); static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } } public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); } public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); } public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); } public static int[] IntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } public static long[] LongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } public static string[] StrN() { return Console.ReadLine().Split(' '); } public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } public static long[,] LongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = Read.LongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M) { Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new Dictionary<int, long>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1], ab[2]); dict[ab[1]].Add(ab[0], ab[2]); } return dict; } } } }
[["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 72], ["+", 12, 16, 31, 23, 0, 16, 12, 214, 205, 22], ["+", 12, 16, 31, 23, 0, 16, 12, 214, 0, 131], ["+", 12, 16, 31, 23, 0, 16, 12, 214, 141, 22], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22]]
8
2,407
8
using System; using System.Collections.Generic; public class CSharp { public static void Main() { Kyopuro chokudai = new Kyopuro(); chokudai.AtCoder(); } } public class Kyopuro { string s; int q; int[] x, d, n; public void AtCoder() { q = int.Parse(Console.ReadLine()); string[] input; int[] x = new int[q]; int[] d = new int[q]; int[] n = new int[q]; for (int i = 0; i < q; i++) { input = Console.ReadLine().Split(' '); x[i] = int.Parse(input[0]); d[i] = int.Parse(input[1]); n[i] = int.Parse(input[2]); } Mod mod = new Mod(1); int p = 1000003; long[] a = new long[p]; a[1] = 1; for (int i = 2; i < p; i++) { a[i] = a[i - 1] * i; a[i] %= p; } long y = 0; long z = 0; long ans = 0; for (int i = 0; i < q; i++) { if (x[i] == 0) { Console.WriteLine(0); continue; } if (d[i] == 0) { Console.WriteLine(mod.Pow(x[i], n[i])); continue; } y = x[i]; y = y * mod.Pow(d[i], p - 2) % p; z = mod.Pow(d[i], n[i]); if (n[i] == 1) { Console.WriteLine(x); continue; } if (y == 0) { Console.WriteLine(0); continue; } if (y + n[i] < p) { ans = a[y + n[i] - 1]; if (y > 1) ans = ans * mod.Pow((int)a[y - 1], p - 2); ans %= p; ans *= z; ans %= p; Console.WriteLine(ans); continue; } else { Console.WriteLine(0); continue; } } } public static void DebugWL(object x) { System.Diagnostics.Debug.WriteLine(x); } } // Mod(int n) // int[] fac: factors (1-indexed) // int n: the length of fac // int .Ncr(n,r): nCr // int .Fac(n): n!%p // int .Pow(n,m): n^m%p public class Mod { const int p = 1000003; int[] fac; public Mod(int n) { fac = new int[n + 1]; for (int i = 1; i <= n; i++) fac[i] = -1; fac[0] = 1; } public int Ncr(int n, int r) { if (n < r) return 0; if (r == 0 | n == r) return 1; long a = Fac(n); a = a * Pow(Fac(n - r), p - 2) % p; a = a * Pow(Fac(r), p - 2) % p; return (int)a; } public int Fac(int n) { if (fac[n] >= 0) return fac[n]; long k = 1; for (long i = 1; i <= n; i++) { k = k * i % p; } fac[n] = (int)k; return fac[n]; } public int Pow(int n, int m) { if (m == 0) return 1; if (m == 1) return n; long a = 1; if (m % 2 == 0) { a = Pow(n, m / 2); a = a * a % p; } else { a = Pow(n, m / 2); a = a * a % p; a = a * n % p; } return (int)a; } }
using System; using System.Collections.Generic; public class CSharp { public static void Main() { Kyopuro chokudai = new Kyopuro(); chokudai.AtCoder(); } } public class Kyopuro { string s; int q; int[] x, d, n; public void AtCoder() { q = int.Parse(Console.ReadLine()); string[] input; int[] x = new int[q]; int[] d = new int[q]; int[] n = new int[q]; for (int i = 0; i < q; i++) { input = Console.ReadLine().Split(' '); x[i] = int.Parse(input[0]); d[i] = int.Parse(input[1]); n[i] = int.Parse(input[2]); } Mod mod = new Mod(1); int p = 1000003; long[] a = new long[p]; a[1] = 1; for (int i = 2; i < p; i++) { a[i] = a[i - 1] * i; a[i] %= p; } long y = 0; long z = 0; long ans = 0; for (int i = 0; i < q; i++) { if (x[i] == 0) { Console.WriteLine(0); continue; } if (d[i] == 0) { Console.WriteLine(mod.Pow(x[i], n[i])); continue; } y = x[i]; y = y * mod.Pow(d[i], p - 2) % p; z = mod.Pow(d[i], n[i]); if (n[i] == 1) { Console.WriteLine(x[i]); continue; } if (y == 0) { Console.WriteLine(0); continue; } if (y + n[i] - 1 < p) { ans = a[y + n[i] - 1]; if (y > 1) ans = ans * mod.Pow((int)a[y - 1], p - 2); ans %= p; ans *= z; ans %= p; Console.WriteLine(ans); continue; } else { Console.WriteLine(0); continue; } } } public static void DebugWL(object x) { System.Diagnostics.Debug.WriteLine(x); } } // Mod(int n) // int[] fac: factors (1-indexed) // int n: the length of fac // int .Ncr(n,r): nCr // int .Fac(n): n!%p // int .Pow(n,m): n^m%p public class Mod { const int p = 1000003; int[] fac; public Mod(int n) { fac = new int[n + 1]; for (int i = 1; i <= n; i++) fac[i] = -1; fac[0] = 1; } public int Ncr(int n, int r) { if (n < r) return 0; if (r == 0 | n == r) return 1; long a = Fac(n); a = a * Pow(Fac(n - r), p - 2) % p; a = a * Pow(Fac(r), p - 2) % p; return (int)a; } public int Fac(int n) { if (fac[n] >= 0) return fac[n]; long k = 1; for (long i = 1; i <= n; i++) { k = k * i % p; } fac[n] = (int)k; return fac[n]; } public int Pow(int n, int m) { if (m == 0) return 1; if (m == 1) return n; long a = 1; if (m % 2 == 0) { a = Pow(n, m / 2); a = a * a % p; } else { a = Pow(n, m / 2); a = a * a % p; a = a * n % p; } return (int)a; } }
[["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
8
859
5
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC128A { class Program { static void Main(string[] args) { { var word = Console.ReadLine().Split(); double a = double.Parse(word[0]); double b = double.Parse(word[1]); double max; max = ((a * 3) + b) / 2; Console.WriteLine(max); Console.ReadKey(); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC128A { class Program { static void Main(string[] args) { { var word = Console.ReadLine().Split(); int a = int.Parse(word[0]); int b = int.Parse(word[1]); int max; max = ((a * 3) + b) / 2; Console.WriteLine(max); Console.ReadKey(); } } } }
[["-", 8, 196, 0, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
117
10
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC128A { class Program { static void Main(string[] args) { int a, b, c, d; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[2]); c = (3 * a) + b; d = c / 2; Console.WriteLine(d); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC128A { class Program { static void Main(string[] args) { int a, b, c, d; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = (3 * a) + b; d = c / 2; Console.WriteLine(d); Console.ReadKey(); } } }
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
8
124
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class ABC128_A { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int a = int.Parse(str[0]); int p = int.Parse(str[1]); Console.Write((3 * a + p) / 2 - 1); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class ABC128_A { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int a = int.Parse(str[0]); int p = int.Parse(str[1]); Console.Write((3 * a + p) / 2); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
107
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace kyopro { class Program { static void Main(string[] args) { string[] ap = Console.ReadLine().Split(); int a = int.Parse(ap[0]); int p = int.Parse(ap[1]); Console.WriteLine((3 * a + p) / 3); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace kyopro { class Program { static void Main(string[] args) { string[] ap = Console.ReadLine().Split(); int a = int.Parse(ap[0]); int p = int.Parse(ap[1]); Console.WriteLine((3 * a + p) / 2); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
102
2
using System; class plogram { static void Main() { string apple = Console.ReadLine(); string[] array = apple.Split(','); int piese = int.Parse(array[1]); piese += int.Parse(array[0]) * 3; Console.WriteLine(piese / 2); } }
using System; class plogram { static void Main() { string apple = Console.ReadLine(); string[] array = apple.Split(' '); int piese = int.Parse(array[1]); piese += int.Parse(array[0]) * 3; Console.WriteLine(piese / 2); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253]]
8
73
2
using System; class Program { static void Main(string[] args) { string s = Console.ReadLine(); string[] math = s.Split(' '); int piece = 0; piece += int.Parse(math[0]) * 3; piece += int.Parse(math[1]); Console.WriteLine(piece); } }
using System; class Program { static void Main(string[] args) { string s = Console.ReadLine(); string[] math = s.Split(' '); int piece = 0; piece += int.Parse(math[0]) * 3; piece += int.Parse(math[1]); Console.WriteLine(piece / 2); } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
79
2
using System; class Program { static void Main(string[] args) { //まずは数を代入する string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int p = int.Parse(input[1]); //リンゴのかけらの数を求める int sum = a * 3 + p; //できるパイの数を計算 sum = sum / 3; //出力 Console.WriteLine(sum); } }
using System; class Program { static void Main(string[] args) { //まずは数を代入する string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int p = int.Parse(input[1]); //リンゴのかけらの数を求める int sum = a * 3 + p; //できるパイの数を計算 sum = sum / 2; //出力 Console.WriteLine(sum); } }
[["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
88
2
using System; using System.Collections.Generic; using System.Linq; class ABC128A { public static void Main() { var ap = Console.ReadLine().Split(' ').Select(int.Parse); Console.WriteLine(ap.ElementAt(0) * 3 + ap.ElementAt(1) / 2); } }
using System; using System.Collections.Generic; using System.Linq; class ABC128A { public static void Main() { var ap = Console.ReadLine().Split(' ').Select(int.Parse); Console.WriteLine((ap.ElementAt(0) * 3 + ap.ElementAt(1)) / 2); } }
[["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 12, 213, 3, 4, 0, 25]]
8
73
2
using System; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); sample[] PS = new sample[N]; for (int i = 0; i < N; i++) { string[] tmp = Console.ReadLine().Split(' ').ToArray(); PS[i] = new sample { Index = i + 1, city = tmp[0], num = tmp[1] }; } foreach (var a in PS.OrderBy(t => t.city).ThenByDescending(t => t.num)) { Console.WriteLine(a.Index); } } } class sample { public string city { get; set; } public string num { get; set; } public int Index { get; internal set; } } }
using System; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); sample[] PS = new sample[N]; for (int i = 0; i < N; i++) { string[] tmp = Console.ReadLine().Split(' ').ToArray(); PS[i] = new sample { Index = i + 1, city = tmp[0], num = int.Parse(tmp[1]) }; } foreach (var a in PS.OrderBy(t => t.city).ThenByDescending(t => t.num)) { Console.WriteLine(a.Index); } } } class sample { public string city { get; set; } public int num { get; set; } public int Index { get; internal set; } } }
[["+", 10, 229, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 10, 229, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 10, 229, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 10, 229, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 10, 229, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 235, 8, 201, 0, 277, 39, 199], ["+", 8, 201, 0, 235, 8, 201, 0, 277, 39, 199]]
8
187
7
using System; using System.Linq; using System.Collections.Generic; public class AtCoderB { static void Main() { int n = int.Parse(Console.ReadLine()); List<Tuple<int, string, int>> scores = new List<Tuple<int, string, int>>(); for (int i = 0; i < n; i++) { var line = Console.ReadLine(); var words = line.Split(' '); scores.Add(new Tuple<int, string, int>(i, words[0], int.Parse(words[1]))); } scores = scores.OrderBy(s => s.Item2).OrderByDescending(s => s.Item3).ToList(); foreach (var score in scores) { Console.WriteLine(score.Item1); } } }
using System; using System.Linq; using System.Collections.Generic; public class AtCoderB { static void Main() { int n = int.Parse(Console.ReadLine()); List<Tuple<int, string, int>> scores = new List<Tuple<int, string, int>>(); for (int i = 0; i < n; i++) { var line = Console.ReadLine(); var words = line.Split(' '); scores.Add( new Tuple<int, string, int>(i + 1, words[0], int.Parse(words[1]))); } scores = scores.OrderBy(s => s.Item2).ThenByDescending(s => s.Item3).ToList(); foreach (var score in scores) { Console.WriteLine(score.Item1); } } }
[["+", 0, 230, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 230, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 12, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 141, 22]]
8
183
4
using System; using System.Collections.Generic; // list用 using System.Text; // StringBuilder用 using System.Collections; using System.Linq; class Program { static List<int> s = new List<int>(); static List<string> t = new List<string>(); static decimal result; static StringBuilder sb = new StringBuilder(); static int N, M, K; static long[,] table; static void Main() { Read1(); Read5(); var pr = new PriorityQueue<decimal, int>(); decimal[] check = new decimal[N]; for (int i = 0; i < N; i++) { for (int j = 0; j < 10; j++) { if (j >= t[i].Length) { check[i] += 27 * (decimal)Math.Pow(28, j); } else { check[i] += (26 - t[i][j] + 'a') * (decimal)Math.Pow(28, j); } } check[i] += s[i]; } for (int i = 0; i < N; i++) { pr.Add(-check[i], i + 1); } for (int i = 0; i < N; i++) { result = pr.Dequeue().Value; Console.WriteLine(result.ToString()); } } static void Read1() // 1項 { string tmp = Console.ReadLine(); N = int.Parse(tmp); } static void Read2() //複数項(項目数N) { string[] tmp = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { s.Add(int.Parse(tmp[i])); } } static void Read3() // 1行複数項 { string[] tmp = Console.ReadLine().Split(' '); for (int i = 0; i < tmp.Length; i++) { s.Add(int.Parse(tmp[i])); } } static void Read4() // NK1行 { string[] tmp = Console.ReadLine().Split(' '); N = int.Parse(tmp[0]); K = int.Parse(tmp[1]); } static void Read5() // N行K項 { for (int i = 0; i < N; i++) { string[] tmp = Console.ReadLine().Split(' '); t.Add(tmp[0]); s.Add(int.Parse(tmp[1])); } } } class PriorityQueue<TKey, TValue> { SortedDictionary<TKey, Queue<TValue>> dict = new SortedDictionary<TKey, Queue<TValue>>(); int count = 0; public int Count { get { return count; } } public void Add(TKey key, TValue value) { if (!dict.ContainsKey(key)) { dict[key] = new Queue<TValue>(); } dict[key].Enqueue(value); count++; } public KeyValuePair<TKey, TValue> Dequeue() { var queue = dict.First(); if (queue.Value.Count <= 1) { dict.Remove(queue.Key); } count--; return new KeyValuePair<TKey, TValue>(queue.Key, queue.Value.Dequeue()); } }
using System; using System.Collections.Generic; // list用 using System.Text; // StringBuilder用 using System.Collections; using System.Linq; class Program { static List<int> s = new List<int>(); static List<string> t = new List<string>(); static decimal result; static StringBuilder sb = new StringBuilder(); static int N, M, K; static long[,] table; static void Main() { Read1(); Read5(); var pr = new PriorityQueue<decimal, int>(); decimal[] check = new decimal[N]; for (int i = 0; i < N; i++) { for (int j = 0; j < 10; j++) { if (j >= t[i].Length) { check[i] += 27 * (decimal)Math.Pow(28, 9 - j); } else { check[i] += (26 - t[i][j] + 'a') * (decimal)Math.Pow(28, 9 - j); } } check[i] += s[i]; } for (int i = 0; i < N; i++) { pr.Add(-check[i], i + 1); } for (int i = 0; i < N; i++) { result = pr.Dequeue().Value; Console.WriteLine(result.ToString()); } } static void Read1() // 1項 { string tmp = Console.ReadLine(); N = int.Parse(tmp); } static void Read2() //複数項(項目数N) { string[] tmp = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { s.Add(int.Parse(tmp[i])); } } static void Read3() // 1行複数項 { string[] tmp = Console.ReadLine().Split(' '); for (int i = 0; i < tmp.Length; i++) { s.Add(int.Parse(tmp[i])); } } static void Read4() // NK1行 { string[] tmp = Console.ReadLine().Split(' '); N = int.Parse(tmp[0]); K = int.Parse(tmp[1]); } static void Read5() // N行K項 { for (int i = 0; i < N; i++) { string[] tmp = Console.ReadLine().Split(' '); t.Add(tmp[0]); s.Add(int.Parse(tmp[1])); } } } class PriorityQueue<TKey, TValue> { SortedDictionary<TKey, Queue<TValue>> dict = new SortedDictionary<TKey, Queue<TValue>>(); int count = 0; public int Count { get { return count; } } public void Add(TKey key, TValue value) { if (!dict.ContainsKey(key)) { dict[key] = new Queue<TValue>(); } dict[key].Enqueue(value); count++; } public KeyValuePair<TKey, TValue> Dequeue() { var queue = dict.First(); if (queue.Value.Count <= 1) { dict.Remove(queue.Key); } count--; return new KeyValuePair<TKey, TValue>(queue.Key, queue.Value.Dequeue()); } }
[["+", 51, 213, 3, 4, 0, 28, 0, 16, 31, 203], ["+", 51, 213, 3, 4, 0, 28, 0, 16, 17, 33]]
8
731
4
using System; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); Tuple<string, int, int>[] val = new Tuple<string, int, int>[n]; for (int i = 0; i < n; i++) { var r = Console.ReadLine().Split(); val[i] = new Tuple<string, int, int>(r[0], int.Parse(r[1]), i); } var a = val.OrderBy(v => v.Item1).ThenByDescending(v => v.Item2).ToArray(); Console.WriteLine(string.Join("\n", a.Select(v => v.Item3))); } } }
using System; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); Tuple<string, int, int>[] val = new Tuple<string, int, int>[n]; for (int i = 0; i < n; i++) { var r = Console.ReadLine().Split(); val[i] = new Tuple<string, int, int>(r[0], int.Parse(r[1]), i); } var a = val.OrderBy(v => v.Item1).ThenByDescending(v => v.Item2).ToArray(); Console.WriteLine(string.Join("\n", a.Select(v => v.Item3 + 1))); } } }
[["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203]]
8
180
2
using System; using System.Text; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] S = new string[N]; int[] P = new int[N]; for (int i = 0; i < N; i++) { string[] input = Console.ReadLine().Split(' '); S[i] = input[0]; P[i] = int.Parse(input[1]); } List<Tuple<string, int, int>> list = new List<Tuple<string, int, int>>(); for (int j = 0; j < N; j++) { list.Add(new Tuple<string, int, int>(S[j], P[j], j)); } list.Sort((a, b) => (a.Item1 != b.Item1) ? (a.Item1.CompareTo(b.Item1)) : (b.Item2 - a.Item2)); foreach (var x in list) { Console.WriteLine(x.Item3); } } }
using System; using System.Text; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] S = new string[N]; int[] P = new int[N]; for (int i = 0; i < N; i++) { string[] input = Console.ReadLine().Split(' '); S[i] = input[0]; P[i] = int.Parse(input[1]); } List<Tuple<string, int, int>> list = new List<Tuple<string, int, int>>(); for (int j = 0; j < N; j++) { list.Add(new Tuple<string, int, int>(S[j], P[j], j)); } list.Sort((a, b) => (a.Item1 != b.Item1) ? (a.Item1.CompareTo(b.Item1)) : (b.Item2 - a.Item2)); foreach (var x in list) { Console.WriteLine(x.Item3 + 1); } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
281
2
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { public class Hoge { public string Name; public int Point; public int Index; } class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var list = new List<Hoge>(N); for (int i = 0; i < N; i++) { var temp = Console.ReadLine().Split(' '); list.Add(new Hoge { Name = temp[0], Point = int.Parse(temp[1]), Index = i + 1 }); } foreach (var result in list.OrderBy(o => o.Name).GroupBy(o => o.Point)) { foreach (var inn in result.OrderByDescending(o => o.Point)) { Console.WriteLine(inn.Index); } } } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { public class Hoge { public string Name; public int Point; public int Index; } class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var list = new List<Hoge>(N); for (int i = 0; i < N; i++) { var temp = Console.ReadLine().Split(' '); list.Add(new Hoge { Name = temp[0], Point = int.Parse(temp[1]), Index = i + 1 }); } foreach (var result in list.OrderBy(o => o.Name).GroupBy(o => o.Name)) { foreach (var inn in result.OrderByDescending(o => o.Point)) { Console.WriteLine(inn.Index); } } } } }
[["-", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22]]
8
197
2
using System; using System.Collections.Generic; namespace cswork { class Program { public Program() {} Scanner cin; void Omame() { cin = new Scanner(); int n = cin.nextInt(); int m = cin.nextInt(); List<int> sList = new List<int>(); for (int i = 0; i < m; i++) { int k = cin.nextInt(); int s = 0; for (int j = 0; j < k; j++) { int tmpS = cin.nextInt() - 1; s += 1 << tmpS; } sList.Add(s); } List<int> pList = new List<int>(); for (int i = 0; i < m; i++) { int p = cin.nextInt(); pList.Add(p); } int ans = 0; for (int i = 0; i < 1 << n; i++) { bool add = true; for (int j = 0; j < m; j++) { int s = i & sList[j]; int count = 0; for (int k = 0; k < m; k++) { if ((s >> k & 1) == 1) { count++; } } if (count % 2 != pList[j]) { add = false; break; } } if (add) ans++; } Console.WriteLine(ans); } static void Main(string[] args) { new Program().Omame(); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next(); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } }
using System; using System.Collections.Generic; namespace cswork { class Program { public Program() {} Scanner cin; void Omame() { cin = new Scanner(); int n = cin.nextInt(); int m = cin.nextInt(); List<int> sList = new List<int>(); for (int i = 0; i < m; i++) { int k = cin.nextInt(); int s = 0; for (int j = 0; j < k; j++) { int tmpS = cin.nextInt() - 1; s += 1 << tmpS; } sList.Add(s); } List<int> pList = new List<int>(); for (int i = 0; i < m; i++) { int p = cin.nextInt(); pList.Add(p); } int ans = 0; for (int i = 0; i < 1 << n; i++) { bool add = true; for (int j = 0; j < m; j++) { int s = i & sList[j]; int count = 0; for (int k = 0; k < n; k++) { if ((s >> k & 1) == 1) { count++; } } if (count % 2 != pList[j]) { add = false; break; } } if (add) ans++; } Console.WriteLine(ans); } static void Main(string[] args) { new Program().Omame(); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next(); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } }
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22]]
8
497
2
using System; using System.Linq; using System.Collections.Generic; namespace ABC128 { class C { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int M = int.Parse(input[1]); int[] k = new int[M]; int[,] s = new int[M, 10]; for (int i = 0; i < M; i++) { input = Console.ReadLine().Split(' '); k[i] = int.Parse(input[0]); for (int j = 1; j <= k[i]; j++) { s[i, j] = int.Parse(input[j]); // Console.WriteLine("---"); // Console.WriteLine(s[i, j]); } } input = Console.ReadLine().Split(' '); int[] p = new int[M]; for (int i = 0; i < M; i++) { p[i] = int.Parse(input[i]); } int[] a = new int[N]; CalcSw(N, a, M, k, s, p); Console.WriteLine(count); } static int count = 0; static void CalcSw(int N, int[] a, int M, int[] k, int[,] s, int[] p) { if (N == 0) { // foreach (var x in a) { Console.Write(x); } // Console.WriteLine(); // 一番下まできたら、Mとkでループして、 // 電気がついているかどうかを確認する // 計算したらメモ化再帰のでカウントする int c = 0; for (int i = 0; i < M; i++) { c = 0; // Console.WriteLine("------"); for (int j = 1; j <= k[i]; j++) { // Console.WriteLine(s[i, j]); if (a[s[i, j] - 1] == 1) { c++; } } // Console.WriteLine(); // Console.WriteLine("------"); if ((c % 2) != p[i]) { return; } } count++; return; } //ここでスイッチの状態を固定する処理を書く N--; a[N] = 0; CalcSw(N, a, M, k, s, p); a[N] = 1; CalcSw(N, a, M, k, s, p); } } }
using System; using System.Linq; using System.Collections.Generic; namespace ABC128 { class C { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int M = int.Parse(input[1]); int[] k = new int[M]; int[,] s = new int[M, 20]; for (int i = 0; i < M; i++) { input = Console.ReadLine().Split(' '); k[i] = int.Parse(input[0]); for (int j = 1; j <= k[i]; j++) { s[i, j] = int.Parse(input[j]); // Console.WriteLine("---"); // Console.WriteLine(s[i, j]); } } input = Console.ReadLine().Split(' '); int[] p = new int[M]; for (int i = 0; i < M; i++) { p[i] = int.Parse(input[i]); } int[] a = new int[N]; CalcSw(N, a, M, k, s, p); Console.WriteLine(count); } static int count = 0; static void CalcSw(int N, int[] a, int M, int[] k, int[,] s, int[] p) { if (N == 0) { // foreach (var x in a) { Console.Write(x); } // Console.WriteLine(); // 一番下まできたら、Mとkでループして、 // 電気がついているかどうかを確認する // 計算したらメモ化再帰のでカウントする int c = 0; for (int i = 0; i < M; i++) { c = 0; // Console.WriteLine("------"); for (int j = 1; j <= k[i]; j++) { // Console.WriteLine(s[i, j]); if (a[s[i, j] - 1] == 1) { c++; } } // Console.WriteLine(); // Console.WriteLine("------"); if ((c % 2) != p[i]) { return; } } count++; return; } //ここでスイッチの状態を固定する処理を書く N--; a[N] = 0; CalcSw(N, a, M, k, s, p); a[N] = 1; CalcSw(N, a, M, k, s, p); } } }
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203]]
8
468
2
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; } 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(); } } 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 long p1097 = 1000000007; static void Main(string[] args) { //↓ var nm = ReadIntArray(); var n = nm[0]; var m = nm[1]; var kss = new List<List<int>>(m); for (int i = 0; i < m; i++) { var ks = ReadIntArray().Skip(1).ToList(); ks.Sort(); ks.Reverse(); kss.Add(ks); } var ps = ReadIntArray(); var results = new HashSet<int>(Enumerable.Range(0, (int)Math.Pow(2, n))); var bits = new bool[n]; for (int i = 0; i < m; i++) { var p = ps[i]; var ks = kss[i]; var rs = new HashSet<int>(); foreach (var r in results) { var rr = r; for (int j = n - 1; j >= 0; j--) { var pow = (int)Math.Pow(2, j); if (rr >= pow) { bits[j] = true; rr -= pow; } else { bits[j] = false; } } var count = 0; for (int j = 0; j < ks.Count; j++) { if (bits[j]) count++; } if (count % 2 != p) { rs.Add(r); } } foreach (var r in rs) { results.Remove(r); } } Console.WriteLine(results.Count); //↑ } } }
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; } 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(); } } 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 long p1097 = 1000000007; static void Main(string[] args) { //↓ var nm = ReadIntArray(); var n = nm[0]; var m = nm[1]; var kss = new List<List<int>>(m); for (int i = 0; i < m; i++) { var ks = ReadIntArray().Skip(1).ToList(); ks.Sort(); ks.Reverse(); kss.Add(ks); } var ps = ReadIntArray(); var results = new HashSet<int>(Enumerable.Range(0, (int)Math.Pow(2, n))); var bits = new bool[n]; for (int i = 0; i < m; i++) { var p = ps[i]; var ks = kss[i]; var rs = new HashSet<int>(); foreach (var r in results) { var rr = r; for (int j = n - 1; j >= 0; j--) { var pow = (int)Math.Pow(2, j); if (rr >= pow) { bits[j] = true; rr -= pow; } else { bits[j] = false; } } var count = 0; for (int j = 0; j < ks.Count; j++) { if (bits[ks[j] - 1]) count++; } if (count % 2 != p) { rs.Add(r); } } foreach (var r in rs) { results.Remove(r); } } Console.WriteLine(results.Count); //↑ } } }
[["+", 206, 207, 0, 28, 0, 16, 31, 204, 205, 22], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 15, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 15, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
2,220
5
using System; using System.Collections.Generic; using System.Text; using System.Numerics; using System.IO; namespace SolutionCS { 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 maxSW = (int)Math.Pow(2, N); int[] count = new int[M]; int[] mask = new int[M]; for (int i = 0; i < M; i++) { s = Console.ReadLine().Split(' '); int K = int.Parse(s[0]); for (int j = 0; j < K; j++) { mask[i] |= (1 << (int.Parse(s[j + 1]) - 1)); } } s = Console.ReadLine().Split(' '); for (int i = 0; i < M; i++) { count[i] = int.Parse(s[i]); } int ans = 0; for (int i = 0; i < maxSW; i++) { bool isOn = true; for (int j = 0; j < M; j++) { int r = i & mask[j]; if (count[j] != bitCount(r) % 2) { isOn = false; break; } } if (isOn) { ans++; } } Console.WriteLine(ans); } static int[] bitC = new int[] { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; static int bitCount(int i) { int c = 0; while (i > 0) { c += bitC[i & 0x0f]; i >>= 8; } return c; } } }
using System; using System.Collections.Generic; using System.Text; using System.Numerics; using System.IO; namespace SolutionCS { 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 maxSW = (int)Math.Pow(2, N); int[] count = new int[M]; int[] mask = new int[M]; for (int i = 0; i < M; i++) { s = Console.ReadLine().Split(' '); int K = int.Parse(s[0]); for (int j = 0; j < K; j++) { mask[i] |= (1 << (int.Parse(s[j + 1]) - 1)); } } s = Console.ReadLine().Split(' '); for (int i = 0; i < M; i++) { count[i] = int.Parse(s[i]); } int ans = 0; for (int i = 0; i < maxSW; i++) { bool isOn = true; for (int j = 0; j < M; j++) { int r = i & mask[j]; if (count[j] != bitCount(r) % 2) { isOn = false; break; } } if (isOn) { ans++; } } Console.WriteLine(ans); } static int[] bitC = new int[] { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; static int bitCount(int i) { int c = 0; while (i > 0) { c += bitC[i & 0x0f]; i >>= 4; } return c; } } }
[["-", 0, 52, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 12, 203]]
8
428
2
using System; using System.Linq; using System.Collections.Generic; using System.Text; using static System.Console; using static System.Math; class Program { static void Main(string[] args) { int[] NM = ReadLineParseIntArray(); int N = NM[0]; int M = NM[1]; int[][] s = new int [M][]; for (int i = 0; i < M; i++) s[i] = ReadLine().Split(' ').Skip(1).Select(x => int.Parse(x) - 1).ToArray(); int[] p = ReadLineParseIntArray(); int n = (int)Pow(2, N); int ans = 0; for (int i = 0; i <= n; i++) { bool isOK = true; for (int m = 0; m < M; m++) { int number = 0; for (int j = 0; j < s[m].Length; j++) { if (((i >> s[m][j]) & 1) == 1) number++; } if (number % 2 != p[m]) { isOK = false; break; } } if (isOK) ans++; } WriteLine(ans); } static int ReadLineParseInt() => int.Parse(ReadLine()); static int[] ReadLineParseIntArray() => ReadLine().Split(' ').Select(int.Parse).ToArray(); }
using System; using System.Linq; using System.Collections.Generic; using System.Text; using static System.Console; using static System.Math; class Program { static void Main(string[] args) { int[] NM = ReadLineParseIntArray(); int N = NM[0]; int M = NM[1]; int[][] s = new int [M][]; for (int i = 0; i < M; i++) s[i] = ReadLine().Split(' ').Skip(1).Select(x => int.Parse(x) - 1).ToArray(); int[] p = ReadLineParseIntArray(); int n = (int)Pow(2, N); int ans = 0; for (int i = 0; i < n; i++) { bool isOK = true; for (int m = 0; m < M; m++) { int number = 0; for (int j = 0; j < s[m].Length; j++) { if (((i >> s[m][j]) & 1) == 1) number++; } if (number % 2 != p[m]) { isOK = false; break; } } if (isOK) ans++; } WriteLine(ans); } static int ReadLineParseInt() => int.Parse(ReadLine()); static int[] ReadLineParseIntArray() => ReadLine().Split(' ').Select(int.Parse).ToArray(); }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18]]
8
329
2
using System; using System.Linq; using System.Collections.Generic; namespace ABC127 { class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int[] n = s.Select(x => int.Parse(x)).ToArray(); int RR = n[0]; int LL = 1; int L, R = 1; for (int i = 0; i < n[1]; i++) { s = Console.ReadLine().Split(' '); L = int.Parse(s[0]); R = int.Parse(s[1]); if (LL > R || RR < L) { Console.WriteLine("0"); return; } if (LL < L) { LL = L; } if (R < RR) { RR = R; } Console.WriteLine(RR - LL + 1); } } } }
using System; using System.Linq; using System.Collections.Generic; namespace ABC127 { class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int[] n = s.Select(x => int.Parse(x)).ToArray(); int RR = n[0]; int LL = 1; int L, R = 1; for (int i = 0; i < n[1]; i++) { s = Console.ReadLine().Split(' '); L = int.Parse(s[0]); R = int.Parse(s[1]); if (LL > R || RR < L) { Console.WriteLine(0); return; } if (LL < L) { LL = L; } if (R < RR) { RR = R; } } Console.WriteLine(RR - LL + 1); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
211
4
using System; using System.Collections.Generic; using System.Linq; public static class Program { public static void Main(string[] args) { var nm = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var min = 1; var max = nm[0]; for (int i = 0; i < nm[1]; i++) { var door = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); min = min < door[0] ? door[0] : min; max = max > door[1] ? door[1] : max; } Console.WriteLine(max > min ? max - min + 1 : 0); } }
using System; using System.Collections.Generic; using System.Linq; public static class Program { public static void Main(string[] args) { var nm = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var min = 1; var max = nm[0]; for (int i = 0; i < nm[1]; i++) { var door = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); min = min < door[0] ? door[0] : min; max = max > door[1] ? door[1] : max; } Console.WriteLine(max >= min ? max - min + 1 : 0); } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 47], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 20]]
8
178
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; #if !DEBUG using System.IO; #endif public class Program { public static void Main() { #region SetAutoFlushIsFalse #if !DEBUG var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); #endif #endregion var nm = ReadLib.ReadAsIntArray(); var lrArr = ReadLib.ReadNTimesAsIntArray(nm[1]); var maxLeft = lrArr.Select(a => a[0]).Max(); var minRight = lrArr.Select(a => a[1]).Min(); var rawScore = maxLeft - minRight + 1; Console.WriteLine(rawScore < 0 ? 0 : rawScore); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } static class Quick { internal static void Calculate(int[] ts) { QuickSort(ts, 0, ts.Count() - 1); } private static void QuickSort(int[] ts, int p, int r) { if (p < r) { var q = Partition(ts, p, r); QuickSort(ts, p, q - 1); QuickSort(ts, q + 1, r); } } public static int Partition(int[] sArr, int p, int r) { var x = sArr[r]; var i = p - 1; for (int j = p; j < r; j++) { if (sArr[j] <= x) { i++; sArr.Swap(i, j); } } sArr.Swap(i + 1, r); return i + 1; } } static class ReadLib { public static long ReadAsLong() { return long.Parse(Console.ReadLine()); } public static int ReadAsInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadAsIntArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => int.Parse(s) + step) .ToArray(); } public static long[] ReadAsLongArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => long.Parse(s) + step) .ToArray(); } public static ulong[] ReadAsULongArray() { return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray(); } public static string[] ReadAsStringArray() { return Console.ReadLine().Split(' '); } public static int[] ReadNTimesAsInt(int n, int step = 0) { return Enumerable.Range(1, n) .Select(s => int.Parse(Console.ReadLine()) + step) .ToArray(); } public static int[][] ReadNTimesAsIntArray(int n, int step = 0) { return Enumerable.Range(1, n).Select(s => ReadAsIntArray(step)).ToArray(); } public static string[] ReadNTimesAsString(int n) { return Enumerable.Range(1, n).Select(s => Console.ReadLine()).ToArray(); } } static class WriteLib { public static void Write<T>(IEnumerable<T> ts) { ts.ToList().ForEach(s => Console.WriteLine(s)); } } static class MyMath { /// <summary>階乗</summary> public static long Factorial(int n) { if (n == 0) { return 1; } return Permutation(n, 0); } public static long Permutation(int n, int k) { return Enumerable.Range(0, n - k) .Select(i => n - i) .Aggregate(1, (b, i) => b * i); } #region FullPower /// <summary>総乗、π</summary> public static long FullPower(IEnumerable<long> vs) { return vs.Aggregate(1L, (a, b) => a * b); } public static long FullPower(IEnumerable<int> vs) { return vs.Aggregate(1L, (a, b) => a * b); } #endregion /// <summary>最大公約数</summary> public static long Gcd(long item1, long item2) { var a = Math.Max(item1, item2); var b = Math.Min(item1, item2); while (true) { long mod; Math.DivRem(a, b, out mod); if (mod == 0) { break; } a = b; b = mod; } return b; } /// <summary>約分。最大公約数で割ったものを返す。</summary> public static Tuple<long, long> DeviedByGcd(long item1, long item2) { var gcd = Gcd(item1, item2); return new Tuple<long, long>(item1 / gcd, item2 / gcd); } public static long Lcm(int item1, int item2) { return Math.BigMul(item1, item2) / Gcd(item1, item2); } public static ModCombination ModCombination(int maxN, int mod = 1000000007) { return new ModCombination(maxN, mod); } /// <summary>a^n mod</summary> public static int ModPow(int a, int n, int mod = 1000000007) { var res = 1; while (n > 0) { if ((n & 1) == 1) { res = (int)(Math.BigMul(res % mod, a) % mod); // resにaをかける } a = (int)(Math.Pow(a % mod, 2) % mod); // 次のaはa^2 n >>= 1; } return res; } } static class MyMethod { /// <summary>数え上げて、key, 出現回数に変換</summary> public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) { return str.GroupBy(c => c) .Select(g => new KeyValuePair<T, int>(g.Key, g.Count())) .ToDictionary(e => e.Key, e => e.Value); } } /// <summary>DeepCopyするクラス</summary> class DeepCopier { BinaryFormatter b = new BinaryFormatter(); public T DeepCopy<T>(T obj) { T result; using (var mem = new MemoryStream()) { b.Serialize(mem, obj); // binaryFormatterによりobjをmemにserial化して書き出す mem.Position = 0; // memのpotisionを先頭に戻す result = (T)b.Deserialize(mem); // memの内容を読み取る。 } return result; } } static class MergeSort { public static long[] Sort(long[] arr) { return Sort(arr, 0, arr.Count()); } // rightは+1されていることに注意 private static long[] Merge(long[] sArr, int left, int mid, int right) { var n1 = mid - left; var n2 = right - mid; var lArr = new long[n1 + 1]; var rArr = new long[n2 + 1]; for (int i = 0; i < n1; i++) { lArr[i] = sArr[left + i]; } lArr[n1] = int.MaxValue; for (int i = 0; i < n2; i++) { rArr[i] = sArr[mid + i]; } rArr[n2] = int.MaxValue; int l = 0, r = 0; for (int k = left; k < right; k++) { if (lArr[l] <= rArr[r]) { sArr[k] = lArr[l]; l++; } else { sArr[k] = rArr[r]; r++; } } return sArr; // 要素数はright - left } private static long[] Sort(long[] sArr, int left, int right) { if (left + 1 < right) { var mid = (left + right) / 2; sArr = Sort(sArr, left, mid); sArr = Sort(sArr, mid, right); sArr = Merge(sArr, left, mid, right); } return sArr; } } /// <summary>あまりを計算するためのintのラッパー</summary> struct ModInt { int Value { get; } int Mod { get; } public override string ToString() { return Value.ToString(); } public static explicit operator ModInt(long value) { return new ModInt(value); } public ModInt(long value, int mod = 1000000007) { this.Value = (int)(value % mod); this.Mod = mod; } public static explicit operator int(ModInt modInt) { return modInt.Value; } private static void CheckNotEqualMod(ModInt item1, ModInt item2) { if (item1.Mod != item2.Mod) { throw new Exception("mod not equal"); } } public static ModInt operator +(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value + item2.Value; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = Math.BigMul(item1.Value, item2.Value); return new ModInt(value, item1.Mod); } public static ModInt operator -(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value - item2.Value; if (value < 0) { value += item1.Mod; } return new ModInt(value, item1.Mod); } public static ModInt operator +(ModInt item1, int item2) { return item1 + new ModInt(item2, item1.Mod); } public static ModInt operator *(ModInt item1, int item2) { return item1 * new ModInt(item2, item1.Mod); } public static ModInt operator -(ModInt item1, int item2) { return item1 - new ModInt(item2, item1.Mod); } public override int GetHashCode() { return this.Value; } public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return false; } var modIntObj = (ModInt)obj; return modIntObj.Value == this.Value; } public static bool operator ==(ModInt item1, ModInt item2) { return item1.Value == item2.Value; } public static bool operator !=(ModInt item1, ModInt item2) { return !(item1 == item2); } public static bool operator ==(ModInt item1, int item2) { return item1.Value == item2; } public static bool operator !=(ModInt item1, int item2) { return !(item1.Value == item2); } public static bool operator >=(ModInt item1, ModInt item2) { return item1.Value >= item2.Value; } public static bool operator <=(ModInt item1, ModInt item2) { return item1.Value <= item2.Value; } public static bool operator >=(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator <=(ModInt item1, int item2) { return item1.Value <= item2; } public static bool operator>(ModInt item1, ModInt item2) { return item1.Value > item2.Value; } public static bool operator<(ModInt item1, ModInt item2) { return item1.Value < item2.Value; } public static bool operator>(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator<(ModInt item1, int item2) { return item1.Value <= item2; } } /// <summary>組み合わせ</summary> class ModCombination { private int mod; private int[] fac; private int[] finv; private int[] inv; public ModCombination(int max, int mod = 1000000007) { this.mod = mod; fac = new int[max]; // modが法のn!の列 inv = new int[max]; // indexの逆元の列 finv = new int[max]; // modを法とした、invの累積の累積 fac[0] = 1; fac[1] = 1; finv[0] = 1; finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; i++) { fac[i] = (int)(Math.BigMul(fac[i - 1], i) % mod); // factorを求める var s = Math.BigMul(inv[mod % i], mod / i) % mod; inv[i] = (int)(mod - s);   // iに対する逆元を求める finv[i] = (int)(Math.BigMul(finv[i - 1], inv[i]) % mod); } } /// <summary>nCk</summary> public int Calculation(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return (int)(Math.BigMul(fac[n], (int)(Math.BigMul(finv[k], finv[n - k]) % mod)) % mod); } } /// <summary>拡張メソッドs</summary> static class Extention { /// <summary>iとjを入れ替える</summary> public static void Swap<T>(this T[] arr, int i, int j) { var buf = arr[i]; arr[i] = arr[j]; arr[j] = buf; } /// <summary> /// partition。末尾sArr[r]を基準として、左に基準より小さい数、右に基準より大きい数が存在するように配列を並び替える。 /// </summary> /// <param name="sArr"></param> /// <param name="p">partitionの先頭の添字</param> /// <param name="r">partitionの末尾の添字</param> /// <returns>partitionの基準が存在する添字</returns> public static int Partition(this int[] sArr, int p, int r) { var x = sArr[r]; var i = p - 1; for (int j = p; j < r; j++) { if (sArr[j] <= x) { i++; sArr.Swap(i, j); } } sArr.Swap(i + 1, r); return i + 1; } /// <summary>深いコピーをする</summary> public static T DeepCopy<T>(this T obj) { T result; var b = new BinaryFormatter(); using (var mem = new MemoryStream()) { b.Serialize(mem, obj); // binaryFormatterによりobjをmemにserial化して書き出す mem.Position = 0; // memのpotisionを先頭に戻す result = (T)b.Deserialize(mem); // memの内容を読み取る。 } return result; } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; #if !DEBUG using System.IO; #endif public class Program { public static void Main() { #region SetAutoFlushIsFalse #if !DEBUG var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); #endif #endregion var nm = ReadLib.ReadAsIntArray(); var lrArr = ReadLib.ReadNTimesAsIntArray(nm[1]); var maxLeft = lrArr.Select(a => a[0]).Max(); var minRight = lrArr.Select(a => a[1]).Min(); var rawScore = minRight - maxLeft + 1; Console.WriteLine(rawScore < 0 ? 0 : rawScore); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } static class Quick { internal static void Calculate(int[] ts) { QuickSort(ts, 0, ts.Count() - 1); } private static void QuickSort(int[] ts, int p, int r) { if (p < r) { var q = Partition(ts, p, r); QuickSort(ts, p, q - 1); QuickSort(ts, q + 1, r); } } public static int Partition(int[] sArr, int p, int r) { var x = sArr[r]; var i = p - 1; for (int j = p; j < r; j++) { if (sArr[j] <= x) { i++; sArr.Swap(i, j); } } sArr.Swap(i + 1, r); return i + 1; } } static class ReadLib { public static long ReadAsLong() { return long.Parse(Console.ReadLine()); } public static int ReadAsInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadAsIntArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => int.Parse(s) + step) .ToArray(); } public static long[] ReadAsLongArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => long.Parse(s) + step) .ToArray(); } public static ulong[] ReadAsULongArray() { return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray(); } public static string[] ReadAsStringArray() { return Console.ReadLine().Split(' '); } public static int[] ReadNTimesAsInt(int n, int step = 0) { return Enumerable.Range(1, n) .Select(s => int.Parse(Console.ReadLine()) + step) .ToArray(); } public static int[][] ReadNTimesAsIntArray(int n, int step = 0) { return Enumerable.Range(1, n).Select(s => ReadAsIntArray(step)).ToArray(); } public static string[] ReadNTimesAsString(int n) { return Enumerable.Range(1, n).Select(s => Console.ReadLine()).ToArray(); } } static class WriteLib { public static void Write<T>(IEnumerable<T> ts) { ts.ToList().ForEach(s => Console.WriteLine(s)); } } static class MyMath { /// <summary>階乗</summary> public static long Factorial(int n) { if (n == 0) { return 1; } return Permutation(n, 0); } public static long Permutation(int n, int k) { return Enumerable.Range(0, n - k) .Select(i => n - i) .Aggregate(1, (b, i) => b * i); } #region FullPower /// <summary>総乗、π</summary> public static long FullPower(IEnumerable<long> vs) { return vs.Aggregate(1L, (a, b) => a * b); } public static long FullPower(IEnumerable<int> vs) { return vs.Aggregate(1L, (a, b) => a * b); } #endregion /// <summary>最大公約数</summary> public static long Gcd(long item1, long item2) { var a = Math.Max(item1, item2); var b = Math.Min(item1, item2); while (true) { long mod; Math.DivRem(a, b, out mod); if (mod == 0) { break; } a = b; b = mod; } return b; } /// <summary>約分。最大公約数で割ったものを返す。</summary> public static Tuple<long, long> DeviedByGcd(long item1, long item2) { var gcd = Gcd(item1, item2); return new Tuple<long, long>(item1 / gcd, item2 / gcd); } public static long Lcm(int item1, int item2) { return Math.BigMul(item1, item2) / Gcd(item1, item2); } public static ModCombination ModCombination(int maxN, int mod = 1000000007) { return new ModCombination(maxN, mod); } /// <summary>a^n mod</summary> public static int ModPow(int a, int n, int mod = 1000000007) { var res = 1; while (n > 0) { if ((n & 1) == 1) { res = (int)(Math.BigMul(res % mod, a) % mod); // resにaをかける } a = (int)(Math.Pow(a % mod, 2) % mod); // 次のaはa^2 n >>= 1; } return res; } } static class MyMethod { /// <summary>数え上げて、key, 出現回数に変換</summary> public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) { return str.GroupBy(c => c) .Select(g => new KeyValuePair<T, int>(g.Key, g.Count())) .ToDictionary(e => e.Key, e => e.Value); } } /// <summary>DeepCopyするクラス</summary> class DeepCopier { BinaryFormatter b = new BinaryFormatter(); public T DeepCopy<T>(T obj) { T result; using (var mem = new MemoryStream()) { b.Serialize(mem, obj); // binaryFormatterによりobjをmemにserial化して書き出す mem.Position = 0; // memのpotisionを先頭に戻す result = (T)b.Deserialize(mem); // memの内容を読み取る。 } return result; } } static class MergeSort { public static long[] Sort(long[] arr) { return Sort(arr, 0, arr.Count()); } // rightは+1されていることに注意 private static long[] Merge(long[] sArr, int left, int mid, int right) { var n1 = mid - left; var n2 = right - mid; var lArr = new long[n1 + 1]; var rArr = new long[n2 + 1]; for (int i = 0; i < n1; i++) { lArr[i] = sArr[left + i]; } lArr[n1] = int.MaxValue; for (int i = 0; i < n2; i++) { rArr[i] = sArr[mid + i]; } rArr[n2] = int.MaxValue; int l = 0, r = 0; for (int k = left; k < right; k++) { if (lArr[l] <= rArr[r]) { sArr[k] = lArr[l]; l++; } else { sArr[k] = rArr[r]; r++; } } return sArr; // 要素数はright - left } private static long[] Sort(long[] sArr, int left, int right) { if (left + 1 < right) { var mid = (left + right) / 2; sArr = Sort(sArr, left, mid); sArr = Sort(sArr, mid, right); sArr = Merge(sArr, left, mid, right); } return sArr; } } /// <summary>あまりを計算するためのintのラッパー</summary> struct ModInt { int Value { get; } int Mod { get; } public override string ToString() { return Value.ToString(); } public static explicit operator ModInt(long value) { return new ModInt(value); } public ModInt(long value, int mod = 1000000007) { this.Value = (int)(value % mod); this.Mod = mod; } public static explicit operator int(ModInt modInt) { return modInt.Value; } private static void CheckNotEqualMod(ModInt item1, ModInt item2) { if (item1.Mod != item2.Mod) { throw new Exception("mod not equal"); } } public static ModInt operator +(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value + item2.Value; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = Math.BigMul(item1.Value, item2.Value); return new ModInt(value, item1.Mod); } public static ModInt operator -(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value - item2.Value; if (value < 0) { value += item1.Mod; } return new ModInt(value, item1.Mod); } public static ModInt operator +(ModInt item1, int item2) { return item1 + new ModInt(item2, item1.Mod); } public static ModInt operator *(ModInt item1, int item2) { return item1 * new ModInt(item2, item1.Mod); } public static ModInt operator -(ModInt item1, int item2) { return item1 - new ModInt(item2, item1.Mod); } public override int GetHashCode() { return this.Value; } public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return false; } var modIntObj = (ModInt)obj; return modIntObj.Value == this.Value; } public static bool operator ==(ModInt item1, ModInt item2) { return item1.Value == item2.Value; } public static bool operator !=(ModInt item1, ModInt item2) { return !(item1 == item2); } public static bool operator ==(ModInt item1, int item2) { return item1.Value == item2; } public static bool operator !=(ModInt item1, int item2) { return !(item1.Value == item2); } public static bool operator >=(ModInt item1, ModInt item2) { return item1.Value >= item2.Value; } public static bool operator <=(ModInt item1, ModInt item2) { return item1.Value <= item2.Value; } public static bool operator >=(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator <=(ModInt item1, int item2) { return item1.Value <= item2; } public static bool operator>(ModInt item1, ModInt item2) { return item1.Value > item2.Value; } public static bool operator<(ModInt item1, ModInt item2) { return item1.Value < item2.Value; } public static bool operator>(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator<(ModInt item1, int item2) { return item1.Value <= item2; } } /// <summary>組み合わせ</summary> class ModCombination { private int mod; private int[] fac; private int[] finv; private int[] inv; public ModCombination(int max, int mod = 1000000007) { this.mod = mod; fac = new int[max]; // modが法のn!の列 inv = new int[max]; // indexの逆元の列 finv = new int[max]; // modを法とした、invの累積の累積 fac[0] = 1; fac[1] = 1; finv[0] = 1; finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; i++) { fac[i] = (int)(Math.BigMul(fac[i - 1], i) % mod); // factorを求める var s = Math.BigMul(inv[mod % i], mod / i) % mod; inv[i] = (int)(mod - s);   // iに対する逆元を求める finv[i] = (int)(Math.BigMul(finv[i - 1], inv[i]) % mod); } } /// <summary>nCk</summary> public int Calculation(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return (int)(Math.BigMul(fac[n], (int)(Math.BigMul(finv[k], finv[n - k]) % mod)) % mod); } } /// <summary>拡張メソッドs</summary> static class Extention { /// <summary>iとjを入れ替える</summary> public static void Swap<T>(this T[] arr, int i, int j) { var buf = arr[i]; arr[i] = arr[j]; arr[j] = buf; } /// <summary> /// partition。末尾sArr[r]を基準として、左に基準より小さい数、右に基準より大きい数が存在するように配列を並び替える。 /// </summary> /// <param name="sArr"></param> /// <param name="p">partitionの先頭の添字</param> /// <param name="r">partitionの末尾の添字</param> /// <returns>partitionの基準が存在する添字</returns> public static int Partition(this int[] sArr, int p, int r) { var x = sArr[r]; var i = p - 1; for (int j = p; j < r; j++) { if (sArr[j] <= x) { i++; sArr.Swap(i, j); } } sArr.Swap(i + 1, r); return i + 1; } /// <summary>深いコピーをする</summary> public static T DeepCopy<T>(this T obj) { T result; var b = new BinaryFormatter(); using (var mem = new MemoryStream()) { b.Serialize(mem, obj); // binaryFormatterによりobjをmemにserial化して書き出す mem.Position = 0; // memのpotisionを先頭に戻す result = (T)b.Deserialize(mem); // memの内容を読み取る。 } return result; } }
[["-", 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, 17, 33], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 12, 22]]
8
2,845
4
using System; using System.Collections.Generic; using System.Linq; using static System.Math; namespace ConsoleApp1 { class Program { static void Main(string[] args) { A(); } static void A() { var NM = ReadSplitInt(); var LR = new List<List<int>>(); var Lmax = 0; var Rmin = int.MaxValue; for (int i = 0; i < NM[1]; i++) { var lr = ReadSplitInt(); Lmax = Max(Lmax, lr[0]); Rmin = Min(Rmin, lr[1]); } var ans = 0; for (int i = 1; i <= NM[0]; i++) { if (Lmax <= i && i <= Rmin) ans++; } } static List<int> ReadLines(int n) { var l = new List<int>(); for (int i = 0; i < n; i++) { l.Add(ReadInt()); } return l; } static IEnumerable<int> Range(int start, int stop) { if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0)) return new List<int>(); return Enumerable.Range(start, stop - start); } static bool IsDigit(string str) { var i = 0; return int.TryParse(str, out i); } static int SumDigits(long num) { return num.ToString().Select(x => x.ToString()).Sum(int.Parse); } static int[] ToIntArray(string str) { return str.Select(x => x.ToString()).Select(int.Parse).ToArray(); } static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b); static bool IsPrime(int x) { if (x <= 1 || (x != 2 && x % 2 == 0)) return false; if (x == 2) return true; for (int i = 3; i < x; i += 2) if (x % i == 0) return false; return true; } static string Read() => Console.ReadLine(); static int ReadInt() => int.Parse(Read()); static long ReadLong() => long.Parse(Read()); static List<string> ReadSplit() => Read().Split().ToList(); static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList(); static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList(); static void Print(object value) => Console.Write(value.ToString()); static void Println(object value) => Console.WriteLine(value.ToString()); static string Join<T>(IEnumerable<T> list) => string.Join("", list); } public static class MyExtensions { public static string Slice(this string str, int start = 0, int stop = 0) { if (start > str.Length || stop > str.Length || start < 0 || stop < 0) return ""; if (stop == 0) stop = str.Length; return str.Substring(start, stop - start); } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; namespace ConsoleApp1 { class Program { static void Main(string[] args) { A(); } static void A() { var NM = ReadSplitInt(); var LR = new List<List<int>>(); var Lmax = 0; var Rmin = int.MaxValue; for (int i = 0; i < NM[1]; i++) { var lr = ReadSplitInt(); Lmax = Max(Lmax, lr[0]); Rmin = Min(Rmin, lr[1]); } var ans = 0; for (int i = 1; i <= NM[0]; i++) { if (Lmax <= i && i <= Rmin) ans++; } Println(ans); } static List<int> ReadLines(int n) { var l = new List<int>(); for (int i = 0; i < n; i++) { l.Add(ReadInt()); } return l; } static IEnumerable<int> Range(int start, int stop) { if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0)) return new List<int>(); return Enumerable.Range(start, stop - start); } static bool IsDigit(string str) { var i = 0; return int.TryParse(str, out i); } static int SumDigits(long num) { return num.ToString().Select(x => x.ToString()).Sum(int.Parse); } static int[] ToIntArray(string str) { return str.Select(x => x.ToString()).Select(int.Parse).ToArray(); } static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b); static bool IsPrime(int x) { if (x <= 1 || (x != 2 && x % 2 == 0)) return false; if (x == 2) return true; for (int i = 3; i < x; i += 2) if (x % i == 0) return false; return true; } static string Read() => Console.ReadLine(); static int ReadInt() => int.Parse(Read()); static long ReadLong() => long.Parse(Read()); static List<string> ReadSplit() => Read().Split().ToList(); static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList(); static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList(); static void Print(object value) => Console.Write(value.ToString()); static void Println(object value) => Console.WriteLine(value.ToString()); static string Join<T>(IEnumerable<T> list) => string.Join("", list); } public static class MyExtensions { public static string Slice(this string str, int start = 0, int stop = 0) { if (start > str.Length || stop > str.Length || start < 0 || stop < 0) return ""; if (stop == 0) stop = str.Length; return str.Substring(start, stop - start); } } }
[["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 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
729
5
using System; using System.Collections.Generic; using System.Linq; using static System.Console; namespace AtCoder.Probrems.Solvers.ABC127 { public class C { static void Main(string[] args) { var nm = ReadLine().Split().Select(int.Parse).ToArray(); var gates = Enumerable.Range(0, nm[0]).Select(_ => ReadLine().Split()); WriteLine(Solve(nm[0], nm[1], gates)); } public static long Solve(int n, int m, IEnumerable<string[]> gates) { int h = 0; int t = int.MaxValue; foreach (var gate in gates) { h = Math.Max(int.Parse(gate[0]), h); t = Math.Min(int.Parse(gate[1]), t); if (h > t) return 0; } return t - h + 1; } private const int MOD = 1000000007; } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; namespace AtCoder.Probrems.Solvers.ABC127 { public class C { static void Main(string[] args) { var nm = ReadLine().Split().Select(int.Parse).ToArray(); var gates = Enumerable.Range(0, nm[1]).Select(_ => ReadLine().Split()); WriteLine(Solve(nm[0], nm[1], gates)); } public static long Solve(int n, int m, IEnumerable<string[]> gates) { int h = 0; int t = int.MaxValue; foreach (var gate in gates) { h = Math.Max(int.Parse(gate[0]), h); t = Math.Min(int.Parse(gate[1]), t); if (h > t) return 0; } return t - h + 1; } private const int MOD = 1000000007; } }
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
8
218
2
using System; using System.Collections.Generic; using System.Linq; using static System.Math; namespace CSharp { static class Program { static void Main(string[] args) { int n, m; ReadInt(out n, out m); var gates = Enumerable.Repeat(0, m) .Select(_ => { int l, r; ReadInt(out l, out r); return new { L = l, R = r }; }) .ToArray(); int maxL = gates.Max(g => g.L), minR = gates.Min(g => g.R); int ans = maxL >= minR ? minR - maxL + 1 : 0; Console.WriteLine(ans); } #region Helpers static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray(); static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count) .Select(_ => int.Parse(Console.ReadLine())) .ToArray(); static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count) .Select(_ => long.Parse(Console.ReadLine())) .ToArray(); static string ReadString() => Console.ReadLine(); static int ReadInt() => int.Parse(Console.ReadLine()); static long ReadLong() => long.Parse(Console.ReadLine()); static void ReadInt(out int first) { var array = ReadIntArray(); first = array[0]; } static void ReadInt(out int first, out int second) { var array = ReadIntArray(); first = array[0]; second = array[1]; } static void ReadInt(out int first, out int second, out int third) { var array = ReadIntArray(); first = array[0]; second = array[1]; third = array[2]; } static void ReadInt(out int first, out int second, out int third, out int fourth) { var array = ReadIntArray(); first = array[0]; second = array[1]; third = array[2]; fourth = array[3]; } static void ReadLong(out long first) { var array = ReadLongArray(); first = array[0]; } static void ReadLong(out long first, out long second) { var array = ReadLongArray(); first = array[0]; second = array[1]; } static void ReadLong(out long first, out long second, out long third) { var array = ReadLongArray(); first = array[0]; second = array[1]; third = array[2]; } static void ReadLong(out long first, out long second, out long third, out long fourth) { var array = ReadLongArray(); first = array[0]; second = array[1]; third = array[2]; fourth = array[3]; } #endregion } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; namespace CSharp { static class Program { static void Main(string[] args) { int n, m; ReadInt(out n, out m); var gates = Enumerable.Repeat(0, m) .Select(_ => { int l, r; ReadInt(out l, out r); return new { L = l, R = r }; }) .ToArray(); int maxL = gates.Max(g => g.L), minR = gates.Min(g => g.R); int ans = minR >= maxL ? minR - maxL + 1 : 0; Console.WriteLine(ans); } #region Helpers static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray(); static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count) .Select(_ => int.Parse(Console.ReadLine())) .ToArray(); static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count) .Select(_ => long.Parse(Console.ReadLine())) .ToArray(); static string ReadString() => Console.ReadLine(); static int ReadInt() => int.Parse(Console.ReadLine()); static long ReadLong() => long.Parse(Console.ReadLine()); static void ReadInt(out int first) { var array = ReadIntArray(); first = array[0]; } static void ReadInt(out int first, out int second) { var array = ReadIntArray(); first = array[0]; second = array[1]; } static void ReadInt(out int first, out int second, out int third) { var array = ReadIntArray(); first = array[0]; second = array[1]; third = array[2]; } static void ReadInt(out int first, out int second, out int third, out int fourth) { var array = ReadIntArray(); first = array[0]; second = array[1]; third = array[2]; fourth = array[3]; } static void ReadLong(out long first) { var array = ReadLongArray(); first = array[0]; } static void ReadLong(out long first, out long second) { var array = ReadLongArray(); first = array[0]; second = array[1]; } static void ReadLong(out long first, out long second, out long third) { var array = ReadLongArray(); first = array[0]; second = array[1]; third = array[2]; } static void ReadLong(out long first, out long second, out long third, out long fourth) { var array = ReadLongArray(); first = array[0]; second = array[1]; third = array[2]; fourth = array[3]; } #endregion } }
[["-", 0, 200, 0, 212, 0, 41, 15, 16, 31, 22], ["-", 0, 200, 0, 212, 0, 41, 15, 16, 17, 20], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 20], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 12, 22]]
8
675
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace C_Prison { class Program { static void Main(string[] args) { string[] str1 = Console.ReadLine().Split(' '); int N = int.Parse(str1[0]); int M = int.Parse(str1[1]); int[] L = new int[M]; int[] R = new int[M]; for (int i = 0; i < M; i++) { string[] str2 = Console.ReadLine().Split(' '); L[i] = int.Parse(str2[0]); R[i] = int.Parse(str2[1]); } int min = 0; int max = N - 1; for (int i = 0; i < M; i++) { if (min < L[i]) { min = L[i]; } if (R[i] < max) { max = R[i]; } } if (max < min) { Console.Write("0"); } else { Console.Write(max - min + 1); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace C_Prison { class Program { static void Main(string[] args) { string[] str1 = Console.ReadLine().Split(' '); int N = int.Parse(str1[0]); int M = int.Parse(str1[1]); int[] L = new int[M]; int[] R = new int[M]; for (int i = 0; i < M; i++) { string[] str2 = Console.ReadLine().Split(' '); L[i] = int.Parse(str2[0]); R[i] = int.Parse(str2[1]); } int min = 1; int max = N; for (int i = 0; i < M; i++) { if (min < L[i]) { min = L[i]; } if (R[i] < max) { max = R[i]; } } if (max < min) { Console.Write("0"); } else { Console.Write(max - min + 1); } } } }
[["-", 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]]
8
271
4
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 { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; var M = cin.ReadInt; var Lmax = 0; var Rmin = N; for (var i = 0; i < M; i++) { var L = cin.ReadInt; var R = cin.ReadInt; if (L > Lmax) Lmax = L; if (R < Rmin) Rmin = R; } WriteLine(Rmin <= Lmax ? Rmin - Lmax + 1 : 0); } } 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 AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; var M = cin.ReadInt; var Lmax = 0; var Rmin = N; for (var i = 0; i < M; i++) { var L = cin.ReadInt; var R = cin.ReadInt; if (L > Lmax) Lmax = L; if (R < Rmin) Rmin = R; } WriteLine(Lmax <= Rmin ? Rmin - Lmax + 1 : 0); } } 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; } } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 19], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 19], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 22]]
8
513
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; Func cin2; void calc() { cin = new Scanner(); cin2 = new Func(); int[] NM = cin.ArrayInt(2, 0); int ans = 0; int lmax = 0; int rmin = 99999; for (int i = 0; i < NM[1]; i++) { int[] lr = cin.ArrayInt(2, 0); if (lr[0] > lmax) lmax = lr[0]; if (lr[1] < rmin) rmin = lr[1]; } ans = rmin - lmax + 1; if (ans < 0) ans = 0; Console.WriteLine(ans); } } 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 Answer { public static void Int2DArrayAns(int[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } // Answer.IntArrayAns(x); public static void Char2DArrayAns(char[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } } class Func { public long GCDLong(long a, long b) { while (a != 0) { long t = a; a = b % a; b = t; } return b; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; Func cin2; void calc() { cin = new Scanner(); cin2 = new Func(); int[] NM = cin.ArrayInt(2, 0); int ans = 0; int lmax = 0; int rmin = 9999999; for (int i = 0; i < NM[1]; i++) { int[] lr = cin.ArrayInt(2, 0); if (lr[0] > lmax) lmax = lr[0]; if (lr[1] < rmin) rmin = lr[1]; } ans = rmin - lmax + 1; if (ans < 0) ans = 0; Console.WriteLine(ans); } } 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 Answer { public static void Int2DArrayAns(int[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } // Answer.IntArrayAns(x); public static void Char2DArrayAns(char[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } } class Func { public long GCDLong(long a, long b) { while (a != 0) { long t = a; a = b % a; b = t; } return b; } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
805
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class27 { static void Main() { var NM = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = NM[0], M = NM[1]; var A = Console.ReadLine().Split().Select(long.Parse).ToArray(); var B = new long[M]; var C = new long[M]; for (int i = 0; i < M; i++) { var r = Console.ReadLine().Split().Select(long.Parse).ToArray(); B[i] = r[0]; C[i] = r[1]; } Array.Sort(C, B); Array.Sort(A); bool frag = false; for (int i = 0, k = M - 1; i < N && k >= 0; k--) { for (int j = 0; j < B[k]; j++, i++) { if (A[i] < C[k]) { A[i] = C[k]; } else { frag = true; break; } } if (frag) break; } Console.WriteLine(A.Sum()); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class27 { static void Main() { var NM = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = NM[0], M = NM[1]; var A = Console.ReadLine().Split().Select(long.Parse).ToArray(); var B = new long[M]; var C = new long[M]; for (int i = 0; i < M; i++) { var r = Console.ReadLine().Split().Select(long.Parse).ToArray(); B[i] = r[0]; C[i] = r[1]; } Array.Sort(C, B); Array.Sort(A); bool frag = false; for (int i = 0, k = M - 1; i < N && k >= 0; k--) { for (int j = 0; j < B[k] && i < N; j++, i++) { if (A[i] < C[k]) { A[i] = C[k]; } else { frag = true; break; } } if (frag) break; } Console.WriteLine(A.Sum()); } } }
[["+", 0, 7, 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]]
8
302
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder2 { class Program { static void Main(string[] args) { var inputArray = retreiveLongArray(); var inputCount = 2; // 不正な入力は処理しない if (inputArray.Length != inputCount) { Console.WriteLine("invalid input"); return; } long N = inputArray[0]; long M = inputArray[1]; var aList = retreiveLongArray().OrderBy(x => x).ToList(); var inpDic = new Dictionary<long, long>(); //変更先:変えられる枚数 checked { for (int i = 0; i < M; i++) { var inp = retreiveLongArray(); if (inpDic.ContainsKey(inp[1])) { inpDic[inp[1]] += inp[0]; } else { inpDic.Add(inp[1], inp[0]); } } var koujunC = inpDic.OrderByDescending(x => x.Key).Select(x => x.Key).ToArray(); var koujunClength = koujunC.Length; var j = 0; var Cj = koujunC[j]; for (int i = 0; i < N; i++) { var a = aList[i]; if (a >= Cj) { break; } aList[i] = Cj; inpDic[Cj]--; //その数を変え終わったとき if (inpDic[Cj] == 0) { j++; if (j == koujunClength) { //すべてのカード変更権利を使い切ったとき break; } Cj = koujunC[j++]; } } //答えの出力 var ans = aList.Sum(); Console.WriteLine(ans); } } /// <summary> /// スペースで区切られた文字列配列の入力を受け取る /// </summary> /// <returns></returns> private static string[] retreiveStringArray() { var inputArray = Console.ReadLine().Split(' '); return inputArray; } /// <summary> /// スペースで区切られた整数配列の入力を受け取る /// </summary> /// <returns></returns> private static long[] retreiveLongArray() { var inputArray = Console.ReadLine().Split(' '); var longArray = inputArray.Select(s => long.Parse(s)); return longArray.ToArray(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder2 { class Program { static void Main(string[] args) { var inputArray = retreiveLongArray(); var inputCount = 2; // 不正な入力は処理しない if (inputArray.Length != inputCount) { Console.WriteLine("invalid input"); return; } long N = inputArray[0]; long M = inputArray[1]; var aList = retreiveLongArray().OrderBy(x => x).ToList(); var inpDic = new Dictionary<long, long>(); //変更先:変えられる枚数 checked { for (int i = 0; i < M; i++) { var inp = retreiveLongArray(); if (inpDic.ContainsKey(inp[1])) { inpDic[inp[1]] += inp[0]; } else { inpDic.Add(inp[1], inp[0]); } } var koujunC = inpDic.OrderByDescending(x => x.Key).Select(x => x.Key).ToArray(); var koujunClength = koujunC.Length; var j = 0; var Cj = koujunC[j]; for (int i = 0; i < N; i++) { var a = aList[i]; if (a >= Cj) { break; } aList[i] = Cj; inpDic[Cj]--; //その数を変え終わったとき if (inpDic[Cj] == 0) { j++; if (j == koujunClength) { //すべてのカード変更権利を使い切ったとき break; } Cj = koujunC[j]; } } //答えの出力 var ans = aList.Sum(); Console.WriteLine(ans); } } /// <summary> /// スペースで区切られた文字列配列の入力を受け取る /// </summary> /// <returns></returns> private static string[] retreiveStringArray() { var inputArray = Console.ReadLine().Split(' '); return inputArray; } /// <summary> /// スペースで区切られた整数配列の入力を受け取る /// </summary> /// <returns></returns> private static long[] retreiveLongArray() { var inputArray = Console.ReadLine().Split(' '); var longArray = inputArray.Select(s => long.Parse(s)); return longArray.ToArray(); } } }
[["-", 12, 204, 206, 207, 0, 28, 0, 223, 0, 29]]
8
431
1
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } static void Solve() { var N = sc.ReadInt(); var M = sc.ReadInt(); var A = sc.ReadIntArray(N); Array.Sort(A); var pq = new PriorityQueue<Tuple<int, int>>(N, false); foreach (var g in A.GroupBy(a => a)) { pq.Enqueue(Tuple.Create(g.Key, g.Count())); } for (int i = 0; i < M; i++) { var b = sc.ReadInt(); var c = sc.ReadInt(); var insertCount = 0; while (b > 0 && pq.Peek().Item1 < c) { var t = pq.Dequeue(); var prevValue = t.Item1; var prevCount = t.Item2; if (prevCount > b) { pq.Enqueue(Tuple.Create(prevValue, prevCount - b)); insertCount += b; break; } else { // すべて置き換える insertCount += prevCount; b -= prevCount; } } pq.Enqueue(Tuple.Create(c, insertCount)); } var ans = 0l; while (pq.Count > 0) { var t = pq.Dequeue(); ans += (long)t.Item1 * t.Item2; } Console.WriteLine(ans); } // Comparison<T> f = (x, y) => x.CompareTo(y); // Comparer<T>.Create(f) class PriorityQueue<T> { public readonly T[] Array; public readonly bool Greater; public int Count { get; private set; } = 0; private IComparer<T> Cmp; public PriorityQueue(int capacity, bool greater = true, IComparer<T> cmp = null) { this.Cmp = cmp; if (cmp == null) { this.Cmp = Comparer<T>.Default; } 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.Compare(this.Array[n], 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 = this.Cmp.Compare(a, 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; } } static Scanner sc = new Scanner(); } 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 double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } 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 double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } 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; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } static void Solve() { var N = sc.ReadInt(); var M = sc.ReadInt(); var A = sc.ReadIntArray(N); Array.Sort(A); var pq = new PriorityQueue<Tuple<int, int>>(N, false); foreach (var g in A.GroupBy(a => a)) { pq.Enqueue(Tuple.Create(g.Key, g.Count())); } for (int i = 0; i < M; i++) { var b = sc.ReadInt(); var c = sc.ReadInt(); var insertCount = 0; while (b > 0 && pq.Peek().Item1 < c) { var t = pq.Dequeue(); var prevValue = t.Item1; var prevCount = t.Item2; if (prevCount > b) { pq.Enqueue(Tuple.Create(prevValue, prevCount - b)); insertCount += b; break; } else { insertCount += prevCount; b -= prevCount; } } if (insertCount > 0) pq.Enqueue(Tuple.Create(c, insertCount)); } var ans = 0l; while (pq.Count > 0) { var t = pq.Dequeue(); ans += (long)t.Item1 * t.Item2; } Console.WriteLine(ans); } // Comparison<T> f = (x, y) => x.CompareTo(y); // Comparer<T>.Create(f) class PriorityQueue<T> { public readonly T[] Array; public readonly bool Greater; public int Count { get; private set; } = 0; private IComparer<T> Cmp; public PriorityQueue(int capacity, bool greater = true, IComparer<T> cmp = null) { this.Cmp = cmp; if (cmp == null) { this.Cmp = Comparer<T>.Default; } 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.Compare(this.Array[n], 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 = this.Cmp.Compare(a, 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; } } static Scanner sc = new Scanner(); } 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 double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } 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 double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } 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; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
[["+", 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]]
8
1,799
6