buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
| change_count
int64 0
100
|
|---|---|---|---|---|---|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication5 {
class Program {
static void Main(string[] args) {
string[] tmp = Console.ReadLine().Split(' ');
decimal N = decimal.Parse(tmp[0]);
decimal M = decimal.Parse(tmp[1]);
if (Math.Abs(N - M) >= 2) {
Console.WriteLine(0);
return;
}
decimal ansN = kaijou(N) % 1000000007;
decimal ansM = kaijou(M) % 1000000007;
decimal ans = (ansN * ansM * 2) % 1000000007;
Console.WriteLine(ans);
Console.Read();
}
static decimal kaijou(decimal n) {
decimal ret = 1;
do {
if (n != 1) {
ret *= n;
ret %= 1000000007;
} else {
break;
}
n--;
} while (true);
return ret;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication5 {
class Program {
static void Main(string[] args) {
string[] tmp = Console.ReadLine().Split(' ');
decimal N = decimal.Parse(tmp[0]);
decimal M = decimal.Parse(tmp[1]);
if (Math.Abs(N - M) >= 2) {
Console.WriteLine(0);
return;
}
decimal ansN = kaijou(N) % 1000000007;
decimal ansM = kaijou(M) % 1000000007;
decimal ans = 0;
if (N == M)
ans = (ansN * ansM * 2) % 1000000007;
else
ans = (ansN * ansM) % 1000000007;
Console.WriteLine(ans);
Console.Read();
}
static decimal kaijou(decimal n) {
decimal ret = 1;
do {
if (n != 1) {
ret *= n;
ret %= 1000000007;
} else {
break;
}
n--;
} while (true);
return ret;
}
}
}
|
[["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 17, 109], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 1, 0, 11, 31, 22], ["+", 0, 57, 75, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 48], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 12, 22]]
| 8
| 209
| 21
|
using System;
using System.Linq;
using System.Collections.Generic;
public class Program {
const long Mod = (long)(1e9 + 7);
public static void Main() {
var nm = Console.ReadLine()
.Split()
.Select(x => long.Parse(x))
.OrderBy(x => x)
.ToArray();
var d = nm[1] - nm[0];
if (d > 1) {
Console.WriteLine(0);
return;
}
var t = Frac(1, nm[0]);
t *= t * Frac(nm[0] + 1, d);
t *= 2 - d;
Console.WriteLine(t % Mod);
}
static long Frac(long x, long k) => k == 0 ? 1 : x * Frac(x + 1, k - 1) % Mod;
}
|
using System;
using System.Linq;
using System.Collections.Generic;
public class Program {
const long Mod = (long)(1e9 + 7);
public static void Main() {
var nm = Console.ReadLine()
.Split()
.Select(x => long.Parse(x))
.OrderBy(x => x)
.ToArray();
var d = nm[1] - nm[0];
if (d > 1) {
Console.WriteLine(0);
return;
}
var t = Frac(1, nm[0]);
t *= t * Frac(nm[0] + 1, d) % Mod;
t %= Mod;
t *= 2 - d;
t %= Mod;
Console.WriteLine(t);
}
static long Frac(long x, long k) => k == 0 ? 1 : x * Frac(x + 1, k - 1) % Mod;
}
|
[["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
| 8
| 183
| 12
|
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
public class Program {
public void Proc() {
int nodeCount = int.Parse(Reader.ReadLine());
this.TreeNodeList = new TreeNode[nodeCount];
for (int i = 0; i < nodeCount; i++) {
TreeNode t = new TreeNode(
i, Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray());
this.TreeNodeList[i] = t;
}
this.SortedX = TreeNodeList.OrderBy(a => a.X).ToArray();
this.SortedY = TreeNodeList.OrderBy(a => a.Y).ToArray();
List<Road> roadList = new List<Road>();
for (int i = 1; i < nodeCount; i++) {
roadList.Add(new Road(SortedX[i - 1], SortedX[i]));
roadList.Add(new Road(SortedY[i - 1], SortedY[i]));
}
roadList = roadList.OrderBy(a => a.Length).ToList();
int cnt = 1;
long ans = 0;
foreach (Road r in roadList) {
if (r.t1.Root.ID == r.t2.Root.ID) {
continue;
}
r.t1.Join(r.t2);
ans += r.Length;
cnt++;
if (cnt >= nodeCount) {
break;
}
}
Console.WriteLine(ans);
}
private class Road {
public TreeNode t1;
public TreeNode t2;
public long Length = 0;
public Road(TreeNode t1, TreeNode t2) {
this.t1 = t1;
this.t2 = t2;
this.Length = Math.Min(Math.Abs(t1.X - t2.X), Math.Abs(t1.Y - t2.Y));
}
}
private TreeNode[] TreeNodeList;
private TreeNode[] SortedX;
private TreeNode[] SortedY;
private class TreeNode {
private TreeNode _root = null;
public TreeNode Root {
get {
if (this._root != null) {
if (this._root.Parent == null) {
return this._root;
} else {
this._root = this._root.Parent.Root;
}
} else {
if (this.Parent == null) {
return this;
} else {
this._root = this.Parent.Root;
}
}
return this._root;
}
set { this._root = value; }
}
public long GetLen(TreeNode target) {
return Math.Min(Math.Abs(this.X - target.X), Math.Abs(this.Y - target.Y));
}
public TreeNode Parent;
public List<TreeNode> Items = new List<TreeNode>();
public int ID;
public int XIndex;
public int YIndex;
public long X;
public long Y;
public TreeNode(int id, long[] pos) {
this.ID = id;
this.X = pos[0];
this.Y = pos[1];
}
public void Join(TreeNode target) {
if (this.Root.ID == target.Root.ID) {
return;
} else if (this.Root.ID < target.Root.ID) {
if (target.Parent != null) {
target.UpsideDown();
}
this.Items.Add(target);
target.Parent = this;
target.Root = this.Root;
} else {
target.Join(this);
}
}
public void UpsideDown() {
TreeNode n = this.Parent;
this.Parent = null;
this.Root = null;
n.Items.Remove(this);
n.UpsideDown();
this.Items.Add(n);
n.Parent = this;
n.Root = this;
}
}
public class Reader {
private static StringReader sr;
public static bool IsDebug = false;
public static string ReadLine() {
if (IsDebug) {
if (sr == null) {
sr = new StringReader(InputText.Trim());
}
return sr.ReadLine();
} else {
return Console.ReadLine();
}
}
private static string InputText = @"
6
8 3
4 9
12 19
18 1
13 5
7 6
";
}
public static void Main(string[] args) {
#if DEBUG
Reader.IsDebug = true;
#endif
Program prg = new Program();
prg.Proc();
}
}
|
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
public class Program {
public void Proc() {
int nodeCount = int.Parse(Reader.ReadLine());
this.TreeNodeList = new TreeNode[nodeCount];
for (int i = 0; i < nodeCount; i++) {
TreeNode t = new TreeNode(
i, Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray());
this.TreeNodeList[i] = t;
}
this.SortedX = TreeNodeList.OrderBy(a => a.X).ToArray();
this.SortedY = TreeNodeList.OrderBy(a => a.Y).ToArray();
List<Road> roadList = new List<Road>();
for (int i = 1; i < nodeCount; i++) {
roadList.Add(new Road(SortedX[i - 1], SortedX[i]));
roadList.Add(new Road(SortedY[i - 1], SortedY[i]));
}
roadList = roadList.OrderBy(a => a.Length).ToList();
int cnt = 1;
long ans = 0;
foreach (Road r in roadList) {
if (r.t1.Root.ID == r.t2.Root.ID) {
continue;
}
r.t1.Join(r.t2);
ans += r.Length;
cnt++;
if (cnt >= nodeCount) {
break;
}
}
Console.WriteLine(ans);
}
private class Road {
public TreeNode t1;
public TreeNode t2;
public long Length = 0;
public Road(TreeNode t1, TreeNode t2) {
this.t1 = t1;
this.t2 = t2;
this.Length = Math.Min(Math.Abs(t1.X - t2.X), Math.Abs(t1.Y - t2.Y));
}
}
private TreeNode[] TreeNodeList;
private TreeNode[] SortedX;
private TreeNode[] SortedY;
private class TreeNode {
private TreeNode _root = null;
public TreeNode Root {
get {
if (this._root != null) {
if (this._root.Parent == null) {
return this._root;
} else {
this._root = this._root.Parent.Root;
}
} else {
if (this.Parent == null) {
return this;
} else {
this._root = this.Parent.Root;
}
}
return this._root;
}
set { this._root = value; }
}
public long GetLen(TreeNode target) {
return Math.Min(Math.Abs(this.X - target.X), Math.Abs(this.Y - target.Y));
}
public TreeNode Parent;
public List<TreeNode> Items = new List<TreeNode>();
public int ID;
public long X;
public long Y;
public TreeNode(int id, long[] pos) {
this.ID = id;
this.X = pos[0];
this.Y = pos[1];
}
public void Join(TreeNode target) {
if (this.Root.ID == target.Root.ID) {
return;
} else if (this.Root.ID < target.Root.ID) {
if (target.Parent != null) {
target.UpsideDown();
}
this.Items.Add(target);
target.Parent = this;
target.Root = this.Root;
} else {
target.Join(this);
}
}
public void UpsideDown() {
if (this.Parent == null) {
return;
}
TreeNode n = this.Parent;
this.Parent = null;
this.Root = null;
n.Items.Remove(this);
n.UpsideDown();
this.Items.Add(n);
n.Parent = this;
n.Root = this;
}
}
public class Reader {
private static StringReader sr;
public static bool IsDebug = false;
public static string ReadLine() {
if (IsDebug) {
if (sr == null) {
sr = new StringReader(InputText.Trim());
}
return sr.ReadLine();
} else {
return Console.ReadLine();
}
}
private static string InputText = @"
6
8 3
4 9
12 19
18 1
13 5
7 6
";
}
public static void Main(string[] args) {
#if DEBUG
Reader.IsDebug = true;
#endif
Program prg = new Program();
prg.Proc();
}
}
|
[["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 8, 201, 0, 124, 0, 198, 0, 200, 141, 22], ["-", 8, 201, 0, 235, 8, 201, 0, 124, 0, 35], ["-", 0, 235, 8, 201, 0, 124, 0, 251, 0, 259], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 24], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 25], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 45], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 0, 57, 15, 16, 31, 214, 205, 273, 0, 274], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 215], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 912
| 20
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtTest.ForYellow {
class ARC076_E {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush =
false };
SetOut(sw);
Method(args);
Out.Flush();
}
static void Method(string[] args) {
int[] rcn = ReadInts();
int r = rcn[0];
int c = rcn[1];
int n = rcn[2];
List<int[]> vals = new List<int[]>();
for (int i = 0; i < n; i++) {
int[] xy = ReadInts();
if ((xy[0] == 0 || xy[0] == c || xy[1] == 0 || xy[1] == r) &&
(xy[2] == 0 || xy[2] == c || xy[3] == 0 || xy[3] == r)) {
int left = 0;
if (xy[0] == 0) {
left = xy[1];
} else if (xy[1] == r) {
left = r + xy[0];
} else if (xy[0] == c) {
left = r * 2 + c - xy[1];
} else {
left = r * 2 + c * 2 - xy[0];
}
int right = 0;
if (xy[2] == 0) {
right = xy[3];
} else if (xy[3] == r) {
right = r + xy[2];
} else if (xy[2] == c) {
right = r * 2 + c - xy[3];
} else {
right = r * 2 + c * 2 - xy[2];
}
vals.Add(new int[2] { left, i });
vals.Add(new int[2] { right, i });
}
}
vals = vals.OrderBy(a => a[0]).ToList();
Stack<int> indexes = new Stack<int>();
for (int i = 0; i < vals.Count; i++) {
if (indexes.Count > 0 && indexes.Peek() == vals[i][1]) {
indexes.Pop();
} else {
indexes.Push(vals[i][1]);
}
}
WriteLine(indexes.Count == 0 ? "YES" : "NO");
}
private static string Read() { return ReadLine(); }
private static char[] ReadChars() {
return Array.ConvertAll(Read().Split(), a => a[0]);
}
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
namespace AtTest.ForYellow {
class ARC076_E {
static void Main(string[] args) {
var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush =
false };
SetOut(sw);
Method(args);
Out.Flush();
}
static void Method(string[] args) {
int[] rcn = ReadInts();
int r = rcn[0];
int c = rcn[1];
int n = rcn[2];
List<int[]> vals = new List<int[]>();
for (int i = 0; i < n; i++) {
int[] xy = ReadInts();
if ((xy[0] == 0 || xy[0] == r || xy[1] == 0 || xy[1] == c) &&
(xy[2] == 0 || xy[2] == r || xy[3] == 0 || xy[3] == c)) {
int left = 0;
if (xy[0] == 0) {
left = xy[1];
} else if (xy[1] == c) {
left = c + xy[0];
} else if (xy[0] == r) {
left = c * 2 + r - xy[1];
} else {
left = c * 2 + r * 2 - xy[0];
}
int right = 0;
if (xy[2] == 0) {
right = xy[3];
} else if (xy[3] == c) {
right = c + xy[2];
} else if (xy[2] == r) {
right = c * 2 + r - xy[3];
} else {
right = c * 2 + r * 2 - xy[2];
}
vals.Add(new int[2] { left, i });
vals.Add(new int[2] { right, i });
}
}
vals = vals.OrderBy(a => a[0]).ToList();
Stack<int> indexes = new Stack<int>();
for (int i = 0; i < vals.Count; i++) {
if (indexes.Count > 0 && indexes.Peek() == vals[i][1]) {
indexes.Pop();
} else {
indexes.Push(vals[i][1]);
}
}
WriteLine(indexes.Count == 0 ? "YES" : "NO");
}
private static string Read() { return ReadLine(); }
private static char[] ReadChars() {
return Array.ConvertAll(Read().Split(), a => a[0]);
}
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
[["-", 0, 16, 31, 16, 31, 16, 12, 16, 12, 22], ["+", 0, 16, 31, 16, 31, 16, 12, 16, 12, 22], ["-", 15, 16, 31, 23, 0, 16, 12, 16, 12, 22], ["+", 15, 16, 31, 23, 0, 16, 12, 16, 12, 22], ["-", 15, 16, 12, 23, 0, 16, 12, 16, 12, 22], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 12, 22], ["-", 64, 196, 0, 57, 75, 57, 15, 16, 12, 22], ["+", 64, 196, 0, 57, 75, 57, 15, 16, 12, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 0, 57, 75, 57, 75, 57, 15, 16, 12, 22], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 12, 22], ["-", 0, 11, 12, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 11, 12, 16, 31, 16, 31, 16, 31, 22], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["-", 0, 11, 12, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 11, 12, 16, 31, 16, 12, 16, 31, 22]]
| 8
| 741
| 36
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCorder {
public class Program {
static void Main(string[] args) {
var cin = new Scanner2();
int n = cin.Int();
var counts = new Dictionary<int, int>();
for (int i = 0; i < n; i++) {
int a = cin.Int();
if (counts.ContainsKey(a) == false) {
counts[a] = 1;
} else {
counts[a] += 1;
}
}
if (counts.Count > 2) {
Console.WriteLine("No");
return;
}
if (counts.Count == 2) {
var keys = counts.Keys.OrderBy(x => x).ToArray();
int key1 = keys[0];
int key2 = keys[1];
if (key2 - key1 != 1) {
Console.WriteLine("No");
return;
}
if (counts[key1] <= key1 && key2 <= counts[key2] / 2) {
Console.WriteLine("Yes");
return;
} else {
Console.WriteLine("No");
return;
}
} else {
int key = counts.Keys.First();
if (key <= counts[key] / 2 || key == counts[key] - 1) {
Console.WriteLine("Yes");
return;
} else {
Console.WriteLine("No");
return;
}
}
}
}
public class Scanner2 {
private readonly char[] delimiter_ = new char[] { ' ' };
private readonly string filePath_;
private string[] buf_;
private int index_;
Func<string> reader_;
public Scanner2(string file = "") {
if (string.IsNullOrWhiteSpace(file)) {
reader_ = Console.ReadLine;
} else {
filePath_ = file;
var fs = new StreamReader(file);
reader_ = fs.ReadLine;
}
buf_ = new string[0];
index_ = 0;
}
public string Next() {
if (index_ < buf_.Length) {
return buf_[index_++];
}
string st = reader_();
while (st == "") {
st = reader_();
}
buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
if (buf_.Length == 0) {
return Next();
}
index_ = 0;
return buf_[index_++];
}
public int Int() => int.Parse(Next());
public long Long() => long.Parse(Next());
public double Double() => double.Parse(Next());
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Int() + add;
}
return Array;
}
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = Long() + add;
}
return Array;
}
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = Double() + add;
}
return Array;
}
public void Save(string text) {
if (string.IsNullOrWhiteSpace(filePath_)) {
return;
}
File.WriteAllText(filePath_ + "_output.txt", text);
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCorder {
public class Program {
static void Main(string[] args) {
var cin = new Scanner2();
int n = cin.Int();
var counts = new Dictionary<int, int>();
for (int i = 0; i < n; i++) {
int a = cin.Int();
if (counts.ContainsKey(a) == false) {
counts[a] = 1;
} else {
counts[a] += 1;
}
}
if (counts.Count > 2) {
Console.WriteLine("No");
return;
}
if (counts.Count == 2) {
var keys = counts.Keys.OrderBy(x => x).ToArray();
int key1 = keys[0];
int key2 = keys[1];
if (key2 - key1 != 1) {
Console.WriteLine("No");
return;
}
if (counts[key1] <= key1 && (key2 - counts[key1]) <= counts[key2] / 2) {
Console.WriteLine("Yes");
return;
} else {
Console.WriteLine("No");
return;
}
} else {
int key = counts.Keys.First();
if (key <= counts[key] / 2 || key == counts[key] - 1) {
Console.WriteLine("Yes");
return;
} else {
Console.WriteLine("No");
return;
}
}
}
}
public class Scanner2 {
private readonly char[] delimiter_ = new char[] { ' ' };
private readonly string filePath_;
private string[] buf_;
private int index_;
Func<string> reader_;
public Scanner2(string file = "") {
if (string.IsNullOrWhiteSpace(file)) {
reader_ = Console.ReadLine;
} else {
filePath_ = file;
var fs = new StreamReader(file);
reader_ = fs.ReadLine;
}
buf_ = new string[0];
index_ = 0;
}
public string Next() {
if (index_ < buf_.Length) {
return buf_[index_++];
}
string st = reader_();
while (st == "") {
st = reader_();
}
buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
if (buf_.Length == 0) {
return Next();
}
index_ = 0;
return buf_[index_++];
}
public int Int() => int.Parse(Next());
public long Long() => long.Parse(Next());
public double Double() => double.Parse(Next());
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Int() + add;
}
return Array;
}
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = Long() + add;
}
return Array;
}
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = Double() + add;
}
return Array;
}
public void Save(string text) {
if (string.IsNullOrWhiteSpace(filePath_)) {
return;
}
File.WriteAllText(filePath_ + "_output.txt", text);
}
}
}
|
[["+", 0, 57, 15, 16, 12, 16, 31, 23, 0, 24], ["+", 15, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 12, 16, 31, 23, 0, 16, 12, 204, 205, 22], ["+", 31, 23, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 31, 23, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 12, 16, 31, 23, 0, 25]]
| 8
| 775
| 7
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
class Program {
static void Main() { new Magatro().Solve(); }
}
class Magatro {
private int N;
private int[] a;
private void Scan() {
N = int.Parse(Console.ReadLine());
a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public void Solve() {
Scan();
int min = a.Min();
int max = a.Max();
if (max - min > 1) {
Console.WriteLine("No");
return;
}
if (max - min == 0) {
if (a[0] == N - 1 || a[0] * 2 <= N) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
return;
} else if (max - min == 1) {
if (a.Count(i => i == max) == 1 && max == N - 1) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
return;
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
class Program {
static void Main() { new Magatro().Solve(); }
}
class Magatro {
private int N;
private int[] a;
private void Scan() {
N = int.Parse(Console.ReadLine());
a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
public void Solve() {
Scan();
int min = a.Min();
int max = a.Max();
if (max - min > 1) {
Console.WriteLine("No");
return;
}
if (max - min == 0) {
if (a[0] == N - 1 || a[0] * 2 <= N) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
return;
} else if (max - min == 1) {
int x = a.Count(i => i == min);
int y = N - x;
if (x < max && 2 * (max - x) <= y) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
return;
}
}
}
|
[["-", 0, 57, 75, 57, 64, 196, 0, 57, 0, 121], ["-", 0, 57, 75, 57, 64, 196, 0, 57, 0, 24], ["+", 75, 57, 64, 196, 0, 197, 0, 198, 39, 199], ["+", 64, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 22], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 57, 75, 57, 64, 196, 0, 197, 0, 35], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 0, 57, 75, 57, 64, 196, 0, 57, 0, 121], ["+", 0, 57, 75, 57, 64, 196, 0, 57, 0, 24], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 31, 203], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 48], ["+", 15, 16, 12, 16, 31, 16, 12, 23, 0, 24], ["-", 64, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 31, 22], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 12, 203], ["+", 12, 16, 31, 16, 12, 23, 0, 16, 12, 22], ["+", 15, 16, 12, 16, 31, 16, 12, 23, 0, 25], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
| 8
| 281
| 32
|
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using Debug = System.Diagnostics.Debug;
class P {
static void Main() {
int n = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(int.Parse).ToList();
var grouped = a.GroupBy(x => x).OrderBy(x => x.Key).ToArray();
if (grouped.Length >= 3)
goto end;
if (grouped.Length == 2) {
if (grouped[1].Key - grouped[0].Key != 1)
goto end;
int single = grouped[0].Count();
int many = grouped[1].Count();
int max = many / 2 + single;
int min = 1 + single;
if (grouped[1].Key < min || max < grouped[1].Key)
goto end;
}
if (grouped.Length == 1) {
int count = grouped[0].Count();
int max = count / 2;
int min = 1;
if (grouped[0].Key != count - 1 && (count < min || max < count))
goto end;
}
Console.WriteLine("Yes");
return;
end:
Console.WriteLine("No");
}
}
|
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using Debug = System.Diagnostics.Debug;
class P {
static void Main() {
int n = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(int.Parse).ToList();
var grouped = a.GroupBy(x => x).OrderBy(x => x.Key).ToArray();
if (grouped.Length >= 3)
goto end;
if (grouped.Length == 2) {
if (grouped[1].Key - grouped[0].Key != 1)
goto end;
int single = grouped[0].Count();
int many = grouped[1].Count();
int max = many / 2 + single;
int min = 1 + single;
if (grouped[1].Key < min || max < grouped[1].Key)
goto end;
}
if (grouped.Length == 1) {
int count = grouped[0].Count();
int max = count / 2;
int min = 1;
if (grouped[0].Key != count - 1 &&
(grouped[0].Key < min || max < grouped[0].Key))
goto end;
}
Console.WriteLine("Yes");
return;
end:
Console.WriteLine("No");
}
}
|
[["-", 15, 16, 12, 23, 0, 16, 31, 16, 31, 22], ["+", 0, 16, 31, 16, 31, 214, 205, 204, 205, 22], ["+", 31, 16, 31, 214, 205, 204, 206, 207, 0, 70], ["+", 31, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 31, 214, 205, 204, 206, 207, 0, 73], ["+", 12, 23, 0, 16, 31, 16, 31, 214, 0, 131], ["+", 12, 23, 0, 16, 31, 16, 31, 214, 141, 22], ["-", 15, 16, 12, 23, 0, 16, 12, 16, 12, 22], ["+", 0, 16, 12, 16, 12, 214, 205, 204, 205, 22], ["+", 12, 16, 12, 214, 205, 204, 206, 207, 0, 70], ["+", 12, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 16, 12, 214, 205, 204, 206, 207, 0, 73], ["+", 12, 23, 0, 16, 12, 16, 12, 214, 0, 131], ["+", 12, 23, 0, 16, 12, 16, 12, 214, 141, 22]]
| 8
| 325
| 14
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace AtCoder.AGC016 {
class ColorfulHat {
public static void Main() {
var yes = "Yes";
var no = "No";
var n = int.Parse(ReadLine());
var testinomial = ReadLine().Trim().Split(' ').Select(_ => int.Parse(_));
var suspect = testinomial.Distinct().OrderBy(_ => _).ToArray();
if (suspect.Length > 2)
WriteLine(no);
else {
var smaller = new Color(suspect[0], n);
var bigger = new Color(suspect[0] + 1, n);
foreach (var t in testinomial) {
if (smaller == t) {
smaller.Many++;
bigger.Single++;
} else {
bigger.Many++;
}
}
if (smaller.IsNotParadoxical() || bigger.IsNotParadoxical())
WriteLine(yes);
else
WriteLine(no);
}
}
struct Color {
int ColorNum;
int Num;
public int Single, Many;
public Color(int color, int n) {
ColorNum = color;
Num = n;
Single = Many = 0;
}
public static implicit operator int(Color c) { return c.ColorNum; }
public bool IsNotParadoxical() {
return Num == Single + Many &&
ColorNum >= Single + ((Many == 0) ? 0 : 1) &&
ColorNum <= Single + Many / 2;
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace AtCoder.AGC016 {
class ColorfulHat {
public static void Main() {
var yes = "Yes";
var no = "No";
var n = int.Parse(ReadLine());
var testinomial = ReadLine().Trim().Split(' ').Select(_ => int.Parse(_));
var suspect = testinomial.Distinct().OrderBy(_ => _).ToArray();
if (suspect.Length > 2)
WriteLine(no);
else if (suspect.Length == 2 && ((suspect[0] + 1) != suspect[1]))
WriteLine(no);
else {
var smaller = new Color(suspect[0], n);
var bigger = new Color(suspect[0] + 1, n);
foreach (var t in testinomial) {
if (smaller == t) {
smaller.Many++;
bigger.Single++;
} else {
bigger.Many++;
}
}
if (smaller.IsNotParadoxical() || bigger.IsNotParadoxical())
WriteLine(yes);
else
WriteLine(no);
}
}
struct Color {
int ColorNum;
int Num;
public int Single, Many;
public Color(int color, int n) {
ColorNum = color;
Num = n;
Single = Many = 0;
}
public static implicit operator int(Color c) { return c.ColorNum; }
public bool IsNotParadoxical() {
return Num == Single + Many &&
ColorNum >= Single + ((Many == 0) ? 0 : 1) &&
ColorNum <= Single + Many / 2;
}
}
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 75, 57, 15, 16, 31, 16, 31, 214, 205, 22], ["+", 75, 57, 15, 16, 31, 16, 31, 214, 0, 131], ["+", 75, 57, 15, 16, 31, 16, 31, 214, 141, 22], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 17, 60], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 98], ["+", 0, 57, 75, 57, 15, 16, 12, 23, 0, 24], ["+", 15, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 23, 0, 16, 31, 204, 205, 22], ["+", 31, 23, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 12, 23, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 12, 23, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 15, 16, 12, 23, 0, 16, 31, 23, 0, 25], ["+", 75, 57, 15, 16, 12, 23, 0, 16, 17, 79], ["+", 15, 16, 12, 23, 0, 16, 12, 204, 205, 22], ["+", 12, 23, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 23, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 57, 75, 57, 15, 16, 12, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 0, 57, 75, 57, 64, 1, 0, 213, 63, 22], ["+", 75, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 75, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 64, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95]]
| 8
| 328
| 30
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Codeforces {
internal class Template {
private void Solve() {
var n = cin.NextInt();
var a = new int[n];
for (var i = 0; i < n; i++) {
a[i] = cin.NextInt();
}
var groups = a.GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count());
if (groups.Count > 2) {
Console.WriteLine("No");
} else if (groups.Count == 1) {
var key = groups.Single().Key;
if (n >= key * 2 || key + 1 == n) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
} else {
var keys = groups.Select(x => x.Key).OrderBy(x => x).ToList();
if (keys[1] - keys[0] > 1) {
Console.WriteLine("No");
} else {
if (keys[1] >= n) {
Console.WriteLine("No");
} else if (groups[keys[0]] > keys[0]) {
Console.WriteLine("No");
} else if (groups[keys[1]] < 2 * (keys[0] - 1)) {
Console.WriteLine("No");
} else {
Console.WriteLine("Yes");
}
}
}
}
private static readonly Scanner cin = new Scanner();
private static void Main() {
new Template().Solve();
Console.ReadLine();
}
}
internal class Scanner {
private string[] s = new string[0];
private int i;
private readonly char[] cs = { ' ' };
public string NextString() {
if (i < s.Length)
return s[i++];
var line = Console.ReadLine() ?? string.Empty;
s = line.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 1;
return s.First();
}
public double NextDouble() { return double.Parse(NextString()); }
public int NextInt() { return int.Parse(NextString()); }
public long NextLong() { return long.Parse(NextString()); }
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Codeforces {
internal class Template {
private void Solve() {
var n = cin.NextInt();
var a = new int[n];
for (var i = 0; i < n; i++) {
a[i] = cin.NextInt();
}
var groups = a.GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count());
if (groups.Count > 2) {
Console.WriteLine("No");
} else if (groups.Count == 1) {
var key = groups.Single().Key;
if (n >= key * 2 || key + 1 == n) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
} else {
var keys = groups.Select(x => x.Key).OrderBy(x => x).ToList();
if (keys[1] - keys[0] > 1) {
Console.WriteLine("No");
} else {
if (keys[1] >= n) {
Console.WriteLine("No");
} else if (groups[keys[0]] > keys[0]) {
Console.WriteLine("No");
} else if (groups[keys[1]] < 2 * (keys[0] + 1 - groups[keys[0]])) {
Console.WriteLine("No");
} else {
Console.WriteLine("Yes");
}
}
}
}
private static readonly Scanner cin = new Scanner();
private static void Main() {
new Template().Solve();
Console.ReadLine();
}
}
internal class Scanner {
private string[] s = new string[0];
private int i;
private readonly char[] cs = { ' ' };
public string NextString() {
if (i < s.Length)
return s[i++];
var line = Console.ReadLine() ?? string.Empty;
s = line.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 1;
return s.First();
}
public double NextDouble() { return double.Parse(NextString()); }
public int NextInt() { return int.Parse(NextString()); }
public long NextLong() { return long.Parse(NextString()); }
}
}
|
[["-", 15, 16, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 12, 16, 12, 23, 0, 16, 31, 16, 17, 72], ["+", 15, 16, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 12, 16, 12, 23, 0, 16, 12, 204, 205, 22], ["+", 12, 23, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 12, 23, 0, 16, 12, 204, 206, 207, 0, 73]]
| 8
| 519
| 10
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using System.Threading.Tasks;
class Myon {
public Myon() {}
public static int Main() {
new Myon().calc();
return 0;
}
Scanner cin;
void calc() {
cin = new Scanner();
int N = cin.nextInt();
int[] A = cin.ArrayInt(N);
int[] B = cin.ArrayInt(N);
int[] a = new int[N + 1];
int[] b = new int[N + 1];
int xa = 0, xb = 0;
for (int i = 0; i < N; i++) {
xa ^= A[i];
xb ^= B[i];
}
a[N] = xa;
b[N] = xb;
List<int> la = new List<int>(A);
List<int> lb = new List<int>(B);
la.Add(xa);
lb.Add(xb);
la.Sort();
lb.Sort();
for (int i = 0; i < la.Count; i++) {
if (la[i] != lb[i]) {
Console.WriteLine("-1");
return;
}
}
int nokori = 0;
bool[] ok = new bool[N];
Dictionary<int, List<int>> need = new Dictionary<int, List<int>>();
for (int i = 0; i < N; i++) {
if (A[i] == B[i]) {
ok[i] = true;
continue;
}
if (!need.ContainsKey(B[i]))
need[B[i]] = new List<int>();
need[B[i]].Add(i);
nokori++;
}
if (nokori == 0) {
Console.WriteLine(0);
return;
}
Dictionary<int, int> dic = new Dictionary<int, int>();
for (int i = 0; i < N; i++) {
if (ok[i])
continue;
if (!dic.ContainsKey(A[i]))
dic[A[i]] = dic.Count;
if (!dic.ContainsKey(B[i]))
dic[B[i]] = dic.Count;
}
init(dic.Count);
for (int i = 0; i < N; i++) {
if (ok[i])
continue;
connect(dic[A[i]], dic[B[i]]);
}
int rootCnt = 0;
for (int i = 0; i < dic.Count; i++) {
if (root(i) == i)
rootCnt++;
}
int ans = nokori + rootCnt;
if (xa != xb)
ans--;
Console.WriteLine(ans);
// 1 2 3 4 5 X
// 1 3 2 5 4 X -> 3 + 3 = 6
// 1 3 2 5 X 4 -> 3 + 2 = 5
}
int[] uni;
void init(int N) {
uni = new int[N];
for (int i = 0; i < N; i++) {
uni[i] = -1;
}
}
int root(int a) {
if (uni[a] < 0)
return a;
else
return uni[a] = root(uni[a]);
}
bool connect(int a, int b) {
a = root(a);
b = root(b);
if (a == b)
return false;
if (uni[a] > uni[b])
swap(ref a, ref b);
uni[a] += uni[b];
uni[b] = a;
return true;
}
void swap<T>(ref T a, ref T b) {
T c = a;
a = b;
b = c;
}
}
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;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using System.Threading.Tasks;
class Myon {
public Myon() {}
public static int Main() {
new Myon().calc();
return 0;
}
Scanner cin;
void calc() {
cin = new Scanner();
int N = cin.nextInt();
int[] A = cin.ArrayInt(N);
int[] B = cin.ArrayInt(N);
int[] a = new int[N + 1];
int[] b = new int[N + 1];
int xa = 0, xb = 0;
for (int i = 0; i < N; i++) {
xa ^= A[i];
xb ^= B[i];
}
a[N] = xa;
b[N] = xb;
List<int> la = new List<int>(A);
List<int> lb = new List<int>(B);
la.Add(xa);
lb.Add(xb);
la.Sort();
lb.Sort();
for (int i = 0; i < la.Count; i++) {
if (la[i] != lb[i]) {
Console.WriteLine("-1");
return;
}
}
int nokori = 0;
bool[] ok = new bool[N];
Dictionary<int, List<int>> need = new Dictionary<int, List<int>>();
for (int i = 0; i < N; i++) {
if (A[i] == B[i]) {
ok[i] = true;
continue;
}
if (!need.ContainsKey(B[i]))
need[B[i]] = new List<int>();
need[B[i]].Add(i);
nokori++;
}
if (nokori == 0) {
Console.WriteLine(0);
return;
}
Dictionary<int, int> dic = new Dictionary<int, int>();
for (int i = 0; i < N; i++) {
if (ok[i])
continue;
if (!dic.ContainsKey(A[i]))
dic[A[i]] = dic.Count;
if (!dic.ContainsKey(B[i]))
dic[B[i]] = dic.Count;
}
init(dic.Count);
for (int i = 0; i < N; i++) {
if (ok[i])
continue;
connect(dic[A[i]], dic[B[i]]);
}
int rootCnt = 0;
for (int i = 0; i < dic.Count; i++) {
if (root(i) == i)
rootCnt++;
}
int ans = nokori + rootCnt;
if (xa != xb || (need.ContainsKey(xa) && need[xa].Count >= 1))
ans--;
Console.WriteLine(ans);
// 0 1 0
// 1 0 0
// 0 0 0 1 2 3 0
// 0 0 0 0 2 3 1
// 1 0 0 0 2 3 0
// 1 0 0 0 0 3 2
// 1 2 0 0 0 3 0
// 1 2 0 0 0 0 3
// 1 2 3 0 0 0 0
// 1 2 3 0 0 0 0
// 0 0 1 2 3 0
// 0 0 0 2 3 1
// 1 0 0 2 3 0
// 1 0 0 0 3 2
// 1 2 0 0 3 0
// 1 2 0 0 0 3
// 1 2 0 0 0 3
// 0 0 1 2 3 0
// 0 0 1 2 0 3
// 0 0 3 2 0 1
// 1 0 3 2 0 0
// 1 0 3 0 0 2
// 1 2 3 0 0 0
// 1 2 3 0 0 0
}
int[] uni;
void init(int N) {
uni = new int[N];
for (int i = 0; i < N; i++) {
uni[i] = -1;
}
}
int root(int a) {
if (uni[a] < 0)
return a;
else
return uni[a] = root(uni[a]);
}
bool connect(int a, int b) {
a = root(a);
b = root(b);
if (a == b)
return false;
if (uni[a] > uni[b])
swap(ref a, ref b);
uni[a] += uni[b];
uni[b] = a;
return true;
}
void swap<T>(ref T a, ref T b) {
T c = a;
a = b;
b = c;
}
}
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, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 12, 23, 0, 16, 31, 213, 63, 214, 205, 22], ["+", 12, 23, 0, 16, 31, 213, 63, 214, 0, 131], ["+", 12, 23, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 12, 23, 0, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["+", 12, 23, 0, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 98], ["+", 0, 16, 12, 16, 31, 214, 205, 204, 205, 22], ["+", 12, 16, 31, 214, 205, 204, 206, 207, 0, 70], ["+", 31, 214, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 12, 16, 31, 214, 205, 204, 206, 207, 0, 73], ["+", 12, 23, 0, 16, 12, 16, 31, 214, 0, 131], ["+", 12, 23, 0, 16, 12, 16, 31, 214, 141, 22], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 17, 20], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25]]
| 8
| 1,184
| 18
|
using System;
namespace ChokudaiScanner {
class MainClass {
static void Main() {
Scanner cin = new Scanner();
string r = cin.Next();
string g = cin.Next();
string b = cin.Next();
r += g + b;
int sum = int.Parse(r);
if (sum % 4 == 0) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
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 string[] ArrayNext(int N) {
string[] Array = new string[N];
for (int i = 0; i < N; i++) {
Array[i] = Next();
}
return Array;
}
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;
namespace ChokudaiScanner {
class MainClass {
static void Main() {
Scanner cin = new Scanner();
string r = cin.Next();
string g = cin.Next();
string b = cin.Next();
int sum = int.Parse(r + g + b);
if (sum % 4 == 0) {
Console.WriteLine("YES");
} else {
Console.WriteLine("NO");
}
}
}
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 string[] ArrayNext(int N) {
string[] Array = new string[N];
for (int i = 0; i < N; i++) {
Array[i] = Next();
}
return Array;
}
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, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 500
| 14
|
using System;
class Problem {
public static void Main() {
var s = Console.ReadLine();
if (int.Parse(string.Join(" ", s)) % 4 == 0)
Console.WriteLine("YES");
else
Console.WriteLine("NO");
}
}
|
using System;
public class Problem_A {
public static void Main() {
var s = Console.ReadLine();
if (int.Parse(s.Replace(" ", "")) % 4 == 0)
Console.WriteLine("YES");
else
Console.WriteLine("NO");
}
}
|
[["+", 36, 36, 0, 208, 0, 235, 0, 251, 0, 259], ["-", 36, 36, 36, 36, 0, 208, 0, 235, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 235, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62]]
| 8
| 65
| 10
|
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
namespace AtCoder {
public class Program {
public static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
var r = cin.Read;
var g = cin.Read;
var b = cin.Read;
if (int.Parse(r + g + b) % 4 == 0) {
Console.WriteLine("Even");
} else {
Console.WriteLine("Odd");
}
}
}
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;
namespace AtCoder {
public class Program {
public static void Main(string[] args) {
new Program().Solve(new ConsoleInput(Console.In, ' '));
}
public void Solve(ConsoleInput cin) {
var r = cin.Read;
var g = cin.Read;
var b = cin.Read;
Console.WriteLine(int.Parse(r + g + b) % 4 == 0 ? "YES" : "NO");
}
}
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, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 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, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 473
| 26
|
using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] input = ReadLine().Split();
int h = int.Parse(input[0]);
int w = int.Parse(input[1]);
List<List<string>> a = new List<List<string>>();
List<string> slis = new List<string>();
string s = "";
for (int i = 0; i < w + 2; i++) {
s += "#";
}
a.Add(s.ToList().ConvertAll(x => x.ToString()));
for (int i = 0; i < h; i++) {
slis.Clear();
slis.Add("#");
slis.AddRange(ReadLine().ToList().ConvertAll(x => x.ToString()));
slis.Add("#");
a.Add(slis);
}
a.Add(s.ToList().ConvertAll(x => x.ToString()));
foreach (var i in a) {
WriteLine(string.Join("", i));
}
}
}
|
using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
string[] input = ReadLine().Split();
int h = int.Parse(input[0]);
int w = int.Parse(input[1]);
List<List<string>> a = new List<List<string>>();
List<string> slis = new List<string>();
string s = "";
for (int i = 0; i < w + 2; i++) {
s += "#";
}
a.Add(s.ToList().ConvertAll(x => x.ToString()));
for (int i = 0; i < h; i++) {
slis.Clear();
slis.Add("#");
slis.AddRange(ReadLine().ToList().ConvertAll(x => x.ToString()));
slis.Add("#");
a.Add(string.Join("", slis).ToList().ConvertAll(x => x.ToString()));
}
a.Add(s.ToList().ConvertAll(x => x.ToString()));
foreach (var i in a) {
WriteLine(string.Join("", i));
}
}
}
|
[["+", 205, 213, 63, 214, 205, 213, 63, 214, 205, 199], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 205, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 21], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 22], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 218, 8, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 8, 213, 3, 4, 0, 25], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
| 8
| 276
| 23
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.Globalization;
namespace test {
class Program {
static void Main(string[] args) {
int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
var data = new List<string>();
for (int i = 0; i < a[0]; i++) {
data.Add(Console.ReadLine());
}
Console.Write("*");
for (int i = 0; i < a[1]; i++) {
Console.Write("*");
}
Console.Write("*\n");
for (int i = 0; i < a[0]; i++) {
Console.WriteLine($"*{data[i]}*");
}
Console.Write("*");
for (int i = 0; i < a[1]; i++) {
Console.Write("*");
}
Console.Write("*\n");
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.Globalization;
namespace test {
class Program {
static void Main(string[] args) {
int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
var data = new List<string>();
for (int i = 0; i < a[0]; i++) {
data.Add(Console.ReadLine());
}
Console.Write("#");
for (int i = 0; i < a[1]; i++) {
Console.Write("#");
}
Console.Write("#\n");
for (int i = 0; i < a[0]; i++) {
Console.WriteLine($"#{data[i]}#");
}
Console.Write("#");
for (int i = 0; i < a[1]; i++) {
Console.Write("#");
}
Console.Write("#\n");
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296], ["+", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296]]
| 8
| 254
| 16
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
class Myon {
public Myon() {}
public static int Main() {
new Myon().calc();
return 0;
}
Scanner cin;
void calc() {
cin = new Scanner();
int H = cin.nextInt();
int W = cin.nextInt();
Console.WriteLine(new string('#', W + 2));
Console.WriteLine("#" + cin.next() + "#");
Console.WriteLine(new string('#', W + 2));
}
}
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;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
class Myon {
public Myon() {}
public static int Main() {
new Myon().calc();
return 0;
}
Scanner cin;
void calc() {
cin = new Scanner();
int H = cin.nextInt();
int W = cin.nextInt();
Console.WriteLine(new string('#', W + 2));
for (int i = 0; i < H; i++) {
Console.WriteLine("#" + cin.next() + "#");
}
Console.WriteLine(new string('#', W + 2));
}
}
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;
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
| 8
| 507
| 16
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Console_Cs_Test {
class Program {
public static void Main(string[] args) {
string[] line1 = Console.ReadLine().Trim().Split(' ');
int H = int.Parse(line1[0]);
int W = int.Parse(line1[1]);
List<string> list = new List<string>();
for (int i = 0; i < H; ++i) {
list.Add(Console.ReadLine().Trim());
}
// 出力
string 枠 = "*";
string 外行 = string.Empty;
for (int i = 0; i < W + 2; ++i) {
外行 += 枠;
}
List<string> resultList = new List<string>();
resultList.Add(外行);
foreach (var item in list) {
resultList.Add($"{枠}{item}{枠}");
}
resultList.Add(外行);
foreach (var item in resultList) {
Console.WriteLine(item);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Console_Cs_Test {
class Program {
public static void Main(string[] args) {
string[] line1 = Console.ReadLine().Trim().Split(' ');
int H = int.Parse(line1[0]);
int W = int.Parse(line1[1]);
List<string> list = new List<string>();
for (int i = 0; i < H; ++i) {
list.Add(Console.ReadLine().Trim());
}
// 出力
string 枠 = "#";
string 外行 = string.Empty;
for (int i = 0; i < W + 2; ++i) {
外行 += 枠;
}
List<string> resultList = new List<string>();
resultList.Add(外行);
foreach (var item in list) {
resultList.Add($"{枠}{item}{枠}");
}
resultList.Add(外行);
foreach (var item in resultList) {
Console.WriteLine(item);
}
Console.ReadLine();
}
}
}
|
[["-", 0, 195, 8, 196, 0, 42, 0, 5, 0, 222], ["+", 0, 195, 8, 196, 0, 42, 0, 5, 0, 222], ["+", 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
| 247
| 8
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contest {
class Program {
static void Main() {
var HW = Console.ReadLine().Split().Select(int.Parse);
int H = HW.First(), W = HW.Last();
for (int i = 0; i < W + 2; i++) {
Console.Write("#");
}
for (int i = 0; i < H; i++) {
Console.WriteLine($"#{Console.ReadLine()}#");
}
for (int i = 0; i < W + 2; i++) {
Console.Write("#");
}
#if DEBUG
Console.ReadKey();
#endif
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contest {
class Program {
static void Main() {
var HW = Console.ReadLine().Split().Select(int.Parse);
int H = HW.First(), W = HW.Last();
for (int i = 0; i < W + 2; i++) {
Console.Write("#");
}
Console.WriteLine();
for (int i = 0; i < H; i++) {
Console.WriteLine($"#{Console.ReadLine()}#");
}
for (int i = 0; i < W + 2; i++) {
Console.Write("#");
}
Console.WriteLine();
#if DEBUG
Console.ReadKey();
#endif
}
}
}
|
[["+", 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
| 177
| 12
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
// var s = Console.ReadLine();
// var n = int.Parse(Console.ReadLine());
int[] hw = Console.ReadLine().Split().Select(int.Parse).ToArray();
var h = hw[0];
var w = hw[1];
//分割方法は4パターン
//初めに2パターン
var s1 = 0;
var s2 = 0;
var s3 = 0;
var h1 = 1;
var max = 0;
var min = 0;
var ans = int.MaxValue;
for (h1 = 1; h1 < h; h1++) {
//残りの二つを横に分割するパターン
s1 = h1 * w;
s2 = (h - h1) / 2 * w;
s3 = h * w - s1 - s2;
max = Math.Max(Math.Max(s1, s2), s3);
min = Math.Min(Math.Min(s1, s2), s3);
ans = Math.Min(ans, max - min);
//残りの二つを縦に分割するパターン
s1 = h1 * w;
s2 = (h - h1) * (int)Math.Floor((double)w / (double)2);
s3 = h * w - s1 - s2;
max = Math.Max(Math.Max(s1, s2), s3);
min = Math.Min(Math.Min(s1, s2), s3);
ans = Math.Min(ans, max - min);
}
var w1 = 1;
for (w1 = 1; w1 < w; w1++) {
//残りの二つを横に分割するパターン
s1 = w1 * h;
s2 = (w - w1) / 2 * h;
s3 = h * w - s1 - s2;
max = Math.Max(Math.Max(s1, s2), s3);
min = Math.Min(Math.Min(s1, s2), s3);
ans = Math.Min(ans, max - min);
//残りの二つを縦に分割するパターン
s1 = w1 * h;
s2 = (w - w1) * (int)Math.Floor((double)h / (double)2);
s3 = h * w - s1 - s2;
max = Math.Max(Math.Max(s1, s2), s3);
min = Math.Min(Math.Min(s1, s2), s3);
ans = Math.Min(ans, max - min);
}
// 出力
Console.WriteLine(ans);
}
}
|
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
// 入力
// long s = Console.ReadLine();
// long n = long.Parse(Console.ReadLine());
long[] hw = Console.ReadLine().Split().Select(long.Parse).ToArray();
long h = hw[0];
long w = hw[1];
//分割方法は4パターン
//初めに2パターン
long s1 = 0;
long s2 = 0;
long s3 = 0;
long h1 = 1;
long max = 0;
long min = 0;
long ans = long.MaxValue;
for (h1 = 1; h1 < h; h1++) {
//残りの二つを横に分割するパターン
s1 = h1 * w;
s2 = (h - h1) / 2 * w;
s3 = h * w - s1 - s2;
max = Math.Max(Math.Max(s1, s2), s3);
min = Math.Min(Math.Min(s1, s2), s3);
ans = Math.Min(ans, max - min);
//残りの二つを縦に分割するパターン
s1 = h1 * w;
s2 = (h - h1) * (long)Math.Floor((double)w / (double)2);
s3 = h * w - s1 - s2;
max = Math.Max(Math.Max(s1, s2), s3);
min = Math.Min(Math.Min(s1, s2), s3);
ans = Math.Min(ans, max - min);
}
long w1 = 1;
for (w1 = 1; w1 < w; w1++) {
//残りの二つを横に分割するパターン
s1 = w1 * h;
s2 = (w - w1) / 2 * h;
s3 = h * w - s1 - s2;
max = Math.Max(Math.Max(s1, s2), s3);
min = Math.Min(Math.Min(s1, s2), s3);
ans = Math.Min(ans, max - min);
//残りの二つを縦に分割するパターン
s1 = w1 * h;
s2 = (w - w1) * (long)Math.Floor((double)h / (double)2);
s3 = h * w - s1 - s2;
max = Math.Max(Math.Max(s1, s2), s3);
min = Math.Min(Math.Min(s1, s2), s3);
ans = Math.Min(ans, max - min);
}
// 出力
Console.WriteLine(ans);
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["-", 0, 1, 0, 11, 12, 16, 12, 74, 39, 199], ["+", 0, 1, 0, 11, 12, 16, 12, 74, 39, 199]]
| 8
| 507
| 30
|
using System;
using System.Linq;
using System.Collections.Generic;
class P {
static void Main() {
long[] hw = Console.ReadLine().Split().Select(long.Parse).ToArray();
long res;
if ((hw[1] % 3) * (hw[0] % 3) == 0) {
res = 0;
} else {
long[] a = { hw[0] / 3 * hw[1], (hw[0] - hw[0] / 3) * (hw[1] / 2),
(hw[0] - hw[0] / 3) * (hw[1] - hw[1] / 2) };
long[] b = { (hw[0] / 3 + 1) * hw[1],
(hw[0] - (hw[0] / 3 + 1)) * (hw[1] / 2),
(hw[0] - (hw[0] / 3 + 1)) * (hw[1] - hw[1] / 2) };
long[] c = { hw[1] / 3 * hw[0], (hw[1] - hw[1] / 3) * (hw[0] / 2),
(hw[1] - hw[1] / 3) * (hw[0] - hw[0] / 2) };
long[] d = { (hw[1] / 3 + 1) * hw[0],
(hw[1] - (hw[1] / 3 + 1)) * (hw[0] / 2),
(hw[1] - (hw[0] / 3 + 1)) * (hw[0] - hw[0] / 2) };
res = Math.Min(Math.Min(a.Max() - a.Min(), b.Max() - b.Min()),
Math.Min(c.Max() - c.Min(), d.Max() - d.Min()));
}
Console.WriteLine(res);
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
class P {
static void Main() {
long[] hw = Console.ReadLine().Split().Select(long.Parse).ToArray();
long res;
if ((hw[1] % 3) * (hw[0] % 3) == 0) {
res = 0;
} else {
long[] a = { hw[0] / 3 * hw[1], (hw[0] - hw[0] / 3) * (hw[1] / 2),
(hw[0] - hw[0] / 3) * (hw[1] - hw[1] / 2) };
long[] b = { (hw[0] / 3 + 1) * hw[1],
(hw[0] - (hw[0] / 3 + 1)) * (hw[1] / 2),
(hw[0] - (hw[0] / 3 + 1)) * (hw[1] - hw[1] / 2) };
long[] c = { hw[1] / 3 * hw[0], (hw[1] - hw[1] / 3) * (hw[0] / 2),
(hw[1] - hw[1] / 3) * (hw[0] - hw[0] / 2) };
long[] d = { (hw[1] / 3 + 1) * hw[0],
(hw[1] - (hw[1] / 3 + 1)) * (hw[0] / 2),
(hw[1] - (hw[1] / 3 + 1)) * (hw[0] - hw[0] / 2) };
// Console.WriteLine($"{a.Max() - a.Min()} {b.Max() - b.Min()} {c.Max() -
// c.Min()} {d.Max() - d.Min()}");
res = Math.Min(hw.Select(x => x == 2 ? int.MaxValue : x).Min(),
Math.Min(Math.Min(a.Max() - a.Min(), b.Max() - b.Min()),
Math.Min(c.Max() - c.Min(), d.Max() - d.Min())));
}
Console.WriteLine(res);
}
}
|
[["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 0, 28, 0, 218, 8, 41, 15, 16, 31, 22], ["+", 0, 28, 0, 218, 8, 41, 15, 16, 17, 60], ["+", 0, 28, 0, 218, 8, 41, 15, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 218, 8, 41, 0, 101], ["+", 0, 28, 0, 218, 8, 41, 64, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 41, 64, 214, 0, 131], ["+", 0, 28, 0, 218, 8, 41, 64, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 41, 0, 102], ["+", 3, 4, 0, 28, 0, 218, 8, 41, 75, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 25]]
| 8
| 462
| 28
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC_C {
class C062 {
static long CalcMin(int h, int w) {
long min = long.MaxValue;
for (int i = 1; i < w; i++) {
long S1 = (long)i * h;
int cut = h / 2;
long S2 = (long)(w - i) * cut;
long S3 = (long)(w - i) * (h - cut);
long Smax = Math.Max(S1, S3);
long Smin = Math.Min(S1, S2);
if (min > Smax - Smin) {
min = Smax - Smin;
}
}
return min;
}
static void Main(string[] args) {
string[] s1 = Console.ReadLine().Split(' ');
int h = int.Parse(s1[0]);
int w = int.Parse(s1[1]);
if (h % 3 == 0 || w % 3 == 0) {
Console.WriteLine(0);
} else {
long m1 = CalcMin(w, h);
long m2 = CalcMin(h, w);
long min = Math.Min(m1, m2);
Console.WriteLine(min);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC_C {
class C062 {
static long CalcMin(int h, int w) {
long min = long.MaxValue;
for (int i = 1; i < w; i++) {
long S1 = (long)i * h;
int cut = h / 2;
long S2 = (long)(w - i) * cut;
long S3 = (long)(w - i) * (h - cut);
long Smax = Math.Max(S1, S3);
long Smin = Math.Min(S1, S2);
if (min > Smax - Smin) {
min = Smax - Smin;
}
}
return min;
}
static void Main(string[] args) {
string[] s1 = Console.ReadLine().Split(' ');
int h = int.Parse(s1[0]);
int w = int.Parse(s1[1]);
if (h % 3 == 0 || w % 3 == 0) {
Console.WriteLine(0);
} else {
long m1 = CalcMin(w, h);
long m2 = CalcMin(h, w);
long m3 = Math.Min(h, w); //平行切り
long min = Math.Min(Math.Min(m1, m2), m3);
Console.WriteLine(min);
}
}
}
}
|
[["+", 75, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 196, 0, 197, 0, 35], ["+", 0, 57, 75, 196, 0, 197, 0, 198, 39, 199], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
| 8
| 282
| 19
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using static System.Console;
using static System.Math;
class Simple {
private int H, W;
private string[] a;
void Solve() {
// input
H = io.Int;
W = io.Int;
// cal
var ans = long.MaxValue;
// type A1 横横横
if (H >= 3)
ans = Min(ans, A(H, W));
// type A2 縦縦縦
if (W >= 3)
ans = Min(ans, A(W, H));
// type B1 縦横横
ans = Min(ans, B(H, W));
// rtpe B2 横縦縦
ans = Min(ans, B(W, H));
// ret
WriteLine(ans);
}
long A(long a, long b) => a % 3 == 0 ? 0 : b;
long B(long a, long b) {
var ret = long.MaxValue;
var aIsOdd = a % 2 != 0;
for (int i = 1; i < b; ++i) {
var v1 = a * i;
var v2 = (b - i) * (a / 2);
var v3 = (b - i) * (b - (a / 2));
ret = Min(ret, myMax(v1, v2, v3) - myMin(v1, v2, v3));
}
return ret;
}
long myMin(params long[] a) => a.Min();
long myMax(params long[] a) => a.Max();
SimpleIO io = new SimpleIO();
public static void Main(string[] args) => new Simple().Stream();
private void Stream() {
// var exStdIn = new System.IO.StreamReader("stdin.txt");
// SetIn(exStdIn);
Solve();
io.Flush();
}
}
class SimpleIO {
string[] _nextBuffer;
int _bufferCnt;
char[] cs = new char[] { ' ', '"', ',' };
StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = true };
public SimpleIO() {
_nextBuffer = new string[0];
_bufferCnt = 0;
SetOut(sw);
}
string Next() {
if (_bufferCnt < _nextBuffer.Length)
return _nextBuffer[_bufferCnt++];
var st = ReadLine();
while (st == "")
st = ReadLine();
if (st != null)
_nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
else
st = "";
_bufferCnt = 0;
return _nextBuffer[_bufferCnt++];
}
public string String => Next();
public char Char => char.Parse(String);
public int Int => int.Parse(String);
public long Long => long.Parse(String);
public double Double => double.Parse(String);
public void Flush() => Out.Flush();
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using static System.Console;
using static System.Math;
class Simple {
private int H, W;
private string[] a;
void Solve() {
// input
H = io.Int;
W = io.Int;
// cal
var ans = long.MaxValue;
// type A1 横横横
if (H >= 3)
ans = Min(ans, A(H, W));
// type A2 縦縦縦
if (W >= 3)
ans = Min(ans, A(W, H));
// type B1 縦横横
ans = Min(ans, B(H, W));
// rtpe B2 横縦縦
ans = Min(ans, B(W, H));
// ret
WriteLine(ans);
}
long A(long a, long b) => a % 3 == 0 ? 0 : b;
long B(long a, long b) {
var ret = long.MaxValue;
for (int i = 1; i < b; ++i) {
var v1 = a * i;
var v2 = (b - i) * (a / 2);
var v3 = (b - i) * (a - (a / 2));
ret = Min(ret, myMax(v1, v2, v3) - myMin(v1, v2, v3));
}
return ret;
}
long myMin(params long[] a) => a.Min();
long myMax(params long[] a) => a.Max();
SimpleIO io = new SimpleIO();
public static void Main(string[] args) => new Simple().Stream();
private void Stream() {
// var exStdIn = new System.IO.StreamReader("stdin.txt");
// SetIn(exStdIn);
Solve();
io.Flush();
}
}
class SimpleIO {
string[] _nextBuffer;
int _bufferCnt;
char[] cs = new char[] { ' ', '"', ',' };
StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = true };
public SimpleIO() {
_nextBuffer = new string[0];
_bufferCnt = 0;
SetOut(sw);
}
string Next() {
if (_bufferCnt < _nextBuffer.Length)
return _nextBuffer[_bufferCnt++];
var st = ReadLine();
while (st == "")
st = ReadLine();
if (st != null)
_nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
else
st = "";
_bufferCnt = 0;
return _nextBuffer[_bufferCnt++];
}
public string String => Next();
public char Char => char.Parse(String);
public int Int => int.Parse(String);
public long Long => long.Parse(String);
public double Double => double.Parse(String);
public void Flush() => Out.Flush();
}
|
[["-", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 234, 22], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 0, 131], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 141, 22], ["-", 0, 231, 141, 232, 234, 232, 234, 232, 234, 22], ["-", 0, 231, 141, 232, 234, 232, 234, 232, 0, 131], ["-", 0, 231, 141, 232, 234, 232, 234, 232, 141, 22], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 31, 22], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 109], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 12, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 79], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 212, 0, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 31, 22]]
| 8
| 612
| 32
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace AtCoder {
class MainClass {
// C#7.0
long H, W;
void Solve() {
io.i(out H, out W);
long ans = long.MaxValue;
if (H % 3 == 0 || W % 3 == 0) {
ans = 0;
} else {
for (long i = 1; i < H; i++) {
long tmp = diff(H, W, i);
if (ans > tmp)
ans = tmp;
}
for (long i = 1; i < W; i++) {
long tmp = diff(W, H, i);
if (ans > tmp)
ans = tmp;
}
}
io.o(ans);
}
long diff(long e1, long e2, long i) {
long e = e2 / 2;
long s1 = e2 * i;
long s2 = (e1 - i) * e;
long s3 = (e1 - i) * (e2 - e);
return max(s1, s2, s3) - min(s1, s2, s3);
}
long min(params long[] a) { return a.Min(); }
long max(params long[] a) { return a.Max(); }
public static void Main(string[] args) { new MainClass().Stream(); }
IO io = new IO();
void Stream() {
Solve();
io.writeFlush();
}
class IO {
string[] nextBuffer;
int BufferCnt;
char[] cs = new char[] { ' ' };
StreamWriter sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
public IO() {
nextBuffer = new string[0];
BufferCnt = 0;
Console.SetOut(sw);
}
public string next() {
if (BufferCnt < nextBuffer.Length)
return nextBuffer[BufferCnt++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
BufferCnt = 0;
return nextBuffer[BufferCnt++];
}
public char nextChar() { return char.Parse(next()); }
public int nextInt() { return int.Parse(next()); }
public long nextLong() { return long.Parse(next()); }
public double nextDouble() { return double.Parse(next()); }
public string[] array() { return Console.ReadLine().Split(' '); }
public char[] arrayChar() { return Array.ConvertAll(array(), char.Parse); }
public int[] arrayInt() { return Array.ConvertAll(array(), int.Parse); }
public long[] arrayLong() { return Array.ConvertAll(array(), long.Parse); }
public double[] arrayDouble() {
return Array.ConvertAll(array(), double.Parse);
}
private bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); }
private T convertType<T, U>(U v) {
return (T)Convert.ChangeType(v, typeof(T));
}
private T suitType<T>(string s) {
if (typeEQ<T, int>())
return convertType<T, int>(int.Parse(s));
if (typeEQ<T, long>())
return convertType<T, long>(long.Parse(s));
if (typeEQ<T, double>())
return convertType<T, double>(double.Parse(s));
if (typeEQ<T, char>())
return convertType<T, char>(char.Parse(s));
return convertType<T, string>(s);
}
public void i<T>(out T v) { v = suitType<T>(next()); }
public void i<T, U>(out T v1, out U v2) {
var a = array();
v1 = suitType<T>(a[0]);
v2 = suitType<U>(a[1]);
}
public void i<T, U, V>(out T v1, out U v2, out V v3) {
var a = array();
v1 = suitType<T>(a[0]);
v2 = suitType<U>(a[1]);
v3 = suitType<V>(a[2]);
}
public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) {
var a = array();
v1 = suitType<T>(a[0]);
v2 = suitType<U>(a[1]);
v3 = suitType<V>(a[2]);
v4 = suitType<W>(a[3]);
}
public void ini(out int[] a, int size) {
a = new int[size];
for (int i = 0; i < size; i++)
a[i] = nextInt();
}
public void ini(out int[] a1, out int[] a2, int size) {
a1 = new int[size];
a2 = new int[size];
for (int i = 0; i < size; i++) {
a1[i] = nextInt();
a2[i] = nextInt();
}
}
public void ini(out string[] a, int size) {
a = new string[size];
for (int i = 0; i < size; i++)
a[i] = next();
}
public void inii(out int[] a, int size) {
a = new int[size];
for (int i = 0; i < size; i++)
a[i] = nextInt() - 1;
}
public void inii(out int[] a1, out int[] a2, int size) {
a1 = new int[size];
a2 = new int[size];
for (int i = 0; i < size; i++) {
a1[i] = nextInt() - 1;
a2[i] = nextInt() - 1;
}
}
public void o<T>(T v) { Console.WriteLine(v); }
public void o<T>(params T[] a) {
foreach (T v in a)
Console.WriteLine(v);
}
public void o<T>(List<T> l) {
foreach (T v in l)
sw.WriteLine(v);
}
public void ol<T>(T v) { Console.Write(v + " "); }
public void ol<T>(params T[] a) {
foreach (T v in a)
Console.Write(v + " ");
Console.WriteLine("");
}
public void YN(bool f) { Console.WriteLine(f ? "YES" : "NO"); }
public void Yn(bool f) { Console.WriteLine(f ? "Yes" : "No"); }
public void yn(bool f) { Console.WriteLine(f ? "yes" : "no"); }
public void writeFlush() { Console.Out.Flush(); }
}
class Mathf {
public int mod = 1000000007; // 10^9+7
public long Pow(long a, long b) {
if (b == 0)
return 1;
if (b % 2 == 1)
return (a % mod * Pow(a % mod, b - 1) % mod) % mod;
else
return Pow(a * a % mod, b / 2) % mod;
}
public long Fact(long n) {
return n != 0 ? (n % mod * (Fact(n - 1) % mod) % mod) : 1;
}
public long C(long n, long r) {
if (r == 0 || n == r)
return 1;
else
return (Fact(n) % mod *
Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) %
mod;
}
public long Sum(params long[] a) {
return a.Aggregate((v, next) => (v % mod + next) % mod);
}
public int GCD(int a, int b) {
if (a < b)
Swap(ref a, ref b);
return b == 0 ? a : GCD(b, a % b);
}
public int GCD(int[] array) {
return array.Aggregate((v, next) => GCD(v, next));
}
public void Swap<T>(ref T a, ref T b) {
T tmp = a;
a = b;
b = tmp;
}
public T Max<T>(params T[] v) { return v.Max(); }
public T Min<T>(params T[] v) { return v.Min(); }
public double Dis(int x1, int y1, int x2, int y2) {
return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2));
}
}
}
static class StringEX {
public static string Reversed(this string s) {
return string.Join("", s.Reverse());
}
public static string Repeat(this string s, int n) {
return string.Concat(Enumerable.Repeat(s, n).ToArray());
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace AtCoder {
class MainClass {
// C#7.0
long H, W;
void Solve() {
io.i(out H, out W);
long ans = long.MaxValue;
if (H % 3 == 0 || W % 3 == 0) {
ans = 0;
} else {
ans = Math.Min(H, W);
for (long i = 1; i < H; i++) {
long tmp = diff(H, W, i);
if (ans > tmp)
ans = tmp;
}
for (long i = 1; i < W; i++) {
long tmp = diff(W, H, i);
if (ans > tmp)
ans = tmp;
}
}
io.o(ans);
}
long diff(long e1, long e2, long i) {
long e = e2 / 2;
long s1 = e2 * i;
long s2 = (e1 - i) * e;
long s3 = (e1 - i) * (e2 - e);
return max(s1, s2, s3) - min(s1, s2, s3);
}
long min(params long[] a) { return a.Min(); }
long max(params long[] a) { return a.Max(); }
public static void Main(string[] args) { new MainClass().Stream(); }
IO io = new IO();
void Stream() {
Solve();
io.writeFlush();
}
class IO {
string[] nextBuffer;
int BufferCnt;
char[] cs = new char[] { ' ' };
StreamWriter sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
public IO() {
nextBuffer = new string[0];
BufferCnt = 0;
Console.SetOut(sw);
}
public string next() {
if (BufferCnt < nextBuffer.Length)
return nextBuffer[BufferCnt++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
BufferCnt = 0;
return nextBuffer[BufferCnt++];
}
public char nextChar() { return char.Parse(next()); }
public int nextInt() { return int.Parse(next()); }
public long nextLong() { return long.Parse(next()); }
public double nextDouble() { return double.Parse(next()); }
public string[] array() { return Console.ReadLine().Split(' '); }
public char[] arrayChar() { return Array.ConvertAll(array(), char.Parse); }
public int[] arrayInt() { return Array.ConvertAll(array(), int.Parse); }
public long[] arrayLong() { return Array.ConvertAll(array(), long.Parse); }
public double[] arrayDouble() {
return Array.ConvertAll(array(), double.Parse);
}
private bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); }
private T convertType<T, U>(U v) {
return (T)Convert.ChangeType(v, typeof(T));
}
private T suitType<T>(string s) {
if (typeEQ<T, int>())
return convertType<T, int>(int.Parse(s));
if (typeEQ<T, long>())
return convertType<T, long>(long.Parse(s));
if (typeEQ<T, double>())
return convertType<T, double>(double.Parse(s));
if (typeEQ<T, char>())
return convertType<T, char>(char.Parse(s));
return convertType<T, string>(s);
}
public void i<T>(out T v) { v = suitType<T>(next()); }
public void i<T, U>(out T v1, out U v2) {
var a = array();
v1 = suitType<T>(a[0]);
v2 = suitType<U>(a[1]);
}
public void i<T, U, V>(out T v1, out U v2, out V v3) {
var a = array();
v1 = suitType<T>(a[0]);
v2 = suitType<U>(a[1]);
v3 = suitType<V>(a[2]);
}
public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) {
var a = array();
v1 = suitType<T>(a[0]);
v2 = suitType<U>(a[1]);
v3 = suitType<V>(a[2]);
v4 = suitType<W>(a[3]);
}
public void ini(out int[] a, int size) {
a = new int[size];
for (int i = 0; i < size; i++)
a[i] = nextInt();
}
public void ini(out int[] a1, out int[] a2, int size) {
a1 = new int[size];
a2 = new int[size];
for (int i = 0; i < size; i++) {
a1[i] = nextInt();
a2[i] = nextInt();
}
}
public void ini(out string[] a, int size) {
a = new string[size];
for (int i = 0; i < size; i++)
a[i] = next();
}
public void inii(out int[] a, int size) {
a = new int[size];
for (int i = 0; i < size; i++)
a[i] = nextInt() - 1;
}
public void inii(out int[] a1, out int[] a2, int size) {
a1 = new int[size];
a2 = new int[size];
for (int i = 0; i < size; i++) {
a1[i] = nextInt() - 1;
a2[i] = nextInt() - 1;
}
}
public void o<T>(T v) { Console.WriteLine(v); }
public void o<T>(params T[] a) {
foreach (T v in a)
Console.WriteLine(v);
}
public void o<T>(List<T> l) {
foreach (T v in l)
sw.WriteLine(v);
}
public void ol<T>(T v) { Console.Write(v + " "); }
public void ol<T>(params T[] a) {
foreach (T v in a)
Console.Write(v + " ");
Console.WriteLine("");
}
public void YN(bool f) { Console.WriteLine(f ? "YES" : "NO"); }
public void Yn(bool f) { Console.WriteLine(f ? "Yes" : "No"); }
public void yn(bool f) { Console.WriteLine(f ? "yes" : "no"); }
public void writeFlush() { Console.Out.Flush(); }
}
class Mathf {
public int mod = 1000000007; // 10^9+7
public long Pow(long a, long b) {
if (b == 0)
return 1;
if (b % 2 == 1)
return (a % mod * Pow(a % mod, b - 1) % mod) % mod;
else
return Pow(a * a % mod, b / 2) % mod;
}
public long Fact(long n) {
return n != 0 ? (n % mod * (Fact(n - 1) % mod) % mod) : 1;
}
public long C(long n, long r) {
if (r == 0 || n == r)
return 1;
else
return (Fact(n) % mod *
Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) %
mod;
}
public long Sum(params long[] a) {
return a.Aggregate((v, next) => (v % mod + next) % mod);
}
public int GCD(int a, int b) {
if (a < b)
Swap(ref a, ref b);
return b == 0 ? a : GCD(b, a % b);
}
public int GCD(int[] array) {
return array.Aggregate((v, next) => GCD(v, next));
}
public void Swap<T>(ref T a, ref T b) {
T tmp = a;
a = b;
b = tmp;
}
public T Max<T>(params T[] v) { return v.Max(); }
public T Min<T>(params T[] v) { return v.Min(); }
public double Dis(int x1, int y1, int x2, int y2) {
return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2));
}
}
}
static class StringEX {
public static string Reversed(this string s) {
return string.Join("", s.Reverse());
}
public static string Repeat(this string s, int n) {
return string.Concat(Enumerable.Repeat(s, n).ToArray());
}
}
}
|
[["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35]]
| 8
| 2,071
| 11
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoderBeginnerContest {
public class Program {
static long H;
static long W;
static long s;
public static void Main(string[] args) {
var HW = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
if (HW[0] > HW[1]) {
H = HW[0];
W = HW[1];
} else {
H = HW[1];
W = HW[0];
}
s = H * W;
// 3分割できるとき
if (H % 3 == 0 || W % 3 == 0) {
Console.WriteLine(0);
return;
}
// できないとき
// a1の高さがHのとき(左の四角)
for (long i = 1; i < W; i++) {
long a1 = H * i;
long a2 = (long)(H / 2) * i;
long a3 = H * W - a1 - a2;
var sw = Math.Abs(a1 - a2);
if (sw < Math.Abs(a1 - a3))
sw = Math.Abs(a1 - a3);
if (sw < Math.Abs(a2 - a3))
sw = Math.Abs(a2 - a3);
if (s > sw)
s = sw;
}
for (long i = 1; i < W; i++) {
long a1 = H * i;
long a2 = (long)((W - i) / 2) * H;
long a3 = H * W - a1 - a2;
var sw = Math.Abs(a1 - a2);
if (sw < Math.Abs(a1 - a3))
sw = Math.Abs(a1 - a3);
if (sw < Math.Abs(a2 - a3))
sw = Math.Abs(a2 - a3);
if (s > sw)
s = sw;
}
// a2の幅がWのとき(上の四角)
for (long i = 1; i < H; i++) {
long a1 = i * (long)(W / 2);
long a2 = (H - i) * W;
long a3 = H * W - a1 - a2;
var sw = Math.Abs(a1 - a2);
if (sw < Math.Abs(a1 - a3))
sw = Math.Abs(a1 - a3);
if (sw < Math.Abs(a2 - a3))
sw = Math.Abs(a2 - a3);
if (s > sw)
s = sw;
}
for (long i = 1; i < H; i++) {
long a1 = i * W;
long a2 = (long)((H - i) / 2) * W;
long a3 = H * W - a1 - a2;
var sw = Math.Abs(a1 - a2);
if (sw < Math.Abs(a1 - a3))
sw = Math.Abs(a1 - a3);
if (sw < Math.Abs(a2 - a3))
sw = Math.Abs(a2 - a3);
if (s > sw)
s = sw;
}
Console.WriteLine(s);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoderBeginnerContest {
public class Program {
static long H;
static long W;
static long s;
public static void Main(string[] args) {
var HW = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
if (HW[0] > HW[1]) {
H = HW[0];
W = HW[1];
} else {
H = HW[1];
W = HW[0];
}
s = H * W;
// 3分割できるとき
if (H % 3 == 0 || W % 3 == 0) {
Console.WriteLine(0);
return;
}
// できないとき
// a1の高さがHのとき(左の四角)
for (long i = 1; i < W; i++) {
long a1 = H * i;
long a2 = (long)(H / 2) * (W - i);
long a3 = H * W - a1 - a2;
var sw = Math.Abs(a1 - a2);
if (sw < Math.Abs(a1 - a3))
sw = Math.Abs(a1 - a3);
if (sw < Math.Abs(a2 - a3))
sw = Math.Abs(a2 - a3);
if (s > sw)
s = sw;
}
for (long i = 1; i < W; i++) {
long a1 = H * i;
long a2 = (long)((W - i) / 2) * H;
long a3 = H * W - a1 - a2;
var sw = Math.Abs(a1 - a2);
if (sw < Math.Abs(a1 - a3))
sw = Math.Abs(a1 - a3);
if (sw < Math.Abs(a2 - a3))
sw = Math.Abs(a2 - a3);
if (s > sw)
s = sw;
}
// a2の幅がWのとき(上の四角)
for (long i = 1; i < H; i++) {
long a1 = i * W;
long a2 = (H - i) * (long)(W / 2);
long a3 = H * W - a1 - a2;
var sw = Math.Abs(a1 - a2);
if (sw < Math.Abs(a1 - a3))
sw = Math.Abs(a1 - a3);
if (sw < Math.Abs(a2 - a3))
sw = Math.Abs(a2 - a3);
if (s > sw)
s = sw;
}
for (long i = 1; i < H; i++) {
long a1 = i * W;
long a2 = (long)((H - i) / 2) * W;
long a3 = H * W - a1 - a2;
var sw = Math.Abs(a1 - a2);
if (sw < Math.Abs(a1 - a3))
sw = Math.Abs(a1 - a3);
if (sw < Math.Abs(a2 - a3))
sw = Math.Abs(a2 - a3);
if (s > sw)
s = sw;
}
Console.WriteLine(s);
}
}
}
|
[["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 24], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 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], ["-", 0, 212, 0, 16, 12, 74, 51, 23, 0, 24], ["-", 0, 16, 12, 74, 51, 23, 0, 16, 17, 85], ["-", 0, 16, 12, 74, 51, 23, 0, 16, 12, 203], ["-", 0, 212, 0, 16, 12, 74, 51, 23, 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], ["+", 0, 212, 0, 16, 12, 74, 51, 23, 0, 24], ["+", 0, 16, 12, 74, 51, 23, 0, 16, 17, 85], ["+", 0, 16, 12, 74, 51, 23, 0, 16, 12, 203], ["+", 0, 212, 0, 16, 12, 74, 51, 23, 0, 25]]
| 8
| 651
| 18
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
public class Program {
public static decimal ans = decimal.MaxValue;
public static void Main() {
Reader reader = new Reader(Console.In);
int H = reader.RInt();
int W = reader.Int();
if (W > H) {
int temp = H;
H = W;
W = temp;
}
CalcA(H, W);
CalcA(W, H);
CalcB(H, W);
CalcB(W, H);
Console.WriteLine((long)ans);
}
public static void CalcA(int H, int W) {
for (decimal i = 1; i < H; i++) {
decimal a = i * W;
decimal bh = (H - i) / 2;
decimal ch = H - i - bh;
Diff(a, bh * W, ch * W);
if (ans == 0) {
return;
}
}
}
public static void CalcB(int H, int W) {
for (decimal i = 1; i < H; i++) {
decimal a = i * W;
decimal bw = W / 2;
decimal cw = W - bw;
decimal b = (H - i) * bw;
decimal c = (H - i) * cw;
Diff(a, b, c);
if (ans == 0) {
return;
}
}
}
public static void Diff(decimal a, decimal b, decimal c) {
var list = new List<decimal> { a, b, c };
decimal diff = list.Max() - list.Min();
if (diff < ans) {
ans = diff;
}
}
}
public class Reader {
private readonly TextReader reader;
private readonly char separator = ' ';
private string[] A = new string[0];
private int i;
public Reader(TextReader r) { reader = r; }
public string String() { return Set(); }
public int Int() { return int.Parse(Set()); }
public long Long() { return long.Parse(Set()); }
public decimal Decimal() { return decimal.Parse(Set()); }
public string RString() { return RSet(); }
public int RInt() { return int.Parse(RSet()); }
public long RLong() { return long.Parse(RSet()); }
public decimal RDecimal() { return decimal.Parse(RSet()); }
public int[] IntArray() { return A.Select(x => int.Parse(x)).ToArray(); }
private void Read() {
string line = reader.ReadLine();
A = line.Split(separator);
i = 0;
}
private string Set() { return A[i++]; }
private string RSet() {
Read();
return A[i++];
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
public class Program {
public static long ans = long.MaxValue;
public static void Main() {
Reader reader = new Reader(Console.In);
long H = reader.RLong();
long W = reader.Long();
if (W > H) {
long temp = H;
H = W;
W = temp;
}
CalcA(H, W);
CalcA(W, H);
CalcB(H, W);
CalcB(W, H);
Console.WriteLine((long)ans);
}
public static void CalcA(long H, long W) {
for (long i = 1; i < H; i++) {
long a = i * W;
long bh = (H - i) / 2;
long ch = H - i - bh;
Diff(a, bh * W, ch * W);
if (ans == 0) {
return;
}
}
}
public static void CalcB(long H, long W) {
for (int i = 1; i < H; i++) {
long a = i * W;
long bw = W / 2;
long cw = W - bw;
long b = (H - i) * bw;
long c = (H - i) * cw;
Diff(a, b, c);
if (ans == 0) {
return;
}
}
}
public static void Diff(long a, long b, long c) {
var list = new List<long> { a, b, c };
long diff = list.Max() - list.Min();
if (diff < ans) {
ans = diff;
}
}
}
public class Reader {
private readonly TextReader reader;
private readonly char separator = ' ';
private string[] A = new string[0];
private int i;
public Reader(TextReader r) { reader = r; }
public string String() { return Set(); }
public int Int() { return int.Parse(Set()); }
public long Long() { return long.Parse(Set()); }
public decimal Decimal() { return decimal.Parse(Set()); }
public string RString() { return RSet(); }
public int RInt() { return int.Parse(RSet()); }
public long RLong() { return long.Parse(RSet()); }
public decimal RDecimal() { return decimal.Parse(RSet()); }
public int[] IntArray() { return A.Select(x => int.Parse(x)).ToArray(); }
private void Read() {
string line = reader.ReadLine();
A = line.Split(separator);
i = 0;
}
private string Set() { return A[i++]; }
private string RSet() {
Read();
return A[i++];
}
}
|
[["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["+", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["-", 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, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 57, 64, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 57, 64, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199]]
| 8
| 621
| 52
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
long H, W, ans = long.MaxValue, sa = 0, sb = 0, sc = 0;
string[] s = Console.ReadLine().Split(' ');
H = int.Parse(s[0]);
W = int.Parse(s[1]);
if (H % 3 == 0 || W % 3 == 0) {
ans = 0;
} else {
for (int i = 1; i < H; i++) {
sa = i * W;
if (W % 2 == 0) {
sb = (H - i) * (W / 2);
sc = sb;
} else {
sb = (H - i) * ((W + 1) / 2);
sc = (H - i) * ((W - 1) / 2);
}
long a =
Math.Max(sa, Math.Max(sb, sc)) - Math.Min(sa, Math.Min(sb, sc));
ans = Math.Min(ans, a);
}
for (uint i = 1; i < W; i++) {
sa = i * H;
if (H % 2 == 0) {
sb = (W - i) * (H / 2);
sc = sb;
} else {
sb = (W - i) * ((H + 1) / 2);
sc = (W - i) * ((H - 1) / 2);
}
long a =
Math.Max(sa, Math.Max(sb, sc)) - Math.Min(sa, Math.Min(sb, sc));
ans = Math.Min(ans, a);
}
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1 {
class Program {
static void Main(string[] args) {
long H, W, ans = long.MaxValue, sa = 0, sb = 0, sc = 0;
string[] s = Console.ReadLine().Split(' ');
H = int.Parse(s[0]);
W = int.Parse(s[1]);
ans = Math.Min(ans, H);
ans = Math.Min(ans, W);
if (H % 3 == 0 || W % 3 == 0) {
ans = 0;
} else {
for (int i = 1; i < H; i++) {
sa = i * W;
if (W % 2 == 0) {
sb = (H - i) * (W / 2);
sc = sb;
} else {
sb = (H - i) * ((W + 1) / 2);
sc = (H - i) * ((W - 1) / 2);
}
long a =
Math.Max(sa, Math.Max(sb, sc)) - Math.Min(sa, Math.Min(sb, sc));
ans = Math.Min(ans, a);
}
for (uint i = 1; i < W; i++) {
sa = i * H;
if (H % 2 == 0) {
sb = (W - i) * (H / 2);
sc = sb;
} else {
sb = (W - i) * ((H + 1) / 2);
sc = (W - i) * ((H - 1) / 2);
}
long a =
Math.Max(sa, Math.Max(sb, sc)) - Math.Min(sa, Math.Min(sb, sc));
ans = Math.Min(ans, a);
}
}
Console.WriteLine(ans);
}
}
}
|
[["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 411
| 22
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace abc62 {
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split(' ');
int H = int.Parse(str[0]);
int W = int.Parse(str[1]);
int ans = 0;
if (H % 3 == 0 || W % 3 == 0) {
ans = 0;
} else {
int ans1 = 0;
int ans2 = 0;
if (H % 2 == 0) {
ans1 = H / 2;
} else {
int a = W / 3;
int b = H / 2;
if (W % 3 == 1) {
ans1 = Math.Min(Math.Max(a + 2 * b + 1, 2 * a),
Math.Max(2 * a + 1, a + b + 1));
} else {
ans1 = Math.Max(2 * a + 1, a + b + 1);
}
}
if (W % 2 == 0) {
ans2 = W / 2;
} else {
int a = H / 3;
int b = W / 2;
if (H % 3 == 1) {
ans2 = Math.Min(Math.Max(a + 2 * b + 1, 2 * a),
Math.Max(2 * a + 1, a + b + 1));
} else {
ans2 = Math.Max(2 * a + 1, a + b + 1);
}
}
ans = Math.Min(ans1, ans2);
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace abc62 {
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split(' ');
int H = int.Parse(str[0]);
int W = int.Parse(str[1]);
int ans = 0;
if (H % 3 == 0 || W % 3 == 0) {
ans = 0;
} else {
int ans1 = 0;
int ans2 = 0;
if (H % 2 == 0) {
ans1 = H / 2;
} else {
int a = W / 3;
int b = H / 2;
if (W % 3 == 1) {
ans1 = Math.Min(Math.Max(a + 2 * b + 1, 2 * a),
Math.Max(2 * a + 1, a + b + 1));
} else {
ans1 = Math.Max(2 * a + 1, a + b + 1);
}
}
if (W % 2 == 0) {
ans2 = W / 2;
} else {
int a = H / 3;
int b = W / 2;
if (H % 3 == 1) {
ans2 = Math.Min(Math.Max(a + 2 * b + 1, 2 * a),
Math.Max(2 * a + 1, a + b + 1));
} else {
ans2 = Math.Max(2 * a + 1, a + b + 1);
}
}
ans = Math.Min(ans1, ans2);
}
Console.WriteLine(Math.Min(ans, Math.Min(H, W)));
}
}
}
|
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
| 8
| 358
| 14
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtTest.D_Challenge {
class ABC_062 {
static void Main(string[] args) {
Method(args);
Console.ReadLine();
}
static void Method(string[] args) {
int n = ReadInt();
long[] array = ReadLongs();
var headSums = new long[n + 1];
headSums[0] = 0;
var sDictH = new PriorityQueueNum<bool>();
for (int i = 0; i < n; i++) {
headSums[0] += array[i];
sDictH.Add(array[i], true);
}
for (int i = 1; i <= n; i++) {
headSums[i] = headSums[i - 1] + array[n + i - 1];
sDictH.Add(array[n + i - 1], true);
headSums[i] -= sDictH.Dequeue().Key;
}
var tailSums = new long[n + 1];
tailSums[0] = 0;
var sDictT = new PriorityQueueNum<bool>(true);
for (int i = 0; i < n; i++) {
tailSums[0] += array[3 * n - i - 1];
sDictT.Add(array[3 * n - i - 1], true);
}
for (int i = 1; i <= n; i++) {
tailSums[i] = tailSums[i - 1] + array[2 * n - i];
sDictT.Add(array[2 * n - i], true);
tailSums[i] -= sDictT.Dequeue().Key;
}
long res = long.MinValue;
for (int i = 0; i <= n; i++) {
res = Math.Max(res, headSums[i] - tailSums[n - i]);
}
}
private static string Read() { return Console.ReadLine(); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
public class PriorityQueueNum<TValue> {
SortedDictionary<long, Queue<TValue>> dict =
new SortedDictionary<long, Queue<TValue>>();
public int Count { get; private set; } = 0;
bool reverse = false;
public PriorityQueueNum(bool reverse = false) { this.reverse = reverse; }
public void Add(long key, TValue value) {
if (reverse)
key = -key;
if (!dict.ContainsKey(key)) {
dict[key] = new Queue<TValue>();
}
dict[key].Enqueue(value);
Count++;
}
public KeyValuePair<long, TValue> Dequeue() {
KeyValuePair<long, Queue<TValue>> queue = dict.First();
if (queue.Value.Count <= 1) {
dict.Remove(queue.Key);
}
Count--;
long key = queue.Key;
if (reverse)
key = -key;
return new KeyValuePair<long, TValue>(key, queue.Value.Dequeue());
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtTest.D_Challenge {
class ABC_062 {
static void Main(string[] args) {
Method(args);
Console.ReadLine();
}
static void Method(string[] args) {
int n = ReadInt();
long[] array = ReadLongs();
var headSums = new long[n + 1];
headSums[0] = 0;
var sDictH = new PriorityQueueNum<bool>();
for (int i = 0; i < n; i++) {
headSums[0] += array[i];
sDictH.Add(array[i], true);
}
for (int i = 1; i <= n; i++) {
headSums[i] = headSums[i - 1] + array[n + i - 1];
sDictH.Add(array[n + i - 1], true);
headSums[i] -= sDictH.Dequeue().Key;
}
var tailSums = new long[n + 1];
tailSums[0] = 0;
var sDictT = new PriorityQueueNum<bool>(true);
for (int i = 0; i < n; i++) {
tailSums[0] += array[3 * n - i - 1];
sDictT.Add(array[3 * n - i - 1], true);
}
for (int i = 1; i <= n; i++) {
tailSums[i] = tailSums[i - 1] + array[2 * n - i];
sDictT.Add(array[2 * n - i], true);
tailSums[i] -= sDictT.Dequeue().Key;
}
long res = long.MinValue;
for (int i = 0; i <= n; i++) {
res = Math.Max(res, headSums[i] - tailSums[n - i]);
}
Console.WriteLine(res);
}
private static string Read() { return Console.ReadLine(); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
public class PriorityQueueNum<TValue> {
SortedDictionary<long, Queue<TValue>> dict =
new SortedDictionary<long, Queue<TValue>>();
public int Count { get; private set; } = 0;
bool reverse = false;
public PriorityQueueNum(bool reverse = false) { this.reverse = reverse; }
public void Add(long key, TValue value) {
if (reverse)
key = -key;
if (!dict.ContainsKey(key)) {
dict[key] = new Queue<TValue>();
}
dict[key].Enqueue(value);
Count++;
}
public KeyValuePair<long, TValue> Dequeue() {
KeyValuePair<long, Queue<TValue>> queue = dict.First();
if (queue.Value.Count <= 1) {
dict.Remove(queue.Key);
}
Count--;
long key = queue.Key;
if (reverse)
key = -key;
return new KeyValuePair<long, TValue>(key, queue.Value.Dequeue());
}
}
}
}
|
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 764
| 7
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtTest.D_Challenge {
class ABC_062 {
static void Main(string[] args) {
Method(args);
Console.ReadLine();
}
static void Method(string[] args) {
int n = ReadInt();
long[] array = ReadLongs();
var headSums = new long[n + 1];
headSums[0] = 0;
var sDictH = new PriorityQueueNum();
for (int i = 0; i < n; i++) {
headSums[0] += array[i];
sDictH.Add(array[i], i);
}
for (int i = 1; i <= n; i++) {
headSums[i] = headSums[i - 1] + array[n + i - 1];
sDictH.Add(array[n + i - 1], i + n);
KeyValuePair<long, long> pair = sDictH.Dequeue();
headSums[i] -= pair.Key;
}
var tailSums = new long[n + 1];
tailSums[0] = 0;
var sDictT = new PriorityQueueNum(true);
for (int i = 0; i < n; i++) {
tailSums[0] += array[3 * n - i - 1];
sDictT.Add(array[3 * n - i - 1], i);
}
for (int i = 1; i <= n; i++) {
tailSums[i] = tailSums[i - 1] + array[2 * n - i];
sDictT.Add(-array[2 * n - i], i + n);
KeyValuePair<long, long> pair = sDictT.Dequeue();
tailSums[i] -= pair.Key;
}
long res = long.MinValue;
for (int i = 0; i <= n; i++) {
res = Math.Max(res, headSums[i] - tailSums[n - i]);
}
Console.WriteLine(res);
}
private static string Read() { return Console.ReadLine(); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
public class PriorityQueueNum {
SortedDictionary<long, Queue<long>> dict =
new SortedDictionary<long, Queue<long>>();
public int Count { get; private set; } = 0;
bool reverse = false;
public PriorityQueueNum(bool reverse = false) { this.reverse = reverse; }
public void Add(long key, long value) {
if (!dict.ContainsKey(key)) {
dict[key] = new Queue<long>();
}
if (reverse)
value = -value;
dict[key].Enqueue(value);
Count++;
}
public KeyValuePair<long, long> Dequeue() {
KeyValuePair<long, Queue<long>> queue = dict.First();
if (queue.Value.Count <= 1) {
dict.Remove(queue.Key);
}
Count--;
long val = queue.Value.Dequeue();
if (reverse)
val = -val;
return new KeyValuePair<long, long>(queue.Key, val);
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtTest.D_Challenge {
class ABC_062 {
static void Main(string[] args) {
Method(args);
Console.ReadLine();
}
static void Method(string[] args) {
int n = ReadInt();
long[] array = ReadLongs();
var headSums = new long[n + 1];
headSums[0] = 0;
var sDictH = new PriorityQueueNum();
for (int i = 0; i < n; i++) {
headSums[0] += array[i];
sDictH.Add(array[i], i);
}
for (int i = 1; i <= n; i++) {
headSums[i] = headSums[i - 1] + array[n + i - 1];
sDictH.Add(array[n + i - 1], i + n);
KeyValuePair<long, long> pair = sDictH.Dequeue();
headSums[i] -= pair.Key;
}
var tailSums = new long[n + 1];
tailSums[0] = 0;
var sDictT = new PriorityQueueNum(true);
for (int i = 0; i < n; i++) {
tailSums[0] += array[3 * n - i - 1];
sDictT.Add(array[3 * n - i - 1], i);
}
// Console.WriteLine(tailSums[0]);
for (int i = 1; i <= n; i++) {
tailSums[i] = tailSums[i - 1] + array[2 * n - i];
sDictT.Add(array[2 * n - i], i + n);
KeyValuePair<long, long> pair = sDictT.Dequeue();
tailSums[i] -= pair.Key;
// Console.WriteLine(pair.Key + " " + tailSums[i]);
}
long res = long.MinValue;
for (int i = 0; i <= n; i++) {
res = Math.Max(res, headSums[i] - tailSums[n - i]);
}
Console.WriteLine(res);
}
private static string Read() { return Console.ReadLine(); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
public class PriorityQueueNum {
SortedDictionary<long, Queue<long>> dict =
new SortedDictionary<long, Queue<long>>();
public int Count { get; private set; } = 0;
bool reverse = false;
public PriorityQueueNum(bool reverse = false) { this.reverse = reverse; }
public void Add(long key, long value) {
if (reverse)
key = -key;
if (!dict.ContainsKey(key)) {
dict[key] = new Queue<long>();
}
dict[key].Enqueue(value);
Count++;
}
public KeyValuePair<long, long> Dequeue() {
KeyValuePair<long, Queue<long>> queue = dict.First();
if (queue.Value.Count <= 1) {
dict.Remove(queue.Key);
}
Count--;
long key = queue.Key;
if (reverse)
key = -key;
return new KeyValuePair<long, long>(key, queue.Value.Dequeue());
}
}
}
}
|
[["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 15, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 1, 0, 11, 12, 241, 0, 33], ["+", 0, 57, 64, 1, 0, 11, 12, 241, 0, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 15, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["-", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 64, 1, 0, 11, 12, 241, 0, 33], ["-", 0, 57, 64, 1, 0, 11, 12, 241, 0, 22], ["-", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 212, 0, 213, 63, 214, 205, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 37, 0, 230, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 37, 0, 230, 3, 4, 0, 21], ["-", 0, 230, 3, 4, 0, 28, 0, 214, 141, 22], ["-", 8, 196, 0, 37, 0, 230, 3, 4, 0, 21], ["-", 0, 37, 0, 230, 3, 4, 0, 28, 0, 22], ["+", 0, 28, 0, 213, 63, 214, 205, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
| 8
| 787
| 41
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST {
static void Main() {
Sol mySol = new Sol();
mySol.Solve();
}
}
class Sol {
public void Solve() {
long min = (long)1e18;
for (int t = 0; t < 2; t++) {
for (long x = 1; x <= H; x++) {
long[] s = new long[3];
s[0] = x * W;
s[1] = (H - x) * (W / 2);
s[2] = H * W - s[0] - s[1];
Array.Sort(s);
min = Math.Min(s[2] - s[0], min);
s[1] = (W - x) * (H / 2);
s[2] = H * W - s[0] - s[1];
Array.Sort(s);
min = Math.Min(s[2] - s[0], min);
}
var tmp = H;
H = W;
W = tmp;
}
Console.WriteLine(min);
}
long H, W;
public Sol() {
var d = rla();
H = d[0];
W = d[1];
}
static String rs() { return Console.ReadLine(); }
static int ri() { return int.Parse(Console.ReadLine()); }
static long rl() { return long.Parse(Console.ReadLine()); }
static double rd() { return double.Parse(Console.ReadLine()); }
static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
static int[] ria(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e));
}
static long[] rla(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e));
}
static double[] rda(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep),
e => double.Parse(e));
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST {
static void Main() {
Sol mySol = new Sol();
mySol.Solve();
}
}
class Sol {
public void Solve() {
long min = (long)1e18;
for (int t = 0; t < 2; t++) {
for (long x = 1; x <= H; x++) {
long[] s = new long[3];
s[0] = x * W;
s[1] = (H - x) * (W / 2);
s[2] = H * W - s[0] - s[1];
Array.Sort(s);
min = Math.Min(s[2] - s[0], min);
s[0] = x * W;
s[1] = ((H - x) / 2) * W;
s[2] = H * W - s[0] - s[1];
Array.Sort(s);
min = Math.Min(s[2] - s[0], min);
}
var tmp = H;
H = W;
W = tmp;
}
Console.WriteLine(min);
}
long H, W;
public Sol() {
var d = rla();
H = d[0];
W = d[1];
}
static String rs() { return Console.ReadLine(); }
static int ri() { return int.Parse(Console.ReadLine()); }
static long rl() { return long.Parse(Console.ReadLine()); }
static double rd() { return double.Parse(Console.ReadLine()); }
static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
static int[] ria(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e));
}
static long[] rla(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e));
}
static double[] rda(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep),
e => double.Parse(e));
}
}
|
[["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 12, 16, 31, 23, 0, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 31, 23, 0, 16, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["-", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["-", 0, 11, 12, 16, 12, 23, 0, 16, 31, 22]]
| 8
| 518
| 17
|
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
static class P {
static void Main() {
int n = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(long.Parse).ToArray();
List<long> first = new List<long>();
PriorityQueue<long> pqueue = new PriorityQueue<long>(false);
long sum = 0;
for (int i = 0; i < n; i++) {
pqueue.Push(a[i]);
sum += a[i];
}
first.Add(sum);
for (int i = n; i < n * 2; i++) {
pqueue.Push(a[i]);
sum -= pqueue.Pop();
sum += a[i];
first.Add(sum);
}
List<long> last = new List<long>();
pqueue = new PriorityQueue<long>(true);
sum = 0;
for (int i = n * 3 - 1; i >= n * 2; i--) {
pqueue.Push(a[i]);
sum += a[i];
}
last.Add(sum);
for (int i = n * 2 - 1; i >= n; i--) {
pqueue.Push(a[i]);
sum -= pqueue.Pop();
sum += a[i];
last.Add(sum);
}
last.Reverse();
Console.WriteLine(first.Zip(last, (x, y) => x - y).Max());
}
}
class PriorityQueue<T>
where T : IComparable<T> {
public int Count { get; private set; }
private bool DoReverse;
T[] data;
public PriorityQueue(bool doReverse = false) {
data = new T[65536];
DoReverse = doReverse;
}
public T Top {
get { return data[1]; }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)] public T Pop() {
var top = Top;
var elem = data[Count--];
int index = 1;
while (true) {
if (index * 2 + 1 > Count) {
if (index * 2 > Count)
break;
if (elem.CompareTo(data[index * 2]) > 0 ^ DoReverse) {
data[index] = data[index * 2];
index = index * 2;
} else
break;
} else {
var nextIndex =
data[index * 2].CompareTo(data[index * 2 + 1]) <= 0 ^ DoReverse
? index * 2
: index * 2 + 1;
if (elem.CompareTo(data[nextIndex]) > 0 ^ DoReverse) {
data[index] = data[nextIndex];
index = nextIndex;
} else
break;
}
}
data[index] = elem;
return top;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Push(T value) {
int index = ++Count;
if (data.Length == Count)
Extend(data.Length * 2);
while ((index >>= 1) != 0) {
if (data[index].CompareTo(value) > 0 ^ DoReverse)
data[index << 1] = data[index];
else
break;
}
data[index] = value;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void Extend(int newSize) {
T[] newDatas = new T[newSize];
data.CopyTo(newDatas, 0);
data = newDatas;
}
}
|
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
static class P {
static void Main() {
int n = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(long.Parse).ToArray();
List<long> first = new List<long>();
PriorityQueue<long> pqueue = new PriorityQueue<long>(false);
long sum = 0;
for (int i = 0; i < n; i++) {
pqueue.Push(a[i]);
sum += a[i];
}
first.Add(sum);
for (int i = n; i < n * 2; i++) {
pqueue.Push(a[i]);
sum -= pqueue.Pop();
sum += a[i];
first.Add(sum);
}
List<long> last = new List<long>();
pqueue = new PriorityQueue<long>(true);
sum = 0;
for (int i = n * 3 - 1; i >= n * 2; i--) {
pqueue.Push(a[i]);
sum += a[i];
}
last.Add(sum);
for (int i = n * 2 - 1; i >= n; i--) {
pqueue.Push(a[i]);
sum -= pqueue.Pop();
sum += a[i];
last.Add(sum);
}
last.Reverse();
Console.WriteLine(first.Zip(last, (x, y) => x - y).Max());
}
}
class PriorityQueue<T>
where T : IComparable<T> {
public int Count { get; private set; }
private bool DoReverse;
T[] data;
public PriorityQueue(bool doReverse = false) {
data = new T[65536];
DoReverse = doReverse;
}
public T Top {
get { return data[1]; }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)] public T Pop() {
var top = Top;
var elem = data[Count--];
int index = 1;
while (true) {
if (index * 2 + 1 > Count) {
if (index * 2 > Count)
break;
if (elem.CompareTo(data[index << 1]) > 0 ^ DoReverse)
data[index] = data[index <<= 1];
else
break;
} else {
var nextIndex =
data[index * 2].CompareTo(data[index * 2 + 1]) <= 0 ^ DoReverse
? index * 2
: index * 2 + 1;
if (elem.CompareTo(data[nextIndex]) > 0 ^ DoReverse) {
data[index] = data[index = nextIndex];
} else
break;
}
}
data[index] = elem;
return top;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Push(T value) {
int index = ++Count;
if (data.Length == Count)
Extend(data.Length * 2);
while ((index >> 1) != 0) {
if (data[index >> 1].CompareTo(value) > 0 ^ DoReverse)
data[index] = data[index >>= 1];
else
break;
}
data[index] = value;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void Extend(int newSize) {
T[] newDatas = new T[newSize];
data.CopyTo(newDatas, 0);
data = newDatas;
}
}
|
[["-", 0, 204, 206, 207, 0, 28, 0, 16, 17, 48], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 151], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 48], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 206, 207, 0, 28, 0, 11, 0, 202, 0, 177], ["+", 12, 204, 206, 207, 0, 28, 0, 11, 12, 203], ["-", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["-", 75, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["-", 15, 16, 31, 23, 0, 11, 0, 202, 0, 176], ["+", 0, 52, 15, 16, 31, 23, 0, 16, 17, 152], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 17, 152], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 151], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 206, 207, 0, 28, 0, 11, 0, 202, 0, 176]]
| 8
| 797
| 28
|
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
static class P {
static void Main() {
int n = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(long.Parse).ToArray();
List<long> first = new List<long>();
PriorityQueue<long> pqueue = new PriorityQueue<long>(false);
long sum = 0;
for (int i = 0; i < n; i++) {
pqueue.Push(a[i]);
sum += a[i];
}
first.Add(sum);
for (int i = n; i < n * 2; i++) {
pqueue.Push(a[i]);
sum -= pqueue.Pop();
sum += a[i];
first.Add(sum);
}
List<long> last = new List<long>();
pqueue = new PriorityQueue<long>(true);
sum = 0;
for (int i = n * 3 - 1; i >= n * 2; i--) {
pqueue.Push(a[i]);
sum += a[i];
}
last.Add(sum);
for (int i = n * 2 - 1; i >= n; i--) {
pqueue.Push(a[i]);
sum -= pqueue.Pop();
sum += a[i];
last.Add(sum);
}
last.Reverse();
Console.WriteLine(first.Zip(last, (x, y) => x - y).Max());
}
}
class PriorityQueue<T>
where T : IComparable<T> {
public int Count { get; private set; }
private bool DoReverse;
T[] data;
public PriorityQueue(bool doReverse = false) {
data = new T[65536];
DoReverse = doReverse;
}
public T Top {
get { return data[1]; }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)] public T Pop() {
var top = Top;
var elem = data[Count--];
int index = 1;
while (true) {
if (index * 2 + 1 > Count) {
if (index * 2 > Count)
break;
if ((elem.CompareTo(data[index * 2]) > 0) ^ DoReverse) {
data[index] = data[index * 2];
index = index * 2;
} else
break;
} else {
var nextIndex =
data[index * 2].CompareTo(data[index * 2 + 1]) <= 0 ^ DoReverse
? index * 2
: index * 2 + 1;
if (elem.CompareTo(data[nextIndex]) > 0 ^ DoReverse) {
data[index] = data[nextIndex];
index = nextIndex;
} else
break;
}
}
data[index] = elem;
return top;
}
public void Push(T value) {
if (data.Length == Count)
Extend(data.Length * 2);
Count++;
int index = Count;
while ((index >> 1) != 0) {
if (data[index >> 1].CompareTo(value) > 0) {
data[index] = data[index >> 1];
index >>= 1;
} else
break;
}
data[index] = value;
}
private void Extend(int newSize) {
T[] newDatas = new T[newSize];
data.CopyTo(newDatas, 0);
data = newDatas;
}
}
|
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
static class P {
static void Main() {
int n = int.Parse(Console.ReadLine());
var a = Console.ReadLine().Split().Select(long.Parse).ToArray();
List<long> first = new List<long>();
PriorityQueue<long> pqueue = new PriorityQueue<long>(false);
long sum = 0;
for (int i = 0; i < n; i++) {
pqueue.Push(a[i]);
sum += a[i];
}
first.Add(sum);
for (int i = n; i < n * 2; i++) {
pqueue.Push(a[i]);
sum -= pqueue.Pop();
sum += a[i];
first.Add(sum);
}
List<long> last = new List<long>();
pqueue = new PriorityQueue<long>(true);
sum = 0;
for (int i = n * 3 - 1; i >= n * 2; i--) {
pqueue.Push(a[i]);
sum += a[i];
}
last.Add(sum);
for (int i = n * 2 - 1; i >= n; i--) {
pqueue.Push(a[i]);
sum -= pqueue.Pop();
sum += a[i];
last.Add(sum);
}
last.Reverse();
Console.WriteLine(first.Zip(last, (x, y) => x - y).Max());
}
}
class PriorityQueue<T>
where T : IComparable<T> {
public int Count { get; private set; }
private bool DoReverse;
T[] data;
public PriorityQueue(bool doReverse = false) {
data = new T[65536];
DoReverse = doReverse;
}
public T Top {
get { return data[1]; }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)] public T Pop() {
var top = Top;
var elem = data[Count--];
int index = 1;
while (true) {
if (index * 2 + 1 > Count) {
if (index * 2 > Count)
break;
if (elem.CompareTo(data[index * 2]) > 0 ^ DoReverse) {
data[index] = data[index * 2];
index = index * 2;
} else
break;
} else {
var nextIndex =
data[index * 2].CompareTo(data[index * 2 + 1]) <= 0 ^ DoReverse
? index * 2
: index * 2 + 1;
if (elem.CompareTo(data[nextIndex]) > 0 ^ DoReverse) {
data[index] = data[nextIndex];
index = nextIndex;
} else
break;
}
}
data[index] = elem;
return top;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Push(T value) {
int index = ++Count;
if (data.Length == Count)
Extend(data.Length * 2);
while ((index >> 1) != 0) {
if (data[index >> 1].CompareTo(value) > 0 ^ DoReverse) {
data[index] = data[index >>= 1];
} else
break;
}
data[index] = value;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void Extend(int newSize) {
T[] newDatas = new T[newSize];
data.CopyTo(newDatas, 0);
data = newDatas;
}
}
|
[["-", 64, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["-", 64, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 0, 235, 8, 201, 0, 195, 0, 318, 0, 70], ["+", 8, 201, 0, 195, 0, 318, 0, 319, 141, 22], ["+", 0, 195, 0, 318, 0, 319, 0, 320, 0, 24], ["+", 0, 319, 0, 320, 0, 321, 0, 214, 205, 22], ["+", 0, 319, 0, 320, 0, 321, 0, 214, 0, 131], ["+", 0, 319, 0, 320, 0, 321, 0, 214, 141, 22], ["+", 0, 195, 0, 318, 0, 319, 0, 320, 0, 25], ["+", 0, 235, 8, 201, 0, 195, 0, 318, 0, 73], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 29], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 195, 8, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 140], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 152], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73]]
| 8
| 791
| 40
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC061A {
class Program {
static void Main(string[] args) {
int a, b, c;
var word = Console.ReadLine().Split(' ');
a = int.Parse(word[0]);
b = int.Parse(word[1]);
c = int.Parse(word[2]);
if (a <= c && b >= c)
Console.WriteLine("yes");
else
Console.WriteLine("no");
Console.ReadLine();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC061A {
class Program {
static void Main(string[] args) {
int a, b, c;
var word = Console.ReadLine().Split(' ');
a = int.Parse(word[0]);
b = int.Parse(word[1]);
c = int.Parse(word[2]);
if (a <= c && c <= b) {
Console.WriteLine("Yes");
}
else {
Console.WriteLine("No");
}
Console.ReadLine();
}
}
}
|
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 140
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC061A {
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 C = int.Parse(word[2]);
if ((A <= C) && (C <= B))
Console.WriteLine("YES");
else
Console.WriteLine("NO");
Console.ReadKey();
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC061A {
class Program {
static void Main(string[] args) {
int A, B, C;
var word = Console.ReadLine().Split(' ');
A = int.Parse(word[0]);
B = int.Parse(word[1]);
C = int.Parse(word[2]);
if ((A <= C) && (B >= C))
Console.WriteLine("Yes");
else
Console.WriteLine("No");
Console.ReadKey();
}
}
}
|
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 0, 21], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 57, 15, 16, 12, 23, 0, 16, 31, 22], ["-", 0, 57, 15, 16, 12, 23, 0, 16, 17, 19], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 20], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 12, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
| 8
| 140
| 18
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
class _Class {
void _Do() {
//
var _s = _stringArray();
var R_ = int.Parse(_s[0]);
var G_ = int.Parse(_s[1]);
var B_ = int.Parse(_s[2]);
var c = R_ + 256 * G_ + 256 * 256 * B_;
if (R_ % 4 == 0)
Console.WriteLine("YES");
else
Console.WriteLine("NO");
}
static void Main(string[] args) { new _Class()._Do(); }
// 1
string[] _stringArray() { return Console.ReadLine().Split(); }
// 2.1 -2,147,483,648 ~ +2,147,483,647
int[] _intArray() {
var _s = Console.ReadLine().Split();
var x = new int[_s.Length];
for (var i = 0; i < _s.Length; i++)
x[i] = int.Parse(_s[i]);
return x;
}
// 2.2 -9,223,372,036,854,775,808 ~ +9,223,372,036,854,775,807
long[] _longArray() {
var _s = Console.ReadLine().Split();
var x = new long[_s.Length];
for (var i = 0; i < _s.Length; i++)
x[i] = long.Parse(_s[i]);
return x;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
class _Class {
void _Do() {
//
var _s = _stringArray();
var R_ = int.Parse(_s[0]);
var G_ = int.Parse(_s[1]);
var B_ = int.Parse(_s[2]);
var c = B_ + 10 * G_ + 10 * 10 * R_;
if (c % 4 == 0)
Console.WriteLine("YES");
else
Console.WriteLine("NO");
}
static void Main(string[] args) { new _Class()._Do(); }
// 1
string[] _stringArray() { return Console.ReadLine().Split(); }
// 2.1 -2,147,483,648 ~ +2,147,483,647
int[] _intArray() {
var _s = Console.ReadLine().Split();
var x = new int[_s.Length];
for (var i = 0; i < _s.Length; i++)
x[i] = int.Parse(_s[i]);
return x;
}
// 2.2 -9,223,372,036,854,775,808 ~ +9,223,372,036,854,775,807
long[] _longArray() {
var _s = Console.ReadLine().Split();
var x = new long[_s.Length];
for (var i = 0; i < _s.Length; i++)
x[i] = long.Parse(_s[i]);
return x;
}
}
|
[["-", 0, 200, 0, 212, 0, 16, 31, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 31, 22], ["-", 0, 212, 0, 16, 31, 16, 12, 16, 31, 203], ["+", 0, 212, 0, 16, 31, 16, 12, 16, 31, 203], ["-", 0, 212, 0, 16, 12, 16, 31, 16, 31, 203], ["+", 0, 212, 0, 16, 12, 16, 31, 16, 31, 203], ["-", 0, 212, 0, 16, 12, 16, 31, 16, 12, 203], ["+", 0, 212, 0, 16, 12, 16, 31, 16, 12, 203], ["-", 0, 200, 0, 212, 0, 16, 12, 16, 12, 22], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 12, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22]]
| 8
| 303
| 12
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace AtCoder {
class MainClass {
int A, B, C;
void Solve() {
io.i(out A, out B, out C);
bool ans = A <= C && C <= B;
io.yn(ans);
}
int ManhattanDis(int x1, int y1, int x2, int y2) {
return Math.Abs(x1 - x2) + Math.Abs(y1 - y2);
}
public static void Main(string[] args) { new MainClass().Stream(); }
IO io = new IO();
void Stream() {
Solve();
io.writeFlush();
}
class IO {
string[] nextBuffer;
int BufferCnt;
char[] cs = new char[] { ' ' };
StreamWriter sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
public IO() {
nextBuffer = new string[0];
BufferCnt = 0;
Console.SetOut(sw);
}
public string next() {
if (BufferCnt < nextBuffer.Length)
return nextBuffer[BufferCnt++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
BufferCnt = 0;
return nextBuffer[BufferCnt++];
}
public char nextChar() { return char.Parse(next()); }
public int nextInt() { return int.Parse(next()); }
public long nextLong() { return long.Parse(next()); }
public double nextDouble() { return double.Parse(next()); }
public string[] array() { return Console.ReadLine().Split(' '); }
public char[] arrayChar() { return Array.ConvertAll(array(), char.Parse); }
public int[] arrayInt() { return Array.ConvertAll(array(), int.Parse); }
public long[] arrayLong() { return Array.ConvertAll(array(), long.Parse); }
public double[] arrayDouble() {
return Array.ConvertAll(array(), double.Parse);
}
private bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); }
private T convertType<T, U>(U v) {
return (T)Convert.ChangeType(v, typeof(T));
}
private T suitType<T>(string s) {
if (typeEQ<T, int>())
return convertType<T, int>(int.Parse(s));
if (typeEQ<T, long>())
return convertType<T, long>(long.Parse(s));
if (typeEQ<T, double>())
return convertType<T, double>(double.Parse(s));
if (typeEQ<T, char>())
return convertType<T, char>(char.Parse(s));
return convertType<T, string>(s);
}
public void i<T>(out T v) { v = suitType<T>(next()); }
public void i<T, U>(out T v1, out U v2) {
var a = array();
v1 = suitType<T>(a[0]);
v2 = suitType<U>(a[1]);
}
public void i<T, U, V>(out T v1, out U v2, out V v3) {
var a = array();
v1 = suitType<T>(a[0]);
v2 = suitType<U>(a[1]);
v3 = suitType<V>(a[2]);
}
public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) {
var a = array();
v1 = suitType<T>(a[0]);
v2 = suitType<U>(a[1]);
v3 = suitType<V>(a[2]);
v4 = suitType<W>(a[3]);
}
public void o<T>(T v) { Console.WriteLine(v); }
public void o<T>(params T[] a) {
foreach (T v in a)
Console.WriteLine(v);
}
public void o<T>(List<T> l) {
foreach (T v in l)
sw.WriteLine(v);
}
public void yn(bool f) { Console.WriteLine(f ? "YES" : "NO"); }
public void writeFlush() { Console.Out.Flush(); }
}
class Mathf {
public int mod = 1000000007; // 10^9+7
public long Pow(long a, long b) {
if (b == 0)
return 1;
if (b % 2 == 1)
return (a % mod * Pow(a % mod, b - 1) % mod) % mod;
else
return Pow(a * a % mod, b / 2) % mod;
}
public long Fact(long n) {
return n != 0 ? (n % mod * (Fact(n - 1) % mod) % mod) : 1;
}
public long C(long n, long r) {
if (r == 0 || n == r)
return 1;
else
return (Fact(n) % mod *
Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) %
mod;
}
public long Sum(params long[] a) {
return a.Aggregate((v, next) => (v % mod + next) % mod);
}
public int GCD(int a, int b) {
if (a < b)
Swap(ref a, ref b);
return b == 0 ? a : GCD(b, a % b);
}
public int GCD(int[] array) {
return array.Aggregate((v, next) => GCD(v, next));
}
public void Swap<T>(ref T a, ref T b) {
T tmp = a;
a = b;
b = tmp;
}
public T Max<T>(params T[] v) { return v.Max(); }
public T Min<T>(params T[] v) { return v.Min(); }
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace AtCoder {
class MainClass {
int A, B, C;
void Solve() {
io.i(out A, out B, out C);
bool ans = A <= C && C <= B;
io.yn(ans);
}
int ManhattanDis(int x1, int y1, int x2, int y2) {
return Math.Abs(x1 - x2) + Math.Abs(y1 - y2);
}
public static void Main(string[] args) { new MainClass().Stream(); }
IO io = new IO();
void Stream() {
Solve();
io.writeFlush();
}
class IO {
string[] nextBuffer;
int BufferCnt;
char[] cs = new char[] { ' ' };
StreamWriter sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
public IO() {
nextBuffer = new string[0];
BufferCnt = 0;
Console.SetOut(sw);
}
public string next() {
if (BufferCnt < nextBuffer.Length)
return nextBuffer[BufferCnt++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
BufferCnt = 0;
return nextBuffer[BufferCnt++];
}
public char nextChar() { return char.Parse(next()); }
public int nextInt() { return int.Parse(next()); }
public long nextLong() { return long.Parse(next()); }
public double nextDouble() { return double.Parse(next()); }
public string[] array() { return Console.ReadLine().Split(' '); }
public char[] arrayChar() { return Array.ConvertAll(array(), char.Parse); }
public int[] arrayInt() { return Array.ConvertAll(array(), int.Parse); }
public long[] arrayLong() { return Array.ConvertAll(array(), long.Parse); }
public double[] arrayDouble() {
return Array.ConvertAll(array(), double.Parse);
}
private bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); }
private T convertType<T, U>(U v) {
return (T)Convert.ChangeType(v, typeof(T));
}
private T suitType<T>(string s) {
if (typeEQ<T, int>())
return convertType<T, int>(int.Parse(s));
if (typeEQ<T, long>())
return convertType<T, long>(long.Parse(s));
if (typeEQ<T, double>())
return convertType<T, double>(double.Parse(s));
if (typeEQ<T, char>())
return convertType<T, char>(char.Parse(s));
return convertType<T, string>(s);
}
public void i<T>(out T v) { v = suitType<T>(next()); }
public void i<T, U>(out T v1, out U v2) {
var a = array();
v1 = suitType<T>(a[0]);
v2 = suitType<U>(a[1]);
}
public void i<T, U, V>(out T v1, out U v2, out V v3) {
var a = array();
v1 = suitType<T>(a[0]);
v2 = suitType<U>(a[1]);
v3 = suitType<V>(a[2]);
}
public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) {
var a = array();
v1 = suitType<T>(a[0]);
v2 = suitType<U>(a[1]);
v3 = suitType<V>(a[2]);
v4 = suitType<W>(a[3]);
}
public void o<T>(T v) { Console.WriteLine(v); }
public void o<T>(params T[] a) {
foreach (T v in a)
Console.WriteLine(v);
}
public void o<T>(List<T> l) {
foreach (T v in l)
sw.WriteLine(v);
}
public void YN(bool f) { Console.WriteLine(f ? "YES" : "NO"); }
public void yn(bool f) { Console.WriteLine(f ? "Yes" : "No"); }
public void writeFlush() { Console.Out.Flush(); }
}
class Mathf {
public int mod = 1000000007; // 10^9+7
public long Pow(long a, long b) {
if (b == 0)
return 1;
if (b % 2 == 1)
return (a % mod * Pow(a % mod, b - 1) % mod) % mod;
else
return Pow(a * a % mod, b / 2) % mod;
}
public long Fact(long n) {
return n != 0 ? (n % mod * (Fact(n - 1) % mod) % mod) : 1;
}
public long C(long n, long r) {
if (r == 0 || n == r)
return 1;
else
return (Fact(n) % mod *
Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) %
mod;
}
public long Sum(params long[] a) {
return a.Aggregate((v, next) => (v % mod + next) % mod);
}
public int GCD(int a, int b) {
if (a < b)
Swap(ref a, ref b);
return b == 0 ? a : GCD(b, a % b);
}
public int GCD(int[] array) {
return array.Aggregate((v, next) => GCD(v, next));
}
public void Swap<T>(ref T a, ref T b) {
T tmp = a;
a = b;
b = tmp;
}
public T Max<T>(params T[] v) { return v.Max(); }
public T Min<T>(params T[] v) { return v.Min(); }
}
}
}
|
[["-", 8, 201, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 62], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 46], ["+", 0, 235, 8, 201, 0, 195, 0, 251, 0, 259], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 24], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 25], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 45], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 15, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
| 8
| 1,395
| 26
|
using System;
class Atcoder {
public static int[] cins() {
string[] ss = Console.ReadLine().Split(' ');
int[] Res = new int[ss.Length];
for (int i = 0; i < ss.Length; i++) {
Res[i] = int.Parse(ss[i]);
}
return Res;
}
public static void O(bool b) { Console.WriteLine(b ? "YES" : "NO"); }
public static void Main(string[] args) {
int[] k = cins();
O(k[2] >= k[0] && k[2] <= k[1]);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Atcoder {
public static int[] cins() {
string[] ss = Console.ReadLine().Split(' ');
int[] Res = new int[ss.Length];
for (int i = 0; i < ss.Length; i++) {
Res[i] = int.Parse(ss[i]);
}
return Res;
}
public static void O(bool b) { Console.WriteLine(b ? "Yes" : "No"); }
public static void Main(string[] args) {
int[] k = cins();
O(k[2] >= k[0] && k[2] <= k[1]);
}
}
|
[["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["+", 0, 208, 0, 231, 141, 232, 234, 232, 234, 22], ["+", 0, 208, 0, 231, 141, 232, 234, 232, 0, 131], ["+", 0, 208, 0, 231, 141, 232, 234, 232, 141, 22], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["-", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
| 8
| 153
| 16
|
// Rextester.Program.Main is the entry point for your code. Don't change it.
// Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Rextester {
public class Program {
public static void Main(string[] args) {
// Your code goes here
var input = Console.ReadLine().Split();
int A = int.Parse(input[0]);
int B = int.Parse(input[1]);
int C = int.Parse(input[2]);
A = Math.Abs(A);
B = Math.Abs(B);
C = Math.Abs(C);
if (C >= A && C <= B) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
// Rextester.Program.Main is the entry point for your code. Don't change it.
// Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Rextester {
public class Program {
public static void Main(string[] args) {
// Your code goes here
var input = Console.ReadLine().Split();
int A = int.Parse(input[0]);
int B = int.Parse(input[1]);
int C = int.Parse(input[2]);
if (C >= A && C <= B) {
Console.WriteLine("Yes");
} else {
Console.WriteLine("No");
}
}
}
}
|
[["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 158
| 27
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class _062A {
static void Main() {
var arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
var toshi = arr[0];
var miti = arr[1];
int[] ans = new int[toshi];
int[] point = new int[1];
for (var i = 1; i <= miti; i++) {
point = Console.ReadLine().Split().Select(int.Parse).ToArray();
ans[point[0] - 1]++;
ans[point[1] - 1]++;
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class _062A {
static void Main() {
var arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
var toshi = arr[0];
var miti = arr[1];
int[] ans = new int[toshi];
int[] point = new int[1];
for (var i = 1; i <= miti; i++) {
point = Console.ReadLine().Split().Select(int.Parse).ToArray();
ans[point[0] - 1]++;
ans[point[1] - 1]++;
}
foreach (var x in ans)
Console.WriteLine(x);
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 266], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 24], ["+", 0, 195, 8, 196, 0, 210, 39, 216, 0, 217], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 31, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 267], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 25], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
| 8
| 161
| 9
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main() {
string input = Console.ReadLine();
int city_count = int.Parse(input.Split(' ')[0]);
List<int> citys = new List<int>();
for (int i = 0; i < city_count; i++) {
input = Console.ReadLine();
citys.Add(int.Parse(input.Split(' ')[0]));
citys.Add(int.Parse(input.Split(' ')[1]));
}
for (int i = 1; i <= city_count; i++) {
Console.WriteLine(citys.Where(n => n == i).Count());
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main() {
string input = Console.ReadLine();
int city_count = int.Parse(input.Split(' ')[0]);
int road_count = int.Parse(input.Split(' ')[1]);
List<int> citys = new List<int>();
for (int i = 0; i < road_count; i++) {
input = Console.ReadLine();
citys.Add(int.Parse(input.Split(' ')[0]));
citys.Add(int.Parse(input.Split(' ')[1]));
}
for (int i = 1; i <= city_count; i++) {
Console.WriteLine(citys.Where(n => n == i).Count());
}
}
}
|
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 204, 205, 213, 63, 214, 205, 22], ["+", 0, 28, 0, 204, 205, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 204, 205, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 204, 205, 213, 3, 4, 0, 24], ["+", 205, 213, 3, 4, 0, 28, 0, 252, 0, 104], ["+", 205, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["+", 0, 28, 0, 204, 205, 213, 3, 4, 0, 25], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
| 8
| 173
| 22
|
using System;
namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
string[] str0 = Console.ReadLine().Split(' ');
int N = int.Parse(str0[0]);
int M = int.Parse(str0[1]);
int[] arrA = new int[50];
int[] arrB = new int[50];
int[] arrReault = new int[N];
int count = 0;
while (true) {
string[] str = Console.ReadLine().Split(' ');
if (str.Length < 2)
break;
int a = int.Parse(str[0]);
int b = int.Parse(str[1]);
arrA[count] = a;
arrB[count] = b;
count += 1;
}
for (int i = 0; i < count; i++) {
arrReault[arrA[i] - 1] += 1;
arrReault[arrB[i] - 1] += 1;
}
for (int i = 0; i < N; i++) {
Console.WriteLine(arrReault[i]);
}
Console.ReadKey();
}
}
}
|
using System;
namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
string[] str0 = Console.ReadLine().Split(' ');
int N = int.Parse(str0[0]);
int M = int.Parse(str0[1]);
int[] arrA = new int[M];
int[] arrB = new int[M];
int[] arrReault = new int[N];
for (int i = 0; i < M; i++) {
string[] str = Console.ReadLine().Split(' ');
int a = int.Parse(str[0]);
int b = int.Parse(str[1]);
arrA[i] = a;
arrB[i] = b;
}
for (int i = 0; i < M; i++) {
arrReault[arrA[i] - 1] += 1;
arrReault[arrB[i] - 1] += 1;
}
for (int i = 0; i < N; i++) {
Console.WriteLine(arrReault[i]);
}
Console.ReadKey();
}
}
}
|
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 52, 0, 89], ["-", 8, 201, 0, 195, 8, 196, 0, 52, 0, 24], ["-", 0, 195, 8, 196, 0, 52, 15, 211, 0, 146], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 214, 205, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["-", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 25], ["-", 0, 52, 8, 196, 0, 57, 64, 93, 0, 94], ["-", 0, 52, 8, 196, 0, 57, 64, 93, 0, 35], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
| 8
| 254
| 37
|
using System;
using System.Collections.Generic;
using System.Linq;
class MainClass {
static void Main() {
var NK = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = NK[0], K = NK[1];
var ab = new int [N][];
for (int i = 0; i < N; i++) {
ab[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
}
Array.Sort(ab, (x, y) => x[0].CompareTo(y[0]));
int index = 0;
int num = -1;
for (int i = 0; i < ab.Length; i++) {
num = ab[i][0];
index += ab[i][1];
if (index >= K)
break;
}
Console.WriteLine(num);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class MainClass {
static void Main() {
var NK = Console.ReadLine().Split().Select(long.Parse).ToArray();
int N = (int)NK[0];
long K = NK[1];
var ab = new long [N][];
for (int i = 0; i < N; i++) {
ab[i] = Console.ReadLine().Split().Select(long.Parse).ToArray();
}
Array.Sort(ab, (x, y) => x[0].CompareTo(y[0]));
long index = 0;
int num = -1;
for (int i = 0; i < ab.Length; i++) {
num = (int)ab[i][0];
index += ab[i][1];
if (index >= K)
break;
}
Console.WriteLine(num);
}
}
|
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 0, 21], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 212, 0, 227, 39, 224, 39, 224, 39, 199], ["+", 0, 212, 0, 227, 39, 224, 39, 224, 39, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 0, 24], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 0, 25]]
| 8
| 208
| 17
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace C {
public class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
var NK = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
var (N, K) = (NK[0], NK[1]);
var dict = new Dictionary<int, long>();
for (var i = 0; i < N; i++) {
var ab = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
var (a, b) = (ab[0], ab[1]);
if (dict.ContainsKey(a))
dict[a] += b;
else
dict[a] = b;
}
var count = 0L;
foreach (var val in dict.Keys.OrderBy(x => x)) {
count += dict[val];
if (count >= K) {
Console.WriteLine(val);
return;
}
}
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace C {
public class Program {
static void Main(string[] args) {
var sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
public static void Solve() {
var NK = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
var (N, K) = (NK[0], NK[1]);
var dict = new Dictionary<long, long>();
for (var i = 0; i < N; i++) {
var ab =
Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
var (a, b) = (ab[0], ab[1]);
if (dict.ContainsKey(a))
dict[a] += b;
else
dict[a] = b;
}
var count = 0L;
foreach (var val in dict.Keys.OrderBy(x => x).ToArray()) {
count += dict[val];
if (count >= K) {
Console.WriteLine(val);
return;
}
}
}
}
}
|
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 12, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 210, 12, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 210, 12, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 210, 12, 213, 3, 4, 0, 24]]
| 8
| 290
| 10
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;
namespace Program {
public static class ProblemA {
static bool SAIKI = false;
static public int numberOfRandomCases = 0;
static public void MakeTestCase(List<string> _input, List<string> _output,
ref Func<string[], bool> _outputChecker) {}
static public void Solve() {
var N = NN;
var K = NN;
var abList = Repeat(0, N).Select(_ => new { a = NN, b = NN }).ToArray();
foreach (var item in abList) {
K -= item.b;
if (K <= 0) {
Console.WriteLine(item.a);
return;
}
}
}
class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream)
: base(stream, new UTF8Encoding(false, true)) {
base.AutoFlush = false;
}
public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {
base.AutoFlush = false;
}
}
static LIB_FastIO fastio = new LIB_FastIODebug();
static public void Main(string[] args) {
if (args.Length == 0) {
fastio = new LIB_FastIO();
Console.SetOut(new Printer(Console.OpenStandardOutput()));
}
if (SAIKI) {
var t = new Thread(Solve, 134217728);
t.Start();
t.Join();
} else
Solve();
Console.Out.Flush();
}
static long NN => fastio.Long();
static double ND => fastio.Double();
static string NS => fastio.Scan();
static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
static long Count<T>(this IEnumerable<T> x,
Func<T, bool> pred) => Enumerable.Count(x, pred);
static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v,
(int)n);
static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s,
(int)c);
static IOrderedEnumerable<T>
OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift);
static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) =>
Enumerable.OrderBy(x.OrderByRand(), e => e);
static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x,
Func<T1, T2> selector) =>
Enumerable.OrderBy(x.OrderByRand(), selector);
static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) =>
Enumerable.OrderByDescending(x.OrderByRand(), e => e);
static IOrderedEnumerable<T1>
OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) =>
Enumerable.OrderByDescending(x.OrderByRand(), selector);
static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) =>
x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase);
static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x,
Func<T, string> selector) =>
x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase);
static IOrderedEnumerable<string>
OrderByDescending(this IEnumerable<string> x) =>
x.OrderByRand().OrderByDescending(e => e,
StringComparer.OrdinalIgnoreCase);
static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x,
Func<T, string> selector) =>
x.OrderByRand().OrderByDescending(selector,
StringComparer.OrdinalIgnoreCase);
static uint xorshift {
get {
_xsi.MoveNext();
return _xsi.Current;
}
}
static IEnumerator<uint> _xsi = _xsc();
static IEnumerator<uint> _xsc() {
uint x = 123456789, y = 362436069, z = 521288629,
w = (uint)(DateTime.Now.Ticks & 0xffffffff);
while (true) {
var t = x ^ (x << 11);
x = y;
y = z;
z = w;
w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
yield return w;
}
}
}
}
namespace Library {
class LIB_FastIO {
public LIB_FastIO() { str = Console.OpenStandardInput(); }
readonly Stream str;
readonly byte[] buf = new byte[1024];
int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
virtual public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
virtual public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
virtual public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
class LIB_FastIODebug : LIB_FastIO {
Queue<string> param = new Queue<string>();
string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
public LIB_FastIODebug() {}
public override string Scan() => NextString();
public override long Long() => long.Parse(NextString());
public override double Double() => double.Parse(NextString());
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;
namespace Program {
public static class ProblemA {
static bool SAIKI = false;
static public int numberOfRandomCases = 0;
static public void MakeTestCase(List<string> _input, List<string> _output,
ref Func<string[], bool> _outputChecker) {}
static public void Solve() {
var N = NN;
var K = NN;
var abList = Repeat(0, N).Select(_ => new { a = NN, b = NN }).ToArray();
foreach (var item in abList.OrderBy(e => e.a)) {
K -= item.b;
if (K <= 0) {
Console.WriteLine(item.a);
return;
}
}
}
class Printer : StreamWriter {
public override IFormatProvider FormatProvider {
get { return CultureInfo.InvariantCulture; }
}
public Printer(Stream stream)
: base(stream, new UTF8Encoding(false, true)) {
base.AutoFlush = false;
}
public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {
base.AutoFlush = false;
}
}
static LIB_FastIO fastio = new LIB_FastIODebug();
static public void Main(string[] args) {
if (args.Length == 0) {
fastio = new LIB_FastIO();
Console.SetOut(new Printer(Console.OpenStandardOutput()));
}
if (SAIKI) {
var t = new Thread(Solve, 134217728);
t.Start();
t.Join();
} else
Solve();
Console.Out.Flush();
}
static long NN => fastio.Long();
static double ND => fastio.Double();
static string NS => fastio.Scan();
static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
static long Count<T>(this IEnumerable<T> x,
Func<T, bool> pred) => Enumerable.Count(x, pred);
static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v,
(int)n);
static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s,
(int)c);
static IOrderedEnumerable<T>
OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift);
static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) =>
Enumerable.OrderBy(x.OrderByRand(), e => e);
static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x,
Func<T1, T2> selector) =>
Enumerable.OrderBy(x.OrderByRand(), selector);
static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) =>
Enumerable.OrderByDescending(x.OrderByRand(), e => e);
static IOrderedEnumerable<T1>
OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) =>
Enumerable.OrderByDescending(x.OrderByRand(), selector);
static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) =>
x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase);
static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x,
Func<T, string> selector) =>
x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase);
static IOrderedEnumerable<string>
OrderByDescending(this IEnumerable<string> x) =>
x.OrderByRand().OrderByDescending(e => e,
StringComparer.OrdinalIgnoreCase);
static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x,
Func<T, string> selector) =>
x.OrderByRand().OrderByDescending(selector,
StringComparer.OrdinalIgnoreCase);
static uint xorshift {
get {
_xsi.MoveNext();
return _xsi.Current;
}
}
static IEnumerator<uint> _xsi = _xsc();
static IEnumerator<uint> _xsc() {
uint x = 123456789, y = 362436069, z = 521288629,
w = (uint)(DateTime.Now.Ticks & 0xffffffff);
while (true) {
var t = x ^ (x << 11);
x = y;
y = z;
z = w;
w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
yield return w;
}
}
}
}
namespace Library {
class LIB_FastIO {
public LIB_FastIO() { str = Console.OpenStandardInput(); }
readonly Stream str;
readonly byte[] buf = new byte[1024];
int len, ptr;
public bool isEof = false;
public bool IsEndOfStream {
get { return isEof; }
}
byte read() {
if (isEof)
throw new EndOfStreamException();
if (ptr >= len) {
ptr = 0;
if ((len = str.Read(buf, 0, 1024)) <= 0) {
isEof = true;
return 0;
}
}
return buf[ptr++];
}
char Char() {
byte b = 0;
do
b = read();
while (b < 33 || 126 < b);
return (char)b;
}
virtual public string Scan() {
var sb = new StringBuilder();
for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
sb.Append(b);
return sb.ToString();
}
virtual public long Long() {
long ret = 0;
byte b = 0;
var ng = false;
do
b = read();
while (b != '-' && (b < '0' || '9' < b));
if (b == '-') {
ng = true;
b = read();
}
for (; true; b = read()) {
if (b < '0' || '9' < b)
return ng ? -ret : ret;
else
ret = ret * 10 + b - '0';
}
}
virtual public double Double() {
return double.Parse(Scan(), CultureInfo.InvariantCulture);
}
}
class LIB_FastIODebug : LIB_FastIO {
Queue<string> param = new Queue<string>();
string NextString() {
if (param.Count == 0)
foreach (var item in Console.ReadLine().Split(' '))
param.Enqueue(item);
return param.Dequeue();
}
public LIB_FastIODebug() {}
public override string Scan() => NextString();
public override long Long() => long.Parse(NextString());
public override double Double() => double.Parse(NextString());
}
}
|
[["+", 8, 196, 0, 210, 12, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 210, 12, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 210, 12, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 25]]
| 8
| 1,477
| 9
|
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
class Solve {
const int mod = 1000000007;
static void Main(string[] args) {
var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = input[0];
int K = input[1];
List<Tuple<int, int>> ab = new List<Tuple<int, int>>();
for (var i = 0; i < N; i++) {
var p = Console.ReadLine().Split().Select(int.Parse).ToArray();
ab.Add(new Tuple<int, int>(p[0], p[1]));
}
ab.Sort();
long ans = 0;
long sum = 0;
for (var i = 0; i < N; i++) {
sum += ab[i].Item2;
if (sum >= K) {
ans = ab[i].Item1;
break;
}
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
class Solve {
const int mod = 1000000007;
static void Main(string[] args) {
var input = Console.ReadLine().Split().Select(long.Parse).ToArray();
int N = (int)input[0];
long K = input[1];
List<Tuple<long, long>> ab = new List<Tuple<long, long>>();
for (var i = 0; i < N; i++) {
var p = Console.ReadLine().Split().Select(long.Parse).ToArray();
ab.Add(new Tuple<long, long>(p[0], p[1]));
}
ab.Sort();
long ans = 0;
long sum = 0;
for (var i = 0; i < N; i++) {
sum += ab[i].Item2;
if (sum >= K) {
ans = ab[i].Item1;
break;
}
}
Console.WriteLine(ans);
}
}
|
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 39, 236, 237, 238, 0, 236, 237, 238, 0, 199], ["+", 39, 236, 237, 238, 0, 236, 237, 238, 0, 199], ["-", 0, 28, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 28, 0, 230, 39, 236, 237, 238, 0, 199]]
| 8
| 248
| 21
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var N = sc.ReadInt();
var K = sc.ReadLong();
var counts = new int[(int)1e5 + 1];
var array = new int[N];
for (int i = 0; i < N; i++) {
var a = sc.ReadInt();
var b = sc.ReadInt();
array[i] = a;
counts[a] += b;
}
Array.Sort(array);
long c = 0;
var ans = 0;
for (int i = 0; i < N; i++) {
c += counts[array[i]];
if (c >= K) {
ans = array[i];
break;
}
}
Console.WriteLine(ans);
}
static int MOD = (int)1e9 + 7;
static int INF = (int)1e7 + 1;
static long LINF = (long)1e13 + 1;
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 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;
}
}
class Debug {
public static void Dump<T>(T[,] array) {
#if !DEBUG
return;
#endif
Console.WriteLine();
var h = array.GetLength(0);
var w = array.GetLength(1);
for (int r = 0; r < h; r++) {
for (int c = 0; c < w; c++) {
Console.Write(array[r, c]);
Console.Write(" ");
}
Console.WriteLine();
}
Console.WriteLine();
}
public static void Dump<T>(T[] array) {
#if !DEBUG
return;
#endif
Console.WriteLine();
Console.WriteLine(string.Join(" ", array));
Console.WriteLine();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var N = sc.ReadInt();
var K = sc.ReadLong();
var counts = new long[(int)1e5 + 1];
for (int i = 0; i < N; i++) {
var a = sc.ReadInt();
var b = sc.ReadInt();
counts[a] += b;
}
var ans = 0;
long sum = 0;
for (int i = 1; i < counts.Length; i++) {
sum += counts[i];
if (sum >= K) {
ans = i;
break;
}
}
Console.WriteLine(ans);
}
static int MOD = (int)1e9 + 7;
static int INF = (int)1e7 + 1;
static long LINF = (long)1e13 + 1;
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 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;
}
}
class Debug {
public static void Dump<T>(T[,] array) {
#if !DEBUG
return;
#endif
Console.WriteLine();
var h = array.GetLength(0);
var w = array.GetLength(1);
for (int r = 0; r < h; r++) {
for (int c = 0; c < w; c++) {
Console.Write(array[r, c]);
Console.Write(" ");
}
Console.WriteLine();
}
Console.WriteLine();
}
public static void Dump<T>(T[] array) {
#if !DEBUG
return;
#endif
Console.WriteLine();
Console.WriteLine(string.Join(" ", array));
Console.WriteLine();
}
}
|
[["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 73], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 227, 0, 228], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 70], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 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], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 12, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["-", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70]]
| 8
| 902
| 49
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
int N = int.Parse(input[0]);
int K = int.Parse(input[1]);
Dictionary<int, int> num = new Dictionary<int, int>();
for (int i = 0; i < N; i++) {
string[] input_num = Console.ReadLine().Split(' ');
int a = int.Parse(input_num[0]);
int b = int.Parse(input_num[1]);
if (num.ContainsKey(a)) {
num[a] += b;
} else {
num.Add(a, b);
}
}
int ans = 0;
int sum = 0;
foreach (KeyValuePair<int, int> item in num.OrderBy(x => x.Key)) {
sum += item.Value;
if (sum >= K) {
ans = item.Key;
break;
}
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder {
class Program {
static void Main(string[] args) {
string[] input = Console.ReadLine().Split(' ');
long N = long.Parse(input[0]);
long K = long.Parse(input[1]);
Dictionary<long, long> num = new Dictionary<long, long>();
for (long i = 0; i < N; i++) {
string[] input_num = Console.ReadLine().Split(' ');
long a = long.Parse(input_num[0]);
long b = long.Parse(input_num[1]);
if (num.ContainsKey(a)) {
num[a] += b;
} else {
num.Add(a, b);
}
}
long ans = 0;
long sum = 0;
foreach (KeyValuePair<long, long> item in num.OrderBy(x => x.Key)) {
sum += item.Value;
if (sum >= K) {
ans = item.Key;
break;
}
}
Console.WriteLine(ans);
}
}
}
|
[["-", 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], ["-", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 210, 39, 236, 237, 238, 0, 199], ["+", 8, 196, 0, 210, 39, 236, 237, 238, 0, 199]]
| 8
| 248
| 34
|
using System;
using System.Linq;
namespace AtCoder {
class Program {
public static void Main() {
int[] input = new int[2];
input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
int n = input[0];
long k = input[1];
int[] a = new int[n];
int[] b = new int[n];
for (int i = 0; i < n; i++) {
input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
a[i] = input[0];
b[i] = input[1];
}
Array.Sort(a, b);
int j = 0;
long c = 0;
while (c + b[j] < k) {
c += b[j];
j++;
}
Console.WriteLine(a[j]);
}
}
}
|
using System;
using System.Linq;
namespace AtCoder {
class Program {
public static void Main() {
long[] input = new long[2];
input = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
long n = input[0];
long k = input[1];
long[] a = new long[n];
long[] b = new long[n];
for (long i = 0; i < n; i++) {
input = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
a[i] = input[0];
b[i] = input[1];
}
Array.Sort(a, b);
long j = 0;
long c = 0;
while (c + b[j] < k) {
c += b[j];
j++;
}
Console.WriteLine(a[j]);
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199]]
| 8
| 213
| 22
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp107 {
class Program {
static void Main(string[] args) {
var st = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = st[0];
int K = st[1];
var a = new int[N];
var b = new int[N];
var ans = new int[100010];
for (int i = 0; i < N; i++) {
var x = Console.ReadLine().Split().Select(int.Parse).ToArray();
a[i] = x[0];
b[i] = x[1];
ans[a[i]] += b[i];
}
for (int i = 0; i < 100010; i++) {
K -= ans[i];
if (K <= 0) {
Console.WriteLine(i);
break;
}
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp107 {
class Program {
static void Main(string[] args) {
var st = Console.ReadLine().Split().Select(long.Parse).ToArray();
long N = st[0];
long K = st[1];
var a = new long[N];
var b = new long[N];
var ans = new long[100010];
for (int i = 0; i < N; i++) {
var x = Console.ReadLine().Split().Select(long.Parse).ToArray();
a[i] = x[0];
b[i] = x[1];
ans[a[i]] += b[i];
}
for (int i = 0; i < 100010; i++) {
K -= ans[i];
if (K <= 0) {
Console.WriteLine(i);
break;
}
}
}
}
}
|
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199]]
| 8
| 226
| 14
|
using System;
using System.Collections.Generic;
namespace MyProgram {
class AtCoder {
static void Main() {
int[] input0 = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
int N = input0[0];
int K = input0[1];
int[] a = new int[N];
int[] b = new int[N];
for (var i = 0; i < N; i++) {
int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
a[i] = input[0];
b[i] = input[1];
}
var dict = new Dictionary<int, long>();
for (var i = 0; i < N; i++) {
if (!dict.ContainsKey(a[i]))
dict[a[i]] = b[i];
else
dict[a[i]] += b[i];
}
Array.Sort(a);
int temp = -1;
long count = 0;
for (var i = 0; i < N; i++) {
if (temp != a[i])
count += dict[a[i]];
temp = a[i];
if (count >= K) {
Console.WriteLine(a[i]);
break;
}
}
}
}
}
|
using System;
using System.Collections.Generic;
namespace MyProgram {
class AtCoder {
static void Main() {
long[] input0 = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
long N = input0[0];
long K = input0[1];
long[] a = new long[N];
long[] b = new long[N];
for (var i = 0; i < N; i++) {
long[] input =
Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
a[i] = input[0];
b[i] = input[1];
}
var dict = new Dictionary<long, long>();
for (var i = 0; i < N; i++) {
if (!dict.ContainsKey(a[i]))
dict[a[i]] = b[i];
else
dict[a[i]] += b[i];
}
Array.Sort(a);
long temp = -1;
long count = 0;
for (var i = 0; i < N; i++) {
if (temp != a[i])
count += dict[a[i]];
temp = a[i];
if (count >= K) {
Console.WriteLine(a[i]);
break;
}
}
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199]]
| 8
| 302
| 24
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace abc061_c {
class Program {
static void Main(string[] args) {
var NK = GetIntList();
var N = NK[0];
var K = NK[1];
var abd = new SortedDictionary<int, int>();
for (int i = 0; i < N; i++) {
var ab = GetIntList();
if (!abd.ContainsKey(ab[0]))
abd.Add(ab[0], 0);
abd[ab[0]] += ab[1];
}
int kk = 0;
foreach (var key in abd.Keys) {
kk += abd[key];
if (K <= kk) {
Console.WriteLine(key);
break;
}
}
}
public static string GetStr() => Console.ReadLine();
public static int GetInt() => int.Parse(Console.ReadLine());
public static long GetLong() => long.Parse(Console.ReadLine());
public static double GetDouble() => double.Parse(Console.ReadLine());
public static decimal GetDecimal() => decimal.Parse(Console.ReadLine());
public static List<string>
GetStrList() => Console.ReadLine().Split(' ').ToList();
public static List<int> GetIntList() =>
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
public static List<long> GetLongList() =>
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
public static List<double> GetDoubleList() =>
Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToList();
public static List<decimal> GetDecimalList() =>
Console.ReadLine().Split(' ').Select(x => decimal.Parse(x)).ToList();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace abc061_c {
class Program {
static void Main(string[] args) {
var NK = GetLongList();
var N = NK[0];
var K = NK[1];
var abd = new SortedDictionary<long, long>();
for (int i = 0; i < N; i++) {
var ab = GetIntList();
if (!abd.ContainsKey(ab[0]))
abd.Add(ab[0], 0);
abd[ab[0]] += ab[1];
}
long kk = 0;
foreach (var key in abd.Keys) {
kk += abd[key];
if (K <= kk) {
Console.WriteLine(key);
break;
}
}
}
public static string GetStr() => Console.ReadLine();
public static int GetInt() => int.Parse(Console.ReadLine());
public static long GetLong() => long.Parse(Console.ReadLine());
public static double GetDouble() => double.Parse(Console.ReadLine());
public static decimal GetDecimal() => decimal.Parse(Console.ReadLine());
public static List<string>
GetStrList() => Console.ReadLine().Split(' ').ToList();
public static List<int> GetIntList() =>
Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
public static List<long> GetLongList() =>
Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
public static List<double> GetDoubleList() =>
Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToList();
public static List<decimal> GetDecimalList() =>
Console.ReadLine().Split(' ').Select(x => decimal.Parse(x)).ToList();
}
}
|
[["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["+", 0, 208, 0, 231, 141, 232, 234, 232, 234, 22], ["+", 0, 208, 0, 231, 141, 232, 234, 232, 0, 131], ["+", 0, 208, 0, 231, 141, 232, 234, 232, 141, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
| 8
| 439
| 20
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass {
public const long Giri = 1000000007;
class ValuePair {
public long Value { get; set; }
public long Size { get; set; }
}
public static void Main(string[] args) {
var p = Input().ToInt();
var n = p[0];
var k = p[1];
var list = new List<ValuePair>(n);
for (int i = 0; i < n; i++) {
p = Input().ToInt();
var t = new ValuePair() { Value = p[0], Size = p[1] };
list.Add(t);
}
list.Sort((a, b) => (int)(a.Value - b.Value));
long index = 0;
for (int i = 0; i < n; i++) {
index += list[i].Size;
if (index >= k) {
Console.WriteLine(list[i].Value);
return;
}
}
}
static long GCD(long a, long b) {
var v = new[] { a, b };
while (v[1] != 0) {
v = new[] { v[1], v[0] % v[1] };
}
return v[0];
}
public static string[] Input() { return Console.ReadLine().Split(' '); }
public static int Clamp(int val, int max, int min = 0) {
return Math.Min(max, Math.Max(min, val));
}
}
public static class Smarter {
public static int ToInt(this string str) { return int.Parse(str); }
public static long ToLong(this string str) { return long.Parse(str); }
public static int[] ToInt(this string[] str) {
var r = new int[str.Length];
for (int i = 0; i < str.Length; i++)
r[i] = str[i].ToInt();
return r;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass {
public const long Giri = 1000000007;
class ValuePair {
public long Value { get; set; }
public long Size { get; set; }
}
public static void Main(string[] args) {
var p = Input();
var n = p[0].ToLong();
var k = p[1].ToLong();
var list = new List<ValuePair>((int)n);
for (int i = 0; i < n; i++) {
p = Input();
var t = new ValuePair() { Value = p[0].ToLong(), Size = p[1].ToLong() };
list.Add(t);
}
list.Sort((a, b) => (int)(a.Value - b.Value));
long index = 0;
for (int i = 0; i < n; i++) {
index += list[i].Size;
if (index >= k) {
Console.WriteLine(list[i].Value);
return;
}
}
}
static long GCD(long a, long b) {
var v = new[] { a, b };
while (v[1] != 0) {
v = new[] { v[1], v[0] % v[1] };
}
return v[0];
}
public static string[] Input() { return Console.ReadLine().Split(' '); }
public static int Clamp(int val, int max, int min = 0) {
return Math.Min(max, Math.Max(min, val));
}
}
public static class Smarter {
public static int ToInt(this string str) { return int.Parse(str); }
public static long ToLong(this string str) { return long.Parse(str); }
public static int[] ToInt(this string[] str) {
var r = new int[str.Length];
for (int i = 0; i < str.Length; i++)
r[i] = str[i].ToInt();
return r;
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24], ["+", 0, 230, 3, 4, 0, 28, 0, 74, 39, 199], ["+", 0, 230, 3, 4, 0, 28, 0, 74, 0, 25], ["-", 12, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 12, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 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
| 462
| 27
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass {
public const long Giri = 1000000007;
public static void Main(string[] args) {
var p = Input().ToInt();
var n = p[0];
var k = p[1];
var ary = new long[100000 + 2];
for (int i = 0; i < n; i++) {
var q = Input();
ary[q[0].ToInt()] += q[1].ToLong();
}
long index = k;
for (int i = 0; i < ary.Length; i++) {
index -= ary[i];
if (index <= 0) {
Console.WriteLine(i);
return;
}
}
}
static long GCD(long a, long b) {
var v = new[] { a, b };
while (v[1] != 0) {
v = new[] { v[1], v[0] % v[1] };
}
return v[0];
}
public static string[] Input() { return Console.ReadLine().Split(' '); }
public static int Clamp(int val, int max, int min = 0) {
return Math.Min(max, Math.Max(min, val));
}
}
public static class Smarter {
public static int ToInt(this string str) { return int.Parse(str); }
public static long ToLong(this string str) { return long.Parse(str); }
public static int[] ToInt(this string[] str) {
var r = new int[str.Length];
for (int i = 0; i < str.Length; i++)
r[i] = str[i].ToInt();
return r;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass {
public const long Giri = 1000000007;
public static void Main(string[] args) {
var p = Input();
var n = p[0].ToLong();
var k = p[1].ToLong();
var ary = new long[100000 + 2];
for (int i = 0; i < n; i++) {
var q = Input();
ary[q[0].ToLong()] += q[1].ToLong();
}
long index = k;
for (int i = 0; i < ary.Length; i++) {
index -= ary[i];
if (index <= 0) {
Console.WriteLine(i);
return;
}
}
}
static long GCD(long a, long b) {
var v = new[] { a, b };
while (v[1] != 0) {
v = new[] { v[1], v[0] % v[1] };
}
return v[0];
}
public static string[] Input() { return Console.ReadLine().Split(' '); }
public static int Clamp(int val, int max, int min = 0) {
return Math.Min(max, Math.Max(min, val));
}
}
public static class Smarter {
public static int ToInt(this string str) { return int.Parse(str); }
public static long ToLong(this string str) { return long.Parse(str); }
public static int[] ToInt(this string[] str) {
var r = new int[str.Length];
for (int i = 0; i < str.Length; i++)
r[i] = str[i].ToInt();
return r;
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 206, 207, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 206, 207, 0, 28, 0, 213, 63, 214, 141, 22]]
| 8
| 398
| 14
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split().Select(long.Parse).ToArray();
long N = input[0], K = input[1];
var bigArray = new long[100000 + 1];
var nums = new List<long>();
for (var i = 0; i < N; ++i) {
var num_times = Console.ReadLine().Split();
long num = long.Parse(num_times[0]), times = long.Parse(num_times[1]);
bigArray[num] += times;
nums.Add(num);
}
var indexes = nums.Distinct();
foreach (var num in indexes) {
K -= bigArray[num];
if (K > 0)
continue;
Console.WriteLine(num);
return;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split().Select(long.Parse).ToArray();
long N = input[0], K = input[1];
var bigArray = new long[100000 + 1];
var nums = new List<long>();
for (var i = 0; i < N; ++i) {
var num_times = Console.ReadLine().Split();
long num = long.Parse(num_times[0]), times = long.Parse(num_times[1]);
bigArray[num] += times;
nums.Add(num);
}
var indexes = nums.Distinct().OrderBy(x => x);
foreach (var num in indexes) {
K -= bigArray[num];
if (K > 0)
continue;
Console.WriteLine(num);
return;
}
}
}
|
[["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 0, 213, 3, 4, 0, 28, 0, 218, 8, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
| 8
| 201
| 7
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split().Select(long.Parse).ToArray();
long N = input[0], K = input[1];
var bigArray = new long[100000 + 1];
for (var i = 0; i < N; ++i) {
var num_times = Console.ReadLine().Split();
long num = long.Parse(num_times[0]), times = long.Parse(num_times[1]);
bigArray[num] += times;
}
for (var i = 1; i < 100000; i++) {
K -= bigArray[i];
if (K > 0)
continue;
Console.WriteLine(i);
Console.Read();
return;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var input = Console.ReadLine().Split().Select(long.Parse).ToArray();
long N = input[0], K = input[1];
var bigArray = new long[100000 + 1];
for (var i = 0; i < N; ++i) {
var num_times = Console.ReadLine().Split();
long num = long.Parse(num_times[0]), times = long.Parse(num_times[1]);
bigArray[num] += times;
}
for (var i = 1; i <= 100000; i++) {
K -= bigArray[i];
if (K > 0)
continue;
Console.WriteLine(i);
return;
}
}
}
|
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24]]
| 8
| 187
| 8
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCorder {
public class Program {
static void Main(string[] args) {
Scanner cin = new Scanner();
int n = cin.Int();
long k = cin.Long();
var ab = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
long a = cin.Long();
long b = cin.Long();
ab[i] = new Tuple<long, long>(a, b);
}
long cnt = 0;
long ans = 0;
for (int i = 0; i < n; i++) {
cnt += ab[i].Item2;
if (cnt >= k) {
ans = ab[i].Item1;
break;
}
}
Console.WriteLine(ans);
}
}
public class Scanner {
private readonly char[] delimiter_ = new char[] { ' ' };
private string[] buf_;
private int index_;
public Scanner() {
buf_ = new string[0];
index_ = 0;
}
public string Next() {
if (index_ < buf_.Length) {
return buf_[index_++];
}
string st = Console.ReadLine();
while (st == "") {
st = Console.ReadLine();
}
buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
if (buf_.Length == 0) {
return Next();
}
index_ = 0;
return buf_[index_++];
}
public int Int() => int.Parse(Next());
public long Long() => long.Parse(Next());
public double Double() => double.Parse(Next());
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Int() + add;
}
return Array;
}
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = Long() + add;
}
return Array;
}
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = Double() + add;
}
return Array;
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AtCorder {
public class Program {
static void Main(string[] args) {
Scanner cin = new Scanner();
int n = cin.Int();
long k = cin.Long();
var ab = new Tuple<long, long>[n];
for (int i = 0; i < n; i++) {
long a = cin.Long();
long b = cin.Long();
ab[i] = new Tuple<long, long>(a, b);
}
var ab2 = ab.OrderBy(x => x.Item1).ToArray();
long cnt = 0;
long ans = 0;
for (int i = 0; i < n; i++) {
cnt += ab2[i].Item2;
if (cnt >= k) {
ans = ab2[i].Item1;
break;
}
}
Console.WriteLine(ans);
}
}
public class Scanner {
private readonly char[] delimiter_ = new char[] { ' ' };
private string[] buf_;
private int index_;
public Scanner() {
buf_ = new string[0];
index_ = 0;
}
public string Next() {
if (index_ < buf_.Length) {
return buf_[index_++];
}
string st = Console.ReadLine();
while (st == "") {
st = Console.ReadLine();
}
buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
if (buf_.Length == 0) {
return Next();
}
index_ = 0;
return buf_[index_++];
}
public int Int() => int.Parse(Next());
public long Long() => long.Parse(Next());
public double Double() => double.Parse(Next());
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Int() + add;
}
return Array;
}
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = Long() + add;
}
return Array;
}
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = Double() + add;
}
return Array;
}
}
}
|
[["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 1, 0, 11, 12, 214, 205, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 214, 205, 204, 205, 22]]
| 8
| 565
| 22
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Cs {
class Program {
static void Main(string[] args) {
var str = Console.ReadLine().Split(' ');
int N = int.Parse(str[0]);
int K = int.Parse(str[1]);
long[] memo = new long[1000001];
for (int i = 0; i < N; i++) {
var str2 = Console.ReadLine().Split(' ');
int a = int.Parse(str2[0]);
int b = int.Parse(str2[1]);
memo[a] += b;
}
long count = 0;
for (long i = 0; i < memo.Length; i++) {
count += memo[i];
if (count >= K) {
Console.WriteLine(i);
return;
}
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Cs {
class Program {
static void Main(string[] args) {
var str = Console.ReadLine().Split(' ');
long N = long.Parse(str[0]);
long K = long.Parse(str[1]);
long[] memo = new long[1000001];
for (long i = 0; i < N; i++) {
var str2 = Console.ReadLine().Split(' ');
long a = long.Parse(str2[0]);
long b = long.Parse(str2[1]);
memo[a] += b;
}
long count = 0;
for (long i = 0; i < memo.Length; i++) {
count += memo[i];
if (count >= K) {
Console.WriteLine(i);
return;
}
}
}
}
}
|
[["-", 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], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199]]
| 8
| 211
| 18
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
namespace AtCoderWorkspace {
public class Solver {
public void Solve() {
var cin = new Scanner();
var n = cin.nextInt();
var k = cin.nextInt();
var a = new int[n];
var b = new int[n];
var list = new List<Tuple<int, int>>();
for (int i = 0; i < n; i++) {
var aa = cin.nextInt();
var bb = cin.nextInt();
list.Add(new Tuple<int, int>(aa, bb));
}
list.OrderBy(x => x.Item1);
long ans = 0;
long count = 0;
foreach (var item in list) {
count += item.Item2;
if (k <= count) {
ans = item.Item1;
break;
}
}
Console.WriteLine(ans);
}
}
#region library
static class C {
public static long LowerBound(long[] a, long key) {
long l = 0;
long r = a.Length;
long mid;
while (l < r) {
mid = ((r - l) / 2) + l;
if (a[mid] <= key)
l = mid + 1;
else
r = mid;
}
return l;
}
public static long UpperBound(long[] a, long key) {
long l = 0;
long r = a.Length;
long mid;
while (l < r) {
mid = ((r - l) / 2) + l;
if (a[mid] < key)
l = mid + 1;
else
r = mid;
}
return l;
}
}
public static partial class MathEx {
public static int GCD(int n, int m) { return (int)GCD((long)n, m); }
public static long GCD(long n, long m) {
n = Math.Abs(n);
m = Math.Abs(m);
while (n != 0) {
m %= n;
if (m == 0)
return n;
n %= m;
}
return m;
}
public static long LCM(long n, long m) { return (n / GCD(n, m)) * m; }
public static bool[] Sieve(int max, List<int> primes = null) {
var isPrime = new bool[max + 1];
for (int i = 2; i < isPrime.Length; i++)
isPrime[i] = true;
for (int i = 2; i * i <= max; i++)
if (!isPrime[i])
continue;
else
for (int j = i * i; j <= max; j += i)
isPrime[j] = false;
if (primes != null)
for (int i = 0; i <= max; i++)
if (isPrime[i])
primes.Add(i);
return isPrime;
}
}
static class Subsequence {
/// <summary>
/// 最長増加部分列
/// </summary>
/// <param name="a">long[]</param>
/// <returns></returns>
public static long LIS(long[] a) {
var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray();
for (int i = 0; i < a.Length; i++) {
dp[C.LowerBound(dp, a[i])] = a[i];
}
return C.LowerBound(dp, long.MaxValue - 1);
}
/// <summary>
/// 重複を許さない最長増加部分列
/// </summary>
/// <param name="a">long[]</param>
/// <returns></returns>
public static long UniqueLIS(long[] a) {
var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray();
for (int i = 0; i < a.Length; i++) {
dp[C.UpperBound(dp, a[i])] = a[i];
}
return C.UpperBound(dp, long.MaxValue - 1);
}
}
class PriorityQueue<T> {
private readonly List<T> heap;
private readonly Comparison<T> compare;
private int size;
public PriorityQueue() : this(Comparer<T>.Default) {}
public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {}
public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {}
public PriorityQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.compare = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && compare(heap[b], heap[a]) < 0)
a = b;
if (compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
}
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;
}
}
public class ModInt {
public static long Mod;
public long num;
public ModInt(long n, int mod = (int)1e9 + 7) {
num = n;
Mod = mod;
}
public override string ToString() { return num.ToString(); }
public static ModInt operator +(ModInt l, ModInt r) {
l.num += r.num;
if (l.num >= Mod)
l.num -= Mod;
return l;
}
public static ModInt operator -(ModInt l, ModInt r) {
l.num -= r.num;
if (l.num < 0)
l.num += Mod;
return l;
}
public static ModInt operator *(ModInt l, ModInt r) {
return new ModInt(l.num * r.num % Mod);
}
public static implicit operator ModInt(long n) {
n %= Mod;
if (n < 0)
n += Mod;
return new ModInt(n);
}
public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }
public static ModInt Pow(long v, long k) {
long ret = 1;
for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
if ((k & 1) == 1)
ret = ret * v % Mod;
return new ModInt(ret);
}
public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
}
#endregion
class Program {
static void Main(string[] s) => new Solver().Solve();
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
namespace AtCoderWorkspace {
public class Solver {
public void Solve() {
var cin = new Scanner();
var n = cin.nextLong();
var k = cin.nextLong();
var list = new List<Tuple<long, long>>();
for (int i = 0; i < n; i++) {
var aa = cin.nextInt();
var bb = cin.nextInt();
list.Add(new Tuple<long, long>(aa, bb));
}
list = list.OrderBy(x => x.Item1).ToList();
long ans = 0;
long count = 0;
foreach (var item in list) {
count += item.Item2;
if (k <= count) {
ans = item.Item1;
break;
}
}
Console.WriteLine(ans);
}
}
#region library
static class C {
public static long LowerBound(long[] a, long key) {
long l = 0;
long r = a.Length;
long mid;
while (l < r) {
mid = ((r - l) / 2) + l;
if (a[mid] <= key)
l = mid + 1;
else
r = mid;
}
return l;
}
public static long UpperBound(long[] a, long key) {
long l = 0;
long r = a.Length;
long mid;
while (l < r) {
mid = ((r - l) / 2) + l;
if (a[mid] < key)
l = mid + 1;
else
r = mid;
}
return l;
}
}
public static partial class MathEx {
public static int GCD(int n, int m) { return (int)GCD((long)n, m); }
public static long GCD(long n, long m) {
n = Math.Abs(n);
m = Math.Abs(m);
while (n != 0) {
m %= n;
if (m == 0)
return n;
n %= m;
}
return m;
}
public static long LCM(long n, long m) { return (n / GCD(n, m)) * m; }
public static bool[] Sieve(int max, List<int> primes = null) {
var isPrime = new bool[max + 1];
for (int i = 2; i < isPrime.Length; i++)
isPrime[i] = true;
for (int i = 2; i * i <= max; i++)
if (!isPrime[i])
continue;
else
for (int j = i * i; j <= max; j += i)
isPrime[j] = false;
if (primes != null)
for (int i = 0; i <= max; i++)
if (isPrime[i])
primes.Add(i);
return isPrime;
}
}
static class Subsequence {
/// <summary>
/// 最長増加部分列
/// </summary>
/// <param name="a">long[]</param>
/// <returns></returns>
public static long LIS(long[] a) {
var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray();
for (int i = 0; i < a.Length; i++) {
dp[C.LowerBound(dp, a[i])] = a[i];
}
return C.LowerBound(dp, long.MaxValue - 1);
}
/// <summary>
/// 重複を許さない最長増加部分列
/// </summary>
/// <param name="a">long[]</param>
/// <returns></returns>
public static long UniqueLIS(long[] a) {
var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray();
for (int i = 0; i < a.Length; i++) {
dp[C.UpperBound(dp, a[i])] = a[i];
}
return C.UpperBound(dp, long.MaxValue - 1);
}
}
class PriorityQueue<T> {
private readonly List<T> heap;
private readonly Comparison<T> compare;
private int size;
public PriorityQueue() : this(Comparer<T>.Default) {}
public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {}
public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {}
public PriorityQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.compare = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && compare(heap[b], heap[a]) < 0)
a = b;
if (compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
}
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;
}
}
public class ModInt {
public static long Mod;
public long num;
public ModInt(long n, int mod = (int)1e9 + 7) {
num = n;
Mod = mod;
}
public override string ToString() { return num.ToString(); }
public static ModInt operator +(ModInt l, ModInt r) {
l.num += r.num;
if (l.num >= Mod)
l.num -= Mod;
return l;
}
public static ModInt operator -(ModInt l, ModInt r) {
l.num -= r.num;
if (l.num < 0)
l.num += Mod;
return l;
}
public static ModInt operator *(ModInt l, ModInt r) {
return new ModInt(l.num * r.num % Mod);
}
public static implicit operator ModInt(long n) {
n %= Mod;
if (n < 0)
n += Mod;
return new ModInt(n);
}
public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }
public static ModInt Pow(long v, long k) {
long ret = 1;
for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
if ((k & 1) == 1)
ret = ret * v % Mod;
return new ModInt(ret);
}
public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
}
#endregion
class Program {
static void Main(string[] s) => new Solver().Solve();
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 227, 0, 228], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 70], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 73], ["-", 39, 236, 237, 238, 0, 236, 237, 238, 0, 199], ["+", 39, 236, 237, 238, 0, 236, 237, 238, 0, 199], ["-", 0, 28, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 28, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 12, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24]]
| 8
| 1,892
| 36
|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Math;
using static System.Console;
using System.Text;
class Program {
static void Main(string[] args) { solve(); }
static Scanner cin;
static int N;
static long K;
static int[] a, b;
static void input() {
cin = new Scanner();
N = cin.nextInt();
K = cin.nextLong();
a = new int[N];
b = new int[N];
for (int i = 0; i < N; i++) {
a[i] = cin.nextInt();
b[i] = cin.nextInt();
}
}
static void solve() {
input();
long iter = 0;
for (int i = 0; i < N; i++) {
iter += b[i];
if (iter >= K) {
WriteLine(a[i]);
return;
}
}
}
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[] ArrayDounble(int N, int add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
}
|
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Math;
using static System.Console;
using System.Text;
class Program {
static void Main(string[] args) { solve(); }
static Scanner cin;
static int N;
static long K;
static int[] a, b;
static void input() {
cin = new Scanner();
N = cin.nextInt();
K = cin.nextLong();
a = new int[N];
b = new int[N];
for (int i = 0; i < N; i++) {
a[i] = cin.nextInt();
b[i] = cin.nextInt();
}
}
static void solve() {
input();
Array.Sort(a, b);
long iter = 0;
for (int i = 0; i < N; i++) {
iter += b[i];
if (iter >= K) {
WriteLine(a[i]);
return;
}
}
}
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[] ArrayDounble(int N, int add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = nextDouble() + add;
}
return Array;
}
}
}
|
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 562
| 9
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;
public class Pair {
public int A { get; private set; }
public int B { get; private set; }
public Pair(int a, int b) {
A = a;
B = b;
}
}
public class C {
public static void Main() {
int N = GetInt();
int K = GetInt();
List<Pair> pairs = new List<Pair>(N);
for (int i = 0; i < N; i++)
pairs.Add(new Pair(GetInt(), GetInt()));
pairs.Sort((x, y) => x.A - y.A);
int num = 0;
for (int i = 0; i < N; i++) {
num += pairs[i].B;
if (num >= K) {
Console.WriteLine(pairs[i].A);
return;
}
}
}
}
public static class MyIO {
private static string[] args = null;
private static int num = -1;
private static int used = -1;
private static string getArg() {
if (used == num) {
args = Console.ReadLine().Split(' ');
num = args.Length;
used = 0;
}
return args[used++];
}
public static int GetInt() { return int.Parse(getArg()); }
public static long GetLong() { return long.Parse(getArg()); }
public static double GetDouble() { return double.Parse(getArg()); }
public static string GetString() { return getArg(); }
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;
public class Pair {
public long A { get; private set; }
public long B { get; private set; }
public Pair(long a, long b) {
A = a;
B = b;
}
}
public class C {
public static void Main() {
long N = GetLong();
long K = GetLong(); // N <= 10^5, bi <= 10^5 thus K <= 10^10
List<Pair> pairs = new List<Pair>();
for (long i = 0; i < N; i++)
pairs.Add(new Pair(GetLong(), GetLong()));
pairs.Sort((x, y) => (int)(x.A - y.A));
long num = 0;
for (long i = 0; i < N; i++) {
num += pairs[(int)i].B;
if (num >= K) {
Console.WriteLine(pairs[(int)i].A);
return;
}
}
}
}
public static class MyIO {
private static string[] args = null;
private static int num = -1;
private static int used = -1;
private static string getArg() {
if (used == num) {
args = Console.ReadLine().Split(' ');
num = args.Length;
used = 0;
}
return args[used++];
}
public static int GetInt() { return int.Parse(getArg()); }
public static long GetLong() { return long.Parse(getArg()); }
public static double GetDouble() { return double.Parse(getArg()); }
public static string GetString() { return getArg(); }
}
|
[["-", 0, 208, 0, 235, 8, 201, 0, 277, 39, 199], ["+", 0, 208, 0, 235, 8, 201, 0, 277, 39, 199], ["-", 8, 201, 0, 263, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 263, 54, 55, 0, 220, 39, 199], ["-", 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, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["-", 0, 212, 0, 230, 3, 4, 0, 28, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 0, 230, 3, 4, 0, 28, 0, 213, 63, 22], ["+", 0, 230, 3, 4, 0, 28, 0, 213, 63, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 74, 0, 24], ["+", 3, 4, 0, 28, 0, 218, 8, 74, 39, 199], ["+", 3, 4, 0, 28, 0, 218, 8, 74, 0, 25], ["+", 0, 28, 0, 218, 8, 74, 51, 23, 0, 24], ["+", 0, 28, 0, 218, 8, 74, 51, 23, 0, 25], ["+", 205, 204, 206, 207, 0, 28, 0, 74, 0, 24], ["+", 205, 204, 206, 207, 0, 28, 0, 74, 39, 199], ["+", 205, 204, 206, 207, 0, 28, 0, 74, 0, 25]]
| 8
| 358
| 38
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
class Program {
static void Main(string[] args) {
string[] cin = Console.ReadLine().Split();
int n = int.Parse(cin[0]);
int k = int.Parse(cin[1]);
int[] basket = new int[100001];
for (int i = 0; i < n; i++) {
cin = Console.ReadLine().Split();
basket[int.Parse(cin[0])] += int.Parse(cin[1]);
}
int ans = 0;
for (int i = 1; i < 100001; i++) {
k -= basket[i];
if (k <= 0) {
ans = i;
break;
}
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
class Program {
static void Main(string[] args) {
string[] cin = Console.ReadLine().Split();
long n = long.Parse(cin[0]);
long k = long.Parse(cin[1]);
long[] basket = new long[100001];
for (long i = 0; i < n; i++) {
cin = Console.ReadLine().Split();
basket[long.Parse(cin[0])] += long.Parse(cin[1]);
}
long ans = 0;
for (long i = 1; i < 100001; i++) {
k -= basket[i];
if (k <= 0) {
ans = i;
break;
}
}
Console.WriteLine(ans);
}
}
|
[["-", 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, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 206, 207, 0, 28, 0, 213, 63, 214, 205, 199], ["+", 206, 207, 0, 28, 0, 213, 63, 214, 205, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199]]
| 8
| 187
| 22
|
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using System.Text;
namespace AtCoder {
public class Program {
static int[] getKeys(char delimiter = ' ') {
var Keys = Console.ReadLine().Split(delimiter);
int N = Keys.Length;
int[] Ns = new int[N];
for (int i = 0; i < N; i++) {
Ns[i] = int.Parse(Keys[i]);
}
return Ns;
}
static long[] getKeys_L(char delimiter = ' ') {
var Keys = Console.ReadLine().Split(delimiter);
int N = Keys.Length;
long[] Ns = new long[N];
for (int i = 0; i < N; i++) {
Ns[i] = long.Parse(Keys[i]);
}
return Ns;
}
static double[] getKeys_D(char delimiter = ' ') {
var Keys = Console.ReadLine().Split(delimiter);
int N = Keys.Length;
var Ns = new double[N];
for (int i = 0; i < N; i++) {
Ns[i] = double.Parse(Keys[i]);
}
return Ns;
}
static int[] getLines(int N, char delimiter = ' ') {
int[] Ns = new int[N];
for (int i = 0; i < N; i++) {
Ns[i] = int.Parse(Console.ReadLine());
}
return Ns;
}
static long[] getLines_L(int N, char delimiter = ' ') {
long[] Ns = new long[N];
for (int i = 0; i < N; i++) {
Ns[i] = long.Parse(Console.ReadLine());
}
return Ns;
}
static double[] getLines_D(int N, char delimiter = ' ') {
double[] Ns = new double[N];
for (int i = 0; i < N; i++) {
Ns[i] = double.Parse(Console.ReadLine());
}
return Ns;
}
public static void Show<T>(T[,] map) {
int H = map.GetLength(0);
int W = map.GetLength(1);
Console.WriteLine("-------------------------");
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
Console.Write(map[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine("-------------------------");
}
public static void Show<T>(T[,] map, string delimiter) {
int H = map.GetLength(0);
int W = map.GetLength(1);
Console.WriteLine("-------------------------");
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
Console.Write(map[i, j] + delimiter);
}
Console.WriteLine();
}
Console.WriteLine("-------------------------");
}
public static void Show<T>(IEnumerable<T> ts) {
foreach (var item in ts) {
Console.Write(item + " ");
}
Console.WriteLine();
}
public static void Show<T>(IEnumerable<T> ts, string delimiter) {
foreach (var item in ts) {
Console.Write(item + delimiter);
}
Console.WriteLine();
}
public static void ShowDictionary<T1, T2>(Dictionary<T1, T2> dictionary) {
foreach (var item in dictionary) {
Console.WriteLine(item);
}
}
static T[] getUniform<T>(int length, T value) {
T[] Ts = new T[length];
for (int i = 0; i < length; i++) {
Ts[i] = value;
}
return Ts;
}
static void setUniform<T>(T[] ts, T value) {
int length = ts.Length;
for (int i = 0; i < length; i++) {
ts[i] = value;
}
}
static T[,] getUniform<T>(int row, int col, T value) {
T[,] Ts = new T[row, col];
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
Ts[j, i] = value;
}
}
return Ts;
}
static void setUniform<T>(T[,] ts, T value) {
int N = ts.GetLength(0);
int M = ts.GetLength(1);
for (int i = 0; i < M; i++) {
for (int j = 0; j < N; j++) {
ts[j, i] = value;
}
}
}
static Tuple<int, int> findIndex<T>(T[,] map, T value)
where T : IComparable {
int row = map.GetLength(0);
int col = map.GetLength(1);
for (int i = 0; i < col; i++) {
for (int j = 0; j < row; j++) {
if (value.CompareTo(map[j, i]) == 0)
return new Tuple<int, int>(j, i);
}
}
return new Tuple<int, int>(-1, -1);
}
static void Main() {
var keys = getKeys();
int N = keys[0];
int K = keys[1];
Dictionary<int, long> Counts = new Dictionary<int, long>();
for (int i = 0; i < N; i++) {
keys = getKeys();
if (Counts.ContainsKey(keys[0])) {
Counts[keys[0]] += keys[1];
} else {
Counts[keys[0]] = keys[1];
}
}
long sum = 0;
foreach (var item in Counts.OrderBy(x => x.Key)) {
sum += item.Value;
if (sum >= K) {
Console.WriteLine(item.Key);
return;
}
}
Console.WriteLine(Counts.Keys.Max());
}
}
}
|
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using System.Text;
namespace AtCoder {
public class Program {
static int[] getKeys(char delimiter = ' ') {
var Keys = Console.ReadLine().Split(delimiter);
int N = Keys.Length;
int[] Ns = new int[N];
for (int i = 0; i < N; i++) {
Ns[i] = int.Parse(Keys[i]);
}
return Ns;
}
static long[] getKeys_L(char delimiter = ' ') {
var Keys = Console.ReadLine().Split(delimiter);
int N = Keys.Length;
long[] Ns = new long[N];
for (int i = 0; i < N; i++) {
Ns[i] = long.Parse(Keys[i]);
}
return Ns;
}
static double[] getKeys_D(char delimiter = ' ') {
var Keys = Console.ReadLine().Split(delimiter);
int N = Keys.Length;
var Ns = new double[N];
for (int i = 0; i < N; i++) {
Ns[i] = double.Parse(Keys[i]);
}
return Ns;
}
static int[] getLines(int N, char delimiter = ' ') {
int[] Ns = new int[N];
for (int i = 0; i < N; i++) {
Ns[i] = int.Parse(Console.ReadLine());
}
return Ns;
}
static long[] getLines_L(int N, char delimiter = ' ') {
long[] Ns = new long[N];
for (int i = 0; i < N; i++) {
Ns[i] = long.Parse(Console.ReadLine());
}
return Ns;
}
static double[] getLines_D(int N, char delimiter = ' ') {
double[] Ns = new double[N];
for (int i = 0; i < N; i++) {
Ns[i] = double.Parse(Console.ReadLine());
}
return Ns;
}
public static void Show<T>(T[,] map) {
int H = map.GetLength(0);
int W = map.GetLength(1);
Console.WriteLine("-------------------------");
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
Console.Write(map[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine("-------------------------");
}
public static void Show<T>(T[,] map, string delimiter) {
int H = map.GetLength(0);
int W = map.GetLength(1);
Console.WriteLine("-------------------------");
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
Console.Write(map[i, j] + delimiter);
}
Console.WriteLine();
}
Console.WriteLine("-------------------------");
}
public static void Show<T>(IEnumerable<T> ts) {
foreach (var item in ts) {
Console.Write(item + " ");
}
Console.WriteLine();
}
public static void Show<T>(IEnumerable<T> ts, string delimiter) {
foreach (var item in ts) {
Console.Write(item + delimiter);
}
Console.WriteLine();
}
public static void ShowDictionary<T1, T2>(Dictionary<T1, T2> dictionary) {
foreach (var item in dictionary) {
Console.WriteLine(item);
}
}
static T[] getUniform<T>(int length, T value) {
T[] Ts = new T[length];
for (int i = 0; i < length; i++) {
Ts[i] = value;
}
return Ts;
}
static void setUniform<T>(T[] ts, T value) {
int length = ts.Length;
for (int i = 0; i < length; i++) {
ts[i] = value;
}
}
static T[,] getUniform<T>(int row, int col, T value) {
T[,] Ts = new T[row, col];
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
Ts[j, i] = value;
}
}
return Ts;
}
static void setUniform<T>(T[,] ts, T value) {
int N = ts.GetLength(0);
int M = ts.GetLength(1);
for (int i = 0; i < M; i++) {
for (int j = 0; j < N; j++) {
ts[j, i] = value;
}
}
}
static Tuple<int, int> findIndex<T>(T[,] map, T value)
where T : IComparable {
int row = map.GetLength(0);
int col = map.GetLength(1);
for (int i = 0; i < col; i++) {
for (int j = 0; j < row; j++) {
if (value.CompareTo(map[j, i]) == 0)
return new Tuple<int, int>(j, i);
}
}
return new Tuple<int, int>(-1, -1);
}
static void Main() {
var keys = getKeys_L();
int N = (int)keys[0];
long K = keys[1];
Dictionary<int, long> Counts = new Dictionary<int, long>();
for (int i = 0; i < N; i++) {
keys = getKeys_L();
if (Counts.ContainsKey((int)keys[0])) {
Counts[(int)keys[0]] += keys[1];
} else {
Counts.Add((int)keys[0], keys[1]);
}
}
long sum = 0;
foreach (var item in Counts.OrderBy(x => x.Key)) {
sum += item.Value;
if (sum >= K) {
Console.WriteLine(item.Key);
return;
}
}
Console.WriteLine(Counts.Keys.Max());
}
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 24], ["+", 15, 213, 3, 4, 0, 28, 0, 74, 39, 199], ["+", 15, 213, 3, 4, 0, 28, 0, 74, 0, 25], ["+", 31, 204, 206, 207, 0, 28, 0, 74, 0, 24], ["+", 31, 204, 206, 207, 0, 28, 0, 74, 39, 199], ["+", 31, 204, 206, 207, 0, 28, 0, 74, 0, 25], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 74, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 74, 39, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 74, 0, 25], ["-", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25]]
| 8
| 1,363
| 26
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC_C {
class C061 {
static void Main(string[] args) {
string[] s1 = Console.ReadLine().Split(' ');
int N = int.Parse(s1[0]);
int K = int.Parse(s1[1]);
SortedDictionary<int, int> dic = new SortedDictionary<int, int>();
List<int> list = new List<int>();
for (int i = 0; i < N; i++) {
string[] s = Console.ReadLine().Split(' ');
int a = int.Parse(s[0]);
int b = int.Parse(s[1]);
if (!dic.ContainsKey(a))
dic.Add(a, 0);
dic[a] += b;
}
long counter = 0;
int index = 0;
while (true) {
counter += dic.Values.ToList()[index];
if (counter >= K)
break;
index++;
}
int x = dic.Keys.ToList()[index];
Console.WriteLine(x);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ABC_C {
class C061 {
static void Main(string[] args) {
string[] s1 = Console.ReadLine().Split(' ');
int N = int.Parse(s1[0]);
long K = long.Parse(s1[1]);
SortedDictionary<int, long> dic = new SortedDictionary<int, long>();
List<int> list = new List<int>();
for (int i = 0; i < N; i++) {
string[] s = Console.ReadLine().Split(' ');
int a = int.Parse(s[0]);
int b = int.Parse(s[1]);
if (!dic.ContainsKey(a))
dic.Add(a, 0);
dic[a] += b;
}
long counter = 0;
int index = 0;
List<long> v = dic.Values.ToList();
while (true) {
counter += v[index];
if (counter >= K)
break;
index++;
}
int x = dic.Keys.ToList()[index];
Console.WriteLine(x);
}
}
}
|
[["-", 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], ["-", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 8, 201, 0, 195, 8, 196, 0, 52, 0, 89], ["-", 8, 201, 0, 195, 8, 196, 0, 52, 0, 24], ["-", 0, 195, 8, 196, 0, 52, 15, 211, 0, 146], ["-", 8, 201, 0, 195, 8, 196, 0, 52, 0, 25], ["-", 0, 195, 8, 196, 0, 52, 8, 196, 0, 45], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 197, 0, 198, 39, 236, 141, 22], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 18], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 47], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 89], ["+", 0, 195, 8, 196, 0, 52, 15, 211, 0, 146], ["+", 0, 195, 8, 196, 0, 52, 8, 196, 0, 45], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22]]
| 8
| 269
| 30
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main() {
Scanner cin = new Scanner();
long N = cin.Long();
long K = cin.Long();
var dic = new Dictionary<long, long>();
for (int i = 0; i < N; i++) {
var a = cin.Long();
var b = cin.Long();
if (dic.ContainsKey(a))
dic[a] += b;
else
dic.Add(a, b);
}
int index = 0;
var list = new List<long>(dic.Keys);
list.Sort();
while (K > dic.Values.ElementAt(index)) {
K -= dic.Values.ElementAt(index);
index++;
}
Console.WriteLine(list[index]);
Console.ReadLine();
}
}
class Scanner //標準入力
{
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int Int() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Int() + add;
}
return Array;
}
public long Long() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = Long() + add;
}
return Array;
}
public double Double() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = Double() + add;
}
return Array;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
static void Main() {
Scanner cin = new Scanner();
long N = cin.Long();
long K = cin.Long();
var dic = new Dictionary<long, long>();
for (int i = 0; i < N; i++) {
var a = cin.Long();
var b = cin.Long();
if (dic.ContainsKey(a))
dic[a] += b;
else
dic.Add(a, b);
}
int index = 0;
var list = new List<long>(dic.Keys);
list.Sort();
while (K > dic[list[index]]) {
K -= dic[list[index]];
index++;
}
Console.WriteLine(list[index]);
Console.ReadLine();
}
}
class Scanner //標準入力
{
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int Int() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Int() + add;
}
return Array;
}
public long Long() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = Long() + add;
}
return Array;
}
public double Double() { return double.Parse(next()); }
public double[] ArrayDouble(int N, double add = 0) {
double[] Array = new double[N];
for (int i = 0; i < N; i++) {
Array[i] = Double() + add;
}
return Array;
}
}
|
[["-", 15, 16, 12, 213, 63, 214, 205, 214, 0, 131], ["-", 15, 16, 12, 213, 63, 214, 205, 214, 141, 22], ["-", 0, 52, 15, 16, 12, 213, 63, 214, 0, 131], ["-", 0, 52, 15, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 52, 15, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 52, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 52, 15, 16, 12, 213, 3, 4, 0, 25], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 52, 15, 16, 12, 204, 206, 207, 0, 73], ["-", 0, 11, 12, 213, 63, 214, 205, 214, 0, 131], ["-", 0, 11, 12, 213, 63, 214, 205, 214, 141, 22], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73]]
| 8
| 558
| 22
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
// using static System.Linq.Enumerable;
using static System.Console;
using static AtCoder.Util;
using static AtCoder.Cin;
using static System.Math;
using static AtCoder.MyMath;
using static AtCoder.StreamExtensions;
using static AtCoder.Matrix;
namespace AtCoder {
using VI = VectorInt2;
static class Program {
static void Main() {
int n = ReadInt();
long k = ReadLong();
var list = new SortedDictionary<int, long>();
for (int i = 0; i < n; i++) {
string[] strer = Console.ReadLine().Split(' ');
int key = int.Parse(strer[0]);
int vla = int.Parse(strer[1]);
if (list.ContainsKey(key)) {
list[key] += vla;
} else {
list[key] = vla;
}
}
long u = 0;
foreach (var s in list) {
u = s.Value;
if (u >= k) {
Console.WriteLine(s.Key);
break;
} else {
k -= u;
}
}
}
}
}
/* ***************** Following Contents are my common library ******** */
namespace AtCoder {
static class Algorithm {
public static LongRange BinSearch(LongRange range, Func<long, bool> isBigger,
long width) =>
BinSearch(range, isBigger, x => range.Right - range.Left < width);
public static LongRange BinSearch(LongRange range, Func<long, bool> isBigger,
Func<LongRange, bool> stopCondition) {
if (stopCondition(range))
return range;
var middle = range.Left + (range.Right - range.Left) / 2;
return isBigger(middle) ? BinSearch(new LongRange(range.Left, middle),
isBigger, stopCondition)
: BinSearch(new LongRange(middle, range.Right),
isBigger, stopCondition);
}
}
static class MyMath {
public static long GCD(long a,
long b) => a<b? GCD(b, a) : b> 0 ? GCD(b, a % b) : a;
public static long Factorial(this long n) => Range(1, n).Aggregate(1L,
Multiply);
public static long nPr(int n, int r) => r < 0 || r > n? 0
: FromTo(n - r + 1, n)
.Select(x => (long)x)
.Aggregate(1L, Multiply);
public static long nCr(int n, int r) => nPr(n, r) / Factorial(r);
public static long Inc(long i) => i + 1;
public static long Dec(long i) => i - 1;
public static long Plus(long i, long j) => i + j;
public static Func<long, long> Plus(long j) => i => i + j;
public static long Minus(long i, long j) => i - j;
public static Func<long, long> Minus(long j) => i => i - j;
public static long Multiply(long i, long j) => i * j;
public static Func<long, long> Multiply(long j) => i => i * j;
public static long Divide(long i, long j) => j / j;
public static Func<long, long> Divide(long j) => i => i * j;
public static long Mod(long i, long j) => i % j;
public static Func<long, long> Mod(long j) => i => i % j;
public static long Max(params long[] ns) => ns.Max();
public static long LowerBound(this long m, long lbound) => Max(m, lbound);
public static long UpperBound(this long m, long ubound) => Min(m, ubound);
public static long Bound(this long m, long lowerBound, long UpperBound) =>
m.LowerBound(lowerBound).UpperBound(UpperBound);
public static long LowerBound(this int m, long lbound) => Max(m, lbound);
public static long UpperBound(this int m, long ubound) => Min(m, ubound);
public static long Bound(this int m, long lowerBound, long UpperBound) =>
m.LowerBound(lowerBound).UpperBound(UpperBound);
public static bool InRange(this long x, long min, long max) => min <= x
&& x <= max;
public static bool IsEven(this int x) => x % 2 == 0;
public static bool IsOdd(this int x) => x % 2 != 0;
public static bool IsEven(this long x) => x % 2 == 0;
public static bool IsOdd(this long x) => x % 2 != 0;
public static IEnumerable<int>
ToDigits(this long n) => n.ToString().Select(x => x.ToInt());
public static IEnumerable<int> ToDigits(this int n) => ((long)n).ToDigits();
public static IEnumerable<int> Factors(this int n) {
for (int i = 1; i <= n; i++)
if (n % i == 0)
yield return i;
}
public static IEnumerable<long> Factors(this long n) {
for (long i = 1; i <= n; i++)
if (n % i == 0)
yield return i;
}
public static IEnumerable<int> Natural() {
for (int i = 0;; i++)
yield return i;
}
public static IEnumerable<int> Positive() => Natural().Skip(1);
public static long Pow(this long i,
long exp) => (exp == 0) ? 1 : i * Pow(i, exp - 1);
public static long Pow(this int i,
long exp) => (exp == 0) ? 1 : i * Pow(i, exp - 1);
public static int IntLog(this long n, long baseNum) {
int count = 0;
while (n > 1) {
n /= baseNum;
count++;
}
return count;
}
}
static class Util {
public static InvalidOperationException UnreachableException =
new InvalidOperationException("unreachable.");
public static string
Show(this IEnumerable<char> source) => new string(source.ToArray());
public static HashSet<T>
ToHashSet<T>(this IEnumerable<T> source) => new HashSet<T>(source);
public static MultiSet<T>
ToMultiSet<T>(this IEnumerable<T> t) => new MultiSet<T>(t);
public static bool IsPalindrome(string s) {
for (int i = 0; i < s.Length / 2; i++) {
if (s[i] != s[s.Length - 1 - i])
return false;
}
return true;
}
public readonly static VectorInt2[] Dir8 = {
new VectorInt2(-1, -1), new VectorInt2(-1, 0), new VectorInt2(-1, 1),
new VectorInt2(0, -1), new VectorInt2(0, 1), new VectorInt2(1, -1),
new VectorInt2(1, 0), new VectorInt2(1, 1)
};
public const long MODCONST = 1000000007;
public static T debug<T>(this T value) {
Console.Error.WriteLine($"debug:{value}");
return value;
}
public static T Id<T>(T t) => t;
public static long ToLong(this String s) => long.Parse(s);
public static long ToLong(this char c) => c - '0';
public static int ToInt(this String s) => int.Parse(s);
public static int ToInt(this char c) => c - '0';
public static VectorInt2 ReadVectorInt2() => new VectorInt2(ReadInt(),
ReadInt());
public static VectorDouble2
ReadVectorDouble2() => new VectorDouble2(ReadInt(), ReadInt());
public static string ReplaceX(this string input, string pattern,
string replace) => Regex.Replace(input, pattern,
replace);
public static IEnumerable<int> Range(int i, int j) => Enumerable.Range(i, j);
public static IEnumerable<long> Range(long i, long j) {
for (long k = i; k < i + j; k++)
yield return k;
}
public static void Swap<T>(this IList<T> enumerable, int i, int j) {
var buf = enumerable[i];
enumerable[i] = enumerable[j];
enumerable[j] = buf;
}
public static bool In<T>(this T t, IEnumerable<T> range) => range.Contains(t);
}
static class ParametricExtensions {
public static Func<S, U> Then<S, T, U>(this Func<S, T> f,
Func<T, U> g) => x => g(f(x));
public static Func<S, U> Compose<S, T, U>(this Func<T, U> f,
Func<S, T> g) => x => f(g(x));
public static void Call<T>(this T t, Action<T> action) => action(t);
public static void WriteLine<T>(this T t) => Console.WriteLine(t);
public static void Write<T>(this T t) => Console.Write(t);
public static T Call<S, T>(this S s, Func<S, T> func) => func(s);
public static S Call<S>(this S s, Func<S, S> func,
int times) => times == 0
? s
: Call(func(s), func, times - 1);
}
static class StreamExtensions {
public static void ReverseRange<T>(this IList<T> enumerable, int i, int j) {
int half = (j - i) / 2;
for (int k = 0; k <= half; k++)
enumerable.Swap(i + k, j - k);
}
public static bool
isEmpty<T>(this IEnumerable<T> enumerable) => !enumerable.Any();
public static void Times(this int n, Action action) {
for (int i = 0; i < n; i++)
action();
}
public static void Times(this long n, Action action) {
for (long i = 0; i < n; i++)
action();
}
public static IEnumerable<T> Times<T>(this int n, Func<T> func) {
for (long i = 0; i < n; i++)
yield return func();
}
public static IEnumerable<T> Times<T>(this long n, Func<T> func) {
for (long i = 0; i < n; i++)
yield return func();
}
public static void ForEach<T>(this IEnumerable<T> e, Action<T> action) {
foreach (var v in e)
action(v);
}
public static long
Prod(this IEnumerable<long> source) => source.Aggregate(Multiply);
public static IEnumerable<int> FromTo(int a,
int b) => Range(a, Max(b - a + 1, 0));
public static IEnumerable<T> Repeat<T>(T t) {
while (true)
yield return t;
}
public static IEnumerable<T> Replicate<T>(int n, T t) => Repeat(t).Take(n);
public static IEnumerable<T> Cycle<T>(this IEnumerable<T> e) {
while (true)
foreach (var v in e)
yield return v;
}
public static IEnumerable<T> Scan<S, T>(this IEnumerable<S> source, T init,
Func<T, S, T> accumulator) {
var result = init;
foreach (var item in source) {
result = accumulator(result, item);
yield return result;
}
}
public static T[] ToArray<T>(params T[] ns) => ns;
public static List<T> ToList<T>(params T[] ns) => ns.ToList();
public static IEnumerable<T> Scan0<S, T>(this IEnumerable<S> source, T init,
Func<T, S, T> accumulator) {
yield return init;
foreach (var item in Scan(source, init, accumulator))
yield return item;
}
public static IEnumerable<Tuple<T1, T2>>
Cartesian<T1, T2>(IEnumerable<T1> s1,
IEnumerable<T2> s2) => from v1 in s1 from v2 in s2 select
new Tuple<T1, T2>(v1, v2);
public static IEnumerable<Tuple<T1, T2, T3>> Cartesian<T1, T2, T3>(
IEnumerable<T1> s1, IEnumerable<T2> s2,
IEnumerable<T3> s3) => from v1 in s1 from v2 in s2 from v3 in s3 select
new Tuple<T1, T2, T3>(v1, v2, v3);
public static IEnumerable<Tuple<T1, T2, T3, T4>>
Cartesian<T1, T2, T3, T4>(IEnumerable<T1> s1, IEnumerable<T2> s2,
IEnumerable<T3> s3, IEnumerable<T4> s4) =>
from v1 in s1 from v2 in s2 from v3 in s3 from v4 in s4 select
new Tuple<T1, T2, T3, T4>(v1, v2, v3, v4);
public static IEnumerable<List<T>> Buffer<T>(this IEnumerable<T> source,
int length) {
while (source.Any()) {
yield return source.Take(length).ToList();
source = source.Skip(length);
}
}
public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> selector) {
T max = source.First();
foreach (var item in source)
if (selector(item) > selector(max))
max = item;
return max;
}
public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> selector) {
T min = source.First();
foreach (var item in source)
if (selector(item) < selector(min))
min = item;
return min;
}
public static int IndexOf<T>(this IList<T> source, Func<T, bool> condition) {
for (int i = 0; i < source.Count; i++)
if (condition(source[i]))
return i;
return -1;
}
public static IEnumerable<List<T>> ChunkBy<T>(this IEnumerable<T> source) =>
ChunkBy(source, Id, EqualityComparer<T>.Default);
public static IEnumerable<List<T>> ChunkBy<S, T>(this IEnumerable<T> source,
Func<T, S> selector) =>
ChunkBy(source, selector, EqualityComparer<S>.Default);
public static IEnumerable<List<T>>
ChunkBy<S, T>(this IEnumerable<T> source, Func<T, S> selector,
IEqualityComparer<S> comparer) {
while (source.Any()) {
var v = selector(source.First());
var l = source.TakeWhile(x => comparer.Equals(selector(x), v)).ToList();
yield return l;
source = source.Skip(l.Count());
}
}
}
static class Matrix {
public static List<List<T>> Transpose<T>(this List<List<T>> source) =>
Range(0, source[0].Count)
.Select(i => source.Select(x => x[i]).ToList())
.ToList();
public static void WriteMatrix(this IEnumerable<IEnumerable<char>> source) {
foreach (var line in source)
line.Show().WriteLine();
}
public static List<List<long>>
ReadLongMatrix(int h, int w) => h.Times(() => ReadLong(w)).ToList();
public static List<List<T>> SelectMatrix<S, T>(this List<List<S>> source,
Func<S, T> f) =>
source.Select(x => x.Select(f).ToList()).ToList();
}
static class Cin {
private static Queue<string> tokens;
static Cin() {
string line;
tokens = new Queue<string>();
while ((line = Console.ReadLine()) != null) {
foreach (var token in line.Split(' ')) {
tokens.Enqueue(token);
}
}
}
static public int ReadInt() => int.Parse(tokens.Dequeue());
static public List<int> ReadInt(long n) {
var list = new List<int>();
n.Times(() => list.Add(ReadInt()));
return list;
}
static public long ReadLong() => long.Parse(tokens.Dequeue());
static public List<long> ReadLong(long n) {
var list = new List<long>();
n.Times(() => list.Add(ReadLong()));
return list;
}
static public string ReadString() => tokens.Dequeue();
static public List<string> ReadString(long n) {
var list = new List<string>();
n.Times(() => list.Add(ReadString()));
return list;
}
static public void SayYesNo(this bool b) => (b ? "Yes" : "No").WriteLine();
static public void SayYESNO(this bool b) => (b ? "YES" : "NO").WriteLine();
}
public struct VectorInt2 {
public int X { get; set; }
public int Y { get; set; }
public VectorInt2(int x, int y) {
X = x;
Y = y;
}
static public VectorInt2 operator +(VectorInt2 v1, VectorInt2 v2) =>
new VectorInt2(v1.X + v2.X, v1.Y + v2.Y);
static public VectorInt2 operator -(VectorInt2 v1, VectorInt2 v2) =>
new VectorInt2(v1.X - v2.X, v1.Y - v2.Y);
static public VectorInt2 operator *(VectorInt2 v1, VectorInt2 v2) =>
new VectorInt2(v1.X * v2.X, v1.Y *v2.Y);
static public VectorInt2
operator *(VectorInt2 v1, int i) => new VectorInt2(v1.X * i, v1.Y *i);
static public VectorInt2
operator *(int i, VectorInt2 v2) => new VectorInt2(i * v2.X, i *v2.Y);
static public VectorInt2
operator /(VectorInt2 v1, int i) => new VectorInt2(v1.X / i, v1.Y / i);
public override string ToString() => $"({X}, {Y})";
}
struct VectorDouble2 {
public double X { get; set; }
public double Y { get; set; }
public VectorDouble2(double x, double y) {
X = x;
Y = y;
}
static public VectorDouble2 operator +(VectorDouble2 v1, VectorDouble2 v2) =>
new VectorDouble2(v1.X + v2.X, v1.Y + v2.Y);
static public VectorDouble2 operator -(VectorDouble2 v1, VectorDouble2 v2) =>
new VectorDouble2(v1.X - v2.X, v1.Y - v2.Y);
static public VectorDouble2 operator *(VectorDouble2 v1, VectorDouble2 v2) =>
new VectorDouble2(v1.X * v2.X, v1.Y *v2.Y);
static public VectorDouble2
operator *(VectorDouble2 v1, int i) => new VectorDouble2(v1.X * i, v1.Y *i);
static public VectorDouble2
operator *(int i, VectorDouble2 v2) => new VectorDouble2(i * v2.X, i *v2.Y);
static public VectorDouble2 operator /(VectorDouble2 v1, double i) =>
new VectorDouble2(v1.X / i, v1.Y / i);
public override string ToString() => $"({X}, {Y})";
public VectorDouble2
Turn(double radian) => new VectorDouble2(X * Cos(radian) - Y * Sin(radian),
X *Sin(radian) + Y * Cos(radian));
}
public struct LongRange {
public long Left;
public long Right;
public LongRange(long left, long right) {
Left = left;
Right = right;
}
}
public struct LongFromToVector {
public VectorInt2 Start;
public VectorInt2 End;
public LongFromToVector(VectorInt2 start, VectorInt2 end) {
Start = start;
End = end;
}
}
}
namespace AtCoder {
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System;
class MultiSet<T> : ICollection<T> {
// TODO: 順番がグチャグチャなので整理する
Dictionary<T, int> occurrence;
public MultiSet(MultiSet<T> source) : this(source.occurrence) {}
public MultiSet(Dictionary<T, int> source) {
occurrence = new Dictionary<T, int>(source);
Validate();
}
public MultiSet(IEnumerable<T> source) {
occurrence = new Dictionary<T, int>();
AddRange(source);
}
public void Add(T data) {
if (!occurrence.ContainsKey(data)) {
occurrence[data] = 1;
return;
}
occurrence[data]++;
}
public void Clear() => occurrence.Clear();
public void Add(T key, int value) {
if (value <= 0)
throw new ArgumentException();
if (!occurrence.ContainsKey(key)) {
occurrence[key] = value;
return;
}
occurrence[key] += value;
}
public void Add(KeyValuePair<T, int> pair) => Add(pair.Key, pair.Value);
public void AddRange(IEnumerable<T> source) => source.ToList().ForEach(Add);
public bool Remove(T data) {
if (!occurrence.ContainsKey(data))
return false;
occurrence[data]--;
if (occurrence[data] == 0)
occurrence.Remove(data);
return true;
}
// IDictionary
public int this[T key] {
get { return occurrence.ContainsKey(key) ? occurrence[key] : 0; }
set {
if (value <= 0)
throw new ArgumentException();
occurrence[key] = value;
}
}
public ICollection<T> Keys {
get { return occurrence.Keys; }
}
public ICollection<int> Values {
get { return occurrence.Values; }
}
public bool ContainsKey(T key) => occurrence.ContainsKey(key);
public bool Contains(T key) => ContainsKey(key);
public bool TryGetValue(T key, out int value) {
value = this[key];
return true;
}
// /IDictionary
public int Count => occurrence.Values.Sum();
public bool IsReadOnly => false;
public void CopyTo(T[] array, int index) {
foreach (var pair in occurrence) {
for (int i = 0; i < pair.Value; i++) {
array[index] = pair.Key;
index++;
}
}
}
public IEnumerator<T> GetEnumerator() {
foreach (var pair in occurrence)
for (int i = 0; i < pair.Value; i++)
yield return pair.Key;
}
IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
public void Validate() {
if (occurrence.Values.Any(x => x <= 0))
throw new ArgumentException();
}
}
class SortedMultiSet<T> : ICollection<T> {
// TODO: 順番がグチャグチャなので整理する
SortedDictionary<T, int> occurrence;
public SortedMultiSet(SortedMultiSet<T> source) : this(source.occurrence) {}
public SortedMultiSet(SortedDictionary<T, int> source) {
occurrence = new SortedDictionary<T, int>(source);
Validate();
}
public SortedMultiSet(IEnumerable<T> source) {
occurrence = new SortedDictionary<T, int>();
AddRange(source);
}
public void Add(T data) {
if (!occurrence.ContainsKey(data)) {
occurrence[data] = 1;
return;
}
occurrence[data]++;
}
public void Clear() => occurrence.Clear();
public void Add(T key, int value) {
if (value <= 0)
throw new ArgumentException();
if (!occurrence.ContainsKey(key)) {
occurrence[key] = value;
return;
}
occurrence[key] += value;
}
public T Max() => occurrence.Max().Key;
public T Min() => occurrence.Min().Key;
public void Add(KeyValuePair<T, int> pair) => Add(pair.Key, pair.Value);
public void AddRange(IEnumerable<T> source) => source.ToList().ForEach(Add);
public bool Remove(T data) {
if (!occurrence.ContainsKey(data))
return false;
occurrence[data]--;
if (occurrence[data] == 0)
occurrence.Remove(data);
return true;
}
// IDictionary
public int this[T key] {
get { return occurrence.ContainsKey(key) ? occurrence[key] : 0; }
set {
if (value <= 0)
throw new ArgumentException();
occurrence[key] = value;
}
}
public ICollection<T> Keys => occurrence.Keys;
public ICollection<int> Values => occurrence.Values;
public bool ContainsKey(T key) => occurrence.ContainsKey(key);
public bool Contains(T key) => ContainsKey(key);
public bool TryGetValue(T key, out int value) {
value = this[key];
return true;
}
// /IDictionary
public int Count => occurrence.Values.Sum();
public bool IsReadOnly => false;
public void CopyTo(T[] array, int index) {
foreach (var pair in occurrence) {
for (int i = 0; i < pair.Value; i++) {
array[index] = pair.Key;
index++;
}
}
}
public IEnumerator<T> GetEnumerator() {
foreach (var pair in occurrence)
for (int i = 0; i < pair.Value; i++)
yield return pair.Key;
}
IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
public void Validate() {
if (occurrence.Values.Any(x => x <= 0))
throw new ArgumentException();
}
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
// using static System.Linq.Enumerable;
using static System.Console;
using static AtCoder.Util;
using static AtCoder.Cin;
using static System.Math;
using static AtCoder.MyMath;
using static AtCoder.StreamExtensions;
using static AtCoder.Matrix;
namespace AtCoder {
using VI = VectorInt2;
static class Program {
static void Main() {
int n = ReadInt();
long k = ReadLong();
var list = new SortedDictionary<int, long>();
for (int i = 0; i < n; i++) {
int key = ReadInt();
int vla = ReadInt();
if (list.ContainsKey(key)) {
list[key] += vla;
} else {
list[key] = vla;
}
}
long u = 0;
foreach (var s in list) {
u = s.Value;
if (u >= k) {
Console.WriteLine(s.Key);
break;
} else {
k -= u;
}
}
}
}
}
/* ***************** Following Contents are my common library ******** */
namespace AtCoder {
static class Algorithm {
public static LongRange BinSearch(LongRange range, Func<long, bool> isBigger,
long width) =>
BinSearch(range, isBigger, x => range.Right - range.Left < width);
public static LongRange BinSearch(LongRange range, Func<long, bool> isBigger,
Func<LongRange, bool> stopCondition) {
if (stopCondition(range))
return range;
var middle = range.Left + (range.Right - range.Left) / 2;
return isBigger(middle) ? BinSearch(new LongRange(range.Left, middle),
isBigger, stopCondition)
: BinSearch(new LongRange(middle, range.Right),
isBigger, stopCondition);
}
}
static class MyMath {
public static long GCD(long a,
long b) => a<b? GCD(b, a) : b> 0 ? GCD(b, a % b) : a;
public static long Factorial(this long n) => Range(1, n).Aggregate(1L,
Multiply);
public static long nPr(int n, int r) => r < 0 || r > n? 0
: FromTo(n - r + 1, n)
.Select(x => (long)x)
.Aggregate(1L, Multiply);
public static long nCr(int n, int r) => nPr(n, r) / Factorial(r);
public static long Inc(long i) => i + 1;
public static long Dec(long i) => i - 1;
public static long Plus(long i, long j) => i + j;
public static Func<long, long> Plus(long j) => i => i + j;
public static long Minus(long i, long j) => i - j;
public static Func<long, long> Minus(long j) => i => i - j;
public static long Multiply(long i, long j) => i * j;
public static Func<long, long> Multiply(long j) => i => i * j;
public static long Divide(long i, long j) => j / j;
public static Func<long, long> Divide(long j) => i => i * j;
public static long Mod(long i, long j) => i % j;
public static Func<long, long> Mod(long j) => i => i % j;
public static long Max(params long[] ns) => ns.Max();
public static long LowerBound(this long m, long lbound) => Max(m, lbound);
public static long UpperBound(this long m, long ubound) => Min(m, ubound);
public static long Bound(this long m, long lowerBound, long UpperBound) =>
m.LowerBound(lowerBound).UpperBound(UpperBound);
public static long LowerBound(this int m, long lbound) => Max(m, lbound);
public static long UpperBound(this int m, long ubound) => Min(m, ubound);
public static long Bound(this int m, long lowerBound, long UpperBound) =>
m.LowerBound(lowerBound).UpperBound(UpperBound);
public static bool InRange(this long x, long min, long max) => min <= x
&& x <= max;
public static bool IsEven(this int x) => x % 2 == 0;
public static bool IsOdd(this int x) => x % 2 != 0;
public static bool IsEven(this long x) => x % 2 == 0;
public static bool IsOdd(this long x) => x % 2 != 0;
public static IEnumerable<int>
ToDigits(this long n) => n.ToString().Select(x => x.ToInt());
public static IEnumerable<int> ToDigits(this int n) => ((long)n).ToDigits();
public static IEnumerable<int> Factors(this int n) {
for (int i = 1; i <= n; i++)
if (n % i == 0)
yield return i;
}
public static IEnumerable<long> Factors(this long n) {
for (long i = 1; i <= n; i++)
if (n % i == 0)
yield return i;
}
public static IEnumerable<int> Natural() {
for (int i = 0;; i++)
yield return i;
}
public static IEnumerable<int> Positive() => Natural().Skip(1);
public static long Pow(this long i,
long exp) => (exp == 0) ? 1 : i * Pow(i, exp - 1);
public static long Pow(this int i,
long exp) => (exp == 0) ? 1 : i * Pow(i, exp - 1);
public static int IntLog(this long n, long baseNum) {
int count = 0;
while (n > 1) {
n /= baseNum;
count++;
}
return count;
}
}
static class Util {
public static InvalidOperationException UnreachableException =
new InvalidOperationException("unreachable.");
public static string
Show(this IEnumerable<char> source) => new string(source.ToArray());
public static HashSet<T>
ToHashSet<T>(this IEnumerable<T> source) => new HashSet<T>(source);
public static MultiSet<T>
ToMultiSet<T>(this IEnumerable<T> t) => new MultiSet<T>(t);
public static bool IsPalindrome(string s) {
for (int i = 0; i < s.Length / 2; i++) {
if (s[i] != s[s.Length - 1 - i])
return false;
}
return true;
}
public readonly static VectorInt2[] Dir8 = {
new VectorInt2(-1, -1), new VectorInt2(-1, 0), new VectorInt2(-1, 1),
new VectorInt2(0, -1), new VectorInt2(0, 1), new VectorInt2(1, -1),
new VectorInt2(1, 0), new VectorInt2(1, 1)
};
public const long MODCONST = 1000000007;
public static T debug<T>(this T value) {
Console.Error.WriteLine($"debug:{value}");
return value;
}
public static T Id<T>(T t) => t;
public static long ToLong(this String s) => long.Parse(s);
public static long ToLong(this char c) => c - '0';
public static int ToInt(this String s) => int.Parse(s);
public static int ToInt(this char c) => c - '0';
public static VectorInt2 ReadVectorInt2() => new VectorInt2(ReadInt(),
ReadInt());
public static VectorDouble2
ReadVectorDouble2() => new VectorDouble2(ReadInt(), ReadInt());
public static string ReplaceX(this string input, string pattern,
string replace) => Regex.Replace(input, pattern,
replace);
public static IEnumerable<int> Range(int i, int j) => Enumerable.Range(i, j);
public static IEnumerable<long> Range(long i, long j) {
for (long k = i; k < i + j; k++)
yield return k;
}
public static void Swap<T>(this IList<T> enumerable, int i, int j) {
var buf = enumerable[i];
enumerable[i] = enumerable[j];
enumerable[j] = buf;
}
public static bool In<T>(this T t, IEnumerable<T> range) => range.Contains(t);
}
static class ParametricExtensions {
public static Func<S, U> Then<S, T, U>(this Func<S, T> f,
Func<T, U> g) => x => g(f(x));
public static Func<S, U> Compose<S, T, U>(this Func<T, U> f,
Func<S, T> g) => x => f(g(x));
public static void Call<T>(this T t, Action<T> action) => action(t);
public static void WriteLine<T>(this T t) => Console.WriteLine(t);
public static void Write<T>(this T t) => Console.Write(t);
public static T Call<S, T>(this S s, Func<S, T> func) => func(s);
public static S Call<S>(this S s, Func<S, S> func,
int times) => times == 0
? s
: Call(func(s), func, times - 1);
}
static class StreamExtensions {
public static void ReverseRange<T>(this IList<T> enumerable, int i, int j) {
int half = (j - i) / 2;
for (int k = 0; k <= half; k++)
enumerable.Swap(i + k, j - k);
}
public static bool
isEmpty<T>(this IEnumerable<T> enumerable) => !enumerable.Any();
public static void Times(this int n, Action action) {
for (int i = 0; i < n; i++)
action();
}
public static void Times(this long n, Action action) {
for (long i = 0; i < n; i++)
action();
}
public static IEnumerable<T> Times<T>(this int n, Func<T> func) {
for (long i = 0; i < n; i++)
yield return func();
}
public static IEnumerable<T> Times<T>(this long n, Func<T> func) {
for (long i = 0; i < n; i++)
yield return func();
}
public static void ForEach<T>(this IEnumerable<T> e, Action<T> action) {
foreach (var v in e)
action(v);
}
public static long
Prod(this IEnumerable<long> source) => source.Aggregate(Multiply);
public static IEnumerable<int> FromTo(int a,
int b) => Range(a, Max(b - a + 1, 0));
public static IEnumerable<T> Repeat<T>(T t) {
while (true)
yield return t;
}
public static IEnumerable<T> Replicate<T>(int n, T t) => Repeat(t).Take(n);
public static IEnumerable<T> Cycle<T>(this IEnumerable<T> e) {
while (true)
foreach (var v in e)
yield return v;
}
public static IEnumerable<T> Scan<S, T>(this IEnumerable<S> source, T init,
Func<T, S, T> accumulator) {
var result = init;
foreach (var item in source) {
result = accumulator(result, item);
yield return result;
}
}
public static T[] ToArray<T>(params T[] ns) => ns;
public static List<T> ToList<T>(params T[] ns) => ns.ToList();
public static IEnumerable<T> Scan0<S, T>(this IEnumerable<S> source, T init,
Func<T, S, T> accumulator) {
yield return init;
foreach (var item in Scan(source, init, accumulator))
yield return item;
}
public static IEnumerable<Tuple<T1, T2>>
Cartesian<T1, T2>(IEnumerable<T1> s1,
IEnumerable<T2> s2) => from v1 in s1 from v2 in s2 select
new Tuple<T1, T2>(v1, v2);
public static IEnumerable<Tuple<T1, T2, T3>> Cartesian<T1, T2, T3>(
IEnumerable<T1> s1, IEnumerable<T2> s2,
IEnumerable<T3> s3) => from v1 in s1 from v2 in s2 from v3 in s3 select
new Tuple<T1, T2, T3>(v1, v2, v3);
public static IEnumerable<Tuple<T1, T2, T3, T4>>
Cartesian<T1, T2, T3, T4>(IEnumerable<T1> s1, IEnumerable<T2> s2,
IEnumerable<T3> s3, IEnumerable<T4> s4) =>
from v1 in s1 from v2 in s2 from v3 in s3 from v4 in s4 select
new Tuple<T1, T2, T3, T4>(v1, v2, v3, v4);
public static IEnumerable<List<T>> Buffer<T>(this IEnumerable<T> source,
int length) {
while (source.Any()) {
yield return source.Take(length).ToList();
source = source.Skip(length);
}
}
public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> selector) {
T max = source.First();
foreach (var item in source)
if (selector(item) > selector(max))
max = item;
return max;
}
public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> selector) {
T min = source.First();
foreach (var item in source)
if (selector(item) < selector(min))
min = item;
return min;
}
public static int IndexOf<T>(this IList<T> source, Func<T, bool> condition) {
for (int i = 0; i < source.Count; i++)
if (condition(source[i]))
return i;
return -1;
}
public static IEnumerable<List<T>> ChunkBy<T>(this IEnumerable<T> source) =>
ChunkBy(source, Id, EqualityComparer<T>.Default);
public static IEnumerable<List<T>> ChunkBy<S, T>(this IEnumerable<T> source,
Func<T, S> selector) =>
ChunkBy(source, selector, EqualityComparer<S>.Default);
public static IEnumerable<List<T>>
ChunkBy<S, T>(this IEnumerable<T> source, Func<T, S> selector,
IEqualityComparer<S> comparer) {
while (source.Any()) {
var v = selector(source.First());
var l = source.TakeWhile(x => comparer.Equals(selector(x), v)).ToList();
yield return l;
source = source.Skip(l.Count());
}
}
}
static class Matrix {
public static List<List<T>> Transpose<T>(this List<List<T>> source) =>
Range(0, source[0].Count)
.Select(i => source.Select(x => x[i]).ToList())
.ToList();
public static void WriteMatrix(this IEnumerable<IEnumerable<char>> source) {
foreach (var line in source)
line.Show().WriteLine();
}
public static List<List<long>>
ReadLongMatrix(int h, int w) => h.Times(() => ReadLong(w)).ToList();
public static List<List<T>> SelectMatrix<S, T>(this List<List<S>> source,
Func<S, T> f) =>
source.Select(x => x.Select(f).ToList()).ToList();
}
static class Cin {
private static Queue<string> tokens;
static Cin() {
string line;
tokens = new Queue<string>();
while ((line = Console.ReadLine()) != null) {
foreach (var token in line.Split(' ')) {
tokens.Enqueue(token);
}
}
}
static public int ReadInt() => int.Parse(tokens.Dequeue());
static public List<int> ReadInt(long n) {
var list = new List<int>();
n.Times(() => list.Add(ReadInt()));
return list;
}
static public long ReadLong() => long.Parse(tokens.Dequeue());
static public List<long> ReadLong(long n) {
var list = new List<long>();
n.Times(() => list.Add(ReadLong()));
return list;
}
static public string ReadString() => tokens.Dequeue();
static public List<string> ReadString(long n) {
var list = new List<string>();
n.Times(() => list.Add(ReadString()));
return list;
}
static public void SayYesNo(this bool b) => (b ? "Yes" : "No").WriteLine();
static public void SayYESNO(this bool b) => (b ? "YES" : "NO").WriteLine();
}
public struct VectorInt2 {
public int X { get; set; }
public int Y { get; set; }
public VectorInt2(int x, int y) {
X = x;
Y = y;
}
static public VectorInt2 operator +(VectorInt2 v1, VectorInt2 v2) =>
new VectorInt2(v1.X + v2.X, v1.Y + v2.Y);
static public VectorInt2 operator -(VectorInt2 v1, VectorInt2 v2) =>
new VectorInt2(v1.X - v2.X, v1.Y - v2.Y);
static public VectorInt2 operator *(VectorInt2 v1, VectorInt2 v2) =>
new VectorInt2(v1.X * v2.X, v1.Y *v2.Y);
static public VectorInt2
operator *(VectorInt2 v1, int i) => new VectorInt2(v1.X * i, v1.Y *i);
static public VectorInt2
operator *(int i, VectorInt2 v2) => new VectorInt2(i * v2.X, i *v2.Y);
static public VectorInt2
operator /(VectorInt2 v1, int i) => new VectorInt2(v1.X / i, v1.Y / i);
public override string ToString() => $"({X}, {Y})";
}
struct VectorDouble2 {
public double X { get; set; }
public double Y { get; set; }
public VectorDouble2(double x, double y) {
X = x;
Y = y;
}
static public VectorDouble2 operator +(VectorDouble2 v1, VectorDouble2 v2) =>
new VectorDouble2(v1.X + v2.X, v1.Y + v2.Y);
static public VectorDouble2 operator -(VectorDouble2 v1, VectorDouble2 v2) =>
new VectorDouble2(v1.X - v2.X, v1.Y - v2.Y);
static public VectorDouble2 operator *(VectorDouble2 v1, VectorDouble2 v2) =>
new VectorDouble2(v1.X * v2.X, v1.Y *v2.Y);
static public VectorDouble2
operator *(VectorDouble2 v1, int i) => new VectorDouble2(v1.X * i, v1.Y *i);
static public VectorDouble2
operator *(int i, VectorDouble2 v2) => new VectorDouble2(i * v2.X, i *v2.Y);
static public VectorDouble2 operator /(VectorDouble2 v1, double i) =>
new VectorDouble2(v1.X / i, v1.Y / i);
public override string ToString() => $"({X}, {Y})";
public VectorDouble2
Turn(double radian) => new VectorDouble2(X * Cos(radian) - Y * Sin(radian),
X *Sin(radian) + Y * Cos(radian));
}
public struct LongRange {
public long Left;
public long Right;
public LongRange(long left, long right) {
Left = left;
Right = right;
}
}
public struct LongFromToVector {
public VectorInt2 Start;
public VectorInt2 End;
public LongFromToVector(VectorInt2 start, VectorInt2 end) {
Start = start;
End = end;
}
}
}
namespace AtCoder {
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System;
class MultiSet<T> : ICollection<T> {
// TODO: 順番がグチャグチャなので整理する
Dictionary<T, int> occurrence;
public MultiSet(MultiSet<T> source) : this(source.occurrence) {}
public MultiSet(Dictionary<T, int> source) {
occurrence = new Dictionary<T, int>(source);
Validate();
}
public MultiSet(IEnumerable<T> source) {
occurrence = new Dictionary<T, int>();
AddRange(source);
}
public void Add(T data) {
if (!occurrence.ContainsKey(data)) {
occurrence[data] = 1;
return;
}
occurrence[data]++;
}
public void Clear() => occurrence.Clear();
public void Add(T key, int value) {
if (value <= 0)
throw new ArgumentException();
if (!occurrence.ContainsKey(key)) {
occurrence[key] = value;
return;
}
occurrence[key] += value;
}
public void Add(KeyValuePair<T, int> pair) => Add(pair.Key, pair.Value);
public void AddRange(IEnumerable<T> source) => source.ToList().ForEach(Add);
public bool Remove(T data) {
if (!occurrence.ContainsKey(data))
return false;
occurrence[data]--;
if (occurrence[data] == 0)
occurrence.Remove(data);
return true;
}
// IDictionary
public int this[T key] {
get { return occurrence.ContainsKey(key) ? occurrence[key] : 0; }
set {
if (value <= 0)
throw new ArgumentException();
occurrence[key] = value;
}
}
public ICollection<T> Keys {
get { return occurrence.Keys; }
}
public ICollection<int> Values {
get { return occurrence.Values; }
}
public bool ContainsKey(T key) => occurrence.ContainsKey(key);
public bool Contains(T key) => ContainsKey(key);
public bool TryGetValue(T key, out int value) {
value = this[key];
return true;
}
// /IDictionary
public int Count => occurrence.Values.Sum();
public bool IsReadOnly => false;
public void CopyTo(T[] array, int index) {
foreach (var pair in occurrence) {
for (int i = 0; i < pair.Value; i++) {
array[index] = pair.Key;
index++;
}
}
}
public IEnumerator<T> GetEnumerator() {
foreach (var pair in occurrence)
for (int i = 0; i < pair.Value; i++)
yield return pair.Key;
}
IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
public void Validate() {
if (occurrence.Values.Any(x => x <= 0))
throw new ArgumentException();
}
}
class SortedMultiSet<T> : ICollection<T> {
// TODO: 順番がグチャグチャなので整理する
SortedDictionary<T, int> occurrence;
public SortedMultiSet(SortedMultiSet<T> source) : this(source.occurrence) {}
public SortedMultiSet(SortedDictionary<T, int> source) {
occurrence = new SortedDictionary<T, int>(source);
Validate();
}
public SortedMultiSet(IEnumerable<T> source) {
occurrence = new SortedDictionary<T, int>();
AddRange(source);
}
public void Add(T data) {
if (!occurrence.ContainsKey(data)) {
occurrence[data] = 1;
return;
}
occurrence[data]++;
}
public void Clear() => occurrence.Clear();
public void Add(T key, int value) {
if (value <= 0)
throw new ArgumentException();
if (!occurrence.ContainsKey(key)) {
occurrence[key] = value;
return;
}
occurrence[key] += value;
}
public T Max() => occurrence.Max().Key;
public T Min() => occurrence.Min().Key;
public void Add(KeyValuePair<T, int> pair) => Add(pair.Key, pair.Value);
public void AddRange(IEnumerable<T> source) => source.ToList().ForEach(Add);
public bool Remove(T data) {
if (!occurrence.ContainsKey(data))
return false;
occurrence[data]--;
if (occurrence[data] == 0)
occurrence.Remove(data);
return true;
}
// IDictionary
public int this[T key] {
get { return occurrence.ContainsKey(key) ? occurrence[key] : 0; }
set {
if (value <= 0)
throw new ArgumentException();
occurrence[key] = value;
}
}
public ICollection<T> Keys => occurrence.Keys;
public ICollection<int> Values => occurrence.Values;
public bool ContainsKey(T key) => occurrence.ContainsKey(key);
public bool Contains(T key) => ContainsKey(key);
public bool TryGetValue(T key, out int value) {
value = this[key];
return true;
}
// /IDictionary
public int Count => occurrence.Values.Sum();
public bool IsReadOnly => false;
public void CopyTo(T[] array, int index) {
foreach (var pair in occurrence) {
for (int i = 0; i < pair.Value; i++) {
array[index] = pair.Key;
index++;
}
}
}
public IEnumerator<T> GetEnumerator() {
foreach (var pair in occurrence)
for (int i = 0; i < pair.Value; i++)
yield return pair.Key;
}
IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
public void Validate() {
if (occurrence.Values.Any(x => x <= 0))
throw new ArgumentException();
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 104], ["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73]]
| 8
| 5,539
| 34
|
using System;
using System.Collections.Generic;
class Program {
static void Main() {
int[] s = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
var hs = new Dictionary<int, int>();
for (int i = 0; i < s[0]; i++) {
int[] q = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
if (hs.ContainsKey(q[0])) {
hs[q[0]] += q[1];
} else {
hs.Add(q[0], q[1]);
}
}
List<int> kl = new List<int>(hs.Keys);
kl.Sort();
foreach (int k in kl) {
s[1] -= hs[k];
if (s[1] < 1) {
Console.WriteLine("{0}", k);
break;
}
}
}
}
|
using System;
using System.Collections.Generic;
class Program {
static void Main() {
long[] s = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
var hs = new Dictionary<long, long>();
for (int i = 0; i < s[0]; i++) {
long[] q = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
if (hs.ContainsKey(q[0])) {
hs[q[0]] += q[1];
} else {
hs.Add(q[0], q[1]);
}
}
List<long> kl = new List<long>(hs.Keys);
kl.Sort();
foreach (long k in kl) {
s[1] -= hs[k];
if (s[1] < 1) {
Console.WriteLine("{0}", k);
break;
}
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 39, 199], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 39, 199]]
| 8
| 212
| 18
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AtCoder {
class Program {
private const int MODULO = 1000000007;
private static string Read() { return Console.ReadLine(); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
static int Solve(int N, int K, Tuple<int, int>[] tuples) {
Array.Sort(tuples);
foreach (var tuple in tuples) {
if (K <= tuple.Item2) {
return tuple.Item1;
}
K -= tuple.Item2;
}
return tuples.Last().Item1;
}
static void Main(string[] args) {
int[] v1 = ReadInts();
int N = v1[0];
int K = v1[1];
var tuples = new Tuple<int, int>[N];
for (int i = 0; i < N; ++i) {
int[] v2 = ReadInts();
tuples[i] = new Tuple<int, int>(v2[0], v2[1]);
}
Console.WriteLine(Solve(N, K, tuples));
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AtCoder {
class Program {
private const int MODULO = 1000000007;
private static string Read() { return Console.ReadLine(); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
static int Solve(int N, long K, Tuple<int, int>[] tuples) {
Array.Sort(tuples);
foreach (var tuple in tuples) {
if (K <= tuple.Item2) {
return tuple.Item1;
}
K -= tuple.Item2;
}
return tuples.Last().Item1;
}
static void Main(string[] args) {
long[] v1 = ReadLongs();
int N = (int)v1[0];
long K = v1[1];
var tuples = new Tuple<int, int>[N];
for (int i = 0; i < N; ++i) {
int[] v2 = ReadInts();
tuples[i] = new Tuple<int, int>(v2[0], v2[1]);
}
Console.WriteLine(Solve(N, K, tuples));
}
}
}
|
[["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
| 8
| 369
| 11
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST {
static void Main() {
Sol mySol = new Sol();
mySol.Solve();
}
}
class Sol {
public void Solve() {
long tot = 0;
for (int i = 0; i < N; i++) {
tot += B[i];
if (tot < K)
continue;
Console.WriteLine(A[i]);
break;
}
}
int N;
long K;
long[] A, B;
public Sol() {
var dd = rla();
N = (int)dd[0];
K = dd[1];
A = new long[N];
B = new long[N];
for (int i = 0; i < N; i++) {
var d = ria();
A[i] = d[0];
B[i] = d[1];
}
}
static String rs() { return Console.ReadLine(); }
static int ri() { return int.Parse(Console.ReadLine()); }
static long rl() { return long.Parse(Console.ReadLine()); }
static double rd() { return double.Parse(Console.ReadLine()); }
static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
static int[] ria(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e));
}
static long[] rla(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e));
}
static double[] rda(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep),
e => double.Parse(e));
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST {
static void Main() {
Sol mySol = new Sol();
mySol.Solve();
}
}
class Sol {
public void Solve() {
long tot = 0;
Array.Sort(A, B);
for (int i = 0; i < N; i++) {
tot += B[i];
if (tot < K)
continue;
Console.WriteLine(A[i]);
break;
}
}
int N;
long K;
long[] A, B;
public Sol() {
var dd = rla();
N = (int)dd[0];
K = dd[1];
A = new long[N];
B = new long[N];
for (int i = 0; i < N; i++) {
var d = ria();
A[i] = d[0];
B[i] = d[1];
}
}
static String rs() { return Console.ReadLine(); }
static int ri() { return int.Parse(Console.ReadLine()); }
static long rl() { return long.Parse(Console.ReadLine()); }
static double rd() { return double.Parse(Console.ReadLine()); }
static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
static int[] ria(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e));
}
static long[] rla(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e));
}
static double[] rda(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep),
e => double.Parse(e));
}
}
|
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
| 8
| 432
| 9
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
int N = x[0];
int K = x[1];
// list
int[] A = new int[N];
int[] B = new int[N];
int[] y = new int[2];
for (int i = 0; i < N; i++) {
y = Console.ReadLine().Split().Select(int.Parse).ToArray();
A[i] = y[0];
B[i] = y[1];
}
Array.Sort(A, B);
int ans = -1;
int sum = 0;
for (int i = 0; i < N; i++) {
sum += B[i];
if (sum >= K) {
ans = A[i];
break;
}
}
Console.WriteLine(ans);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray();
long N = x[0];
long K = x[1];
// list
long[] A = new long[N];
long[] B = new long[N];
int[] y = new int[2];
for (long i = 0; i < N; i++) {
y = Console.ReadLine().Split().Select(int.Parse).ToArray();
A[i] = y[0];
B[i] = y[1];
}
Array.Sort(A, B);
long ans = -1;
long sum = 0;
for (int i = 0; i < N; i++) {
sum += B[i];
if (sum >= K) {
ans = A[i];
break;
}
}
Console.WriteLine(ans);
}
}
}
|
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 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, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199]]
| 8
| 248
| 22
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace Program {
class MainClass {
// C#Lover///////////////////////////////////////////////////
int N, K;
// int[] A,B;
Tuple<int, int>[] AB;
void Solve() {
io.i(out N, out K);
AB = new Tuple<int, int>[N];
N.REP(i => AB[i] = Tuple.Create(io.Int, io.Int));
Array.Sort(AB);
int ans = AB[N - 1].Item1;
for (long i = 0, sumK = 0;; i++) {
sumK += AB[i].Item2;
if (sumK >= K) {
ans = AB[i].Item1;
break;
}
}
io.o(ans);
}
////////////////////////////////////////////////////////////
public static void Main(string[] args) { new MainClass().Stream(); }
IO io = new IO();
void Stream() {
Solve();
io.writeFlush();
}
// void Stream() { Test(); io.writeFlush(); }
void Test() {}
#region MockMacro
// Hack Update
// cannot use break,continue,goto
void FOR(int a, int b, Action<int> act) {
for (int i = a; i < b; i++)
act(i);
}
void REP(int n, Action<int> act) {
for (int i = 0; i < n; i++)
act(i);
}
#endregion
}
#region default
class IO {
TYPE tp;
string[] nextBuffer;
int BufferCnt;
char[] cs = new char[] { ' ' };
StreamWriter sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
public IO() {
nextBuffer = new string[0];
BufferCnt = 0;
Console.SetOut(sw);
tp = new TYPE();
}
public string Next() {
if (BufferCnt < nextBuffer.Length)
return nextBuffer[BufferCnt++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
BufferCnt = 0;
return nextBuffer[BufferCnt++];
}
public string String => Next();
public char Char => char.Parse(String);
public int Int => int.Parse(String);
public long Long => long.Parse(String);
public double Double => double.Parse(String);
public string[] arr => Console.ReadLine().Split(' ');
public char[] arrChar => Array.ConvertAll(arr, char.Parse);
public int[] arrInt => Array.ConvertAll(arr, int.Parse);
public long[] arrLong => Array.ConvertAll(arr, long.Parse);
public double[] arrDouble => Array.ConvertAll(arr, double.Parse);
public T i<T>() { return tp.suitType<T>(String); }
public void i<T>(out T v) { v = tp.suitType<T>(String); }
public void i<T, U>(out T v1, out U v2) {
i(out v1);
i(out v2);
}
public void i<T, U, V>(out T v1, out U v2, out V v3) {
i(out v1);
i(out v2);
i(out v3);
}
public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) {
i(out v1);
i(out v2);
i(out v3);
i(out v4);
}
public void i<T, U, V, W, X>(out T v1, out U v2, out V v3, out W v4,
out X v5) {
i(out v1);
i(out v2);
i(out v3);
i(out v4);
i(out v5);
}
public void ini<T>(out T[] a, int n) {
a = new T[n];
for (int i = 0; i < n; i++)
a[i] = tp.suitType<T>(String);
}
public void ini<T>(out T[] a, out T[] b, int n) {
a = new T[n];
b = new T[n];
for (int i = 0; i < n; i++) {
a[i] = i<T>();
b[i] = i<T>();
}
}
public void ini<T>(out T[,] a, int h, int w) {
a = new T[h, w];
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
a[i, j] = i<T>();
}
public void o<T>(T v) { Console.WriteLine(v); }
public void o<T>(params T[] a) { Array.ForEach(a, n => o(n)); }
public void ol<T>(T v) { Console.Write(v + " "); }
public void ol<T>(params T[] a) { o(connect<T>(a)); }
public void br() { o(""); }
public void writeFlush() { Console.Out.Flush(); }
private string connect<T>(params T[] s) { return string.Join(" ", s); }
}
class Operation<T> {
public Operation() {
var availableT = new Type[] { typeof(int), typeof(long), typeof(double) };
if (!availableT.Contains(typeof(T)))
throw new NotSupportedException();
var p1 = Expression.Parameter(typeof(T));
var p2 = Expression.Parameter(typeof(T));
Add = Expression.Lambda<Func<T, T, T>>(Expression.Add(p1, p2), p1, p2)
.Compile();
Sub = Expression.Lambda<Func<T, T, T>>(Expression.Subtract(p1, p2), p1, p2)
.Compile();
Mul = Expression.Lambda<Func<T, T, T>>(Expression.Multiply(p1, p2), p1, p2)
.Compile();
Div = Expression.Lambda<Func<T, T, T>>(Expression.Divide(p1, p2), p1, p2)
.Compile();
Mod = Expression.Lambda<Func<T, T, T>>(Expression.Modulo(p1, p2), p1, p2)
.Compile();
EQ = Expression.Lambda<Func<T, T, bool>>(Expression.Equal(p1, p2), p1, p2)
.Compile();
GT = Expression
.Lambda<Func<T, T, bool>>(Expression.GreaterThan(p1, p2), p1, p2)
.Compile();
GE = Expression
.Lambda<Func<T, T, bool>>(Expression.GreaterThanOrEqual(p1, p2),
p1, p2)
.Compile();
LT =
Expression.Lambda<Func<T, T, bool>>(Expression.LessThan(p1, p2), p1, p2)
.Compile();
LE = Expression
.Lambda<Func<T, T, bool>>(Expression.LessThanOrEqual(p1, p2), p1,
p2)
.Compile();
}
public Func<T, T, T> Add { get; private set; }
public Func<T, T, T> Sub { get; private set; }
public Func<T, T, T> Mul { get; private set; }
public Func<T, T, T> Div { get; private set; }
public Func<T, T, T> Mod { get; private set; }
public Func<T, T, bool> EQ { get; private set; }
public Func<T, T, bool> GT { get; private set; }
public Func<T, T, bool> GE { get; private set; }
public Func<T, T, bool> LT { get; private set; }
public Func<T, T, bool> LE { get; private set; }
}
class OP {
// Matを簡潔に...
public T Add<T>(T a, T b) {
var op = new Operation<T>();
return op.Add(a, b);
}
public T Sub<T>(T a, T b) {
var op = new Operation<T>();
return op.Sub(a, b);
}
public T Mul<T>(T a, T b) {
var op = new Operation<T>();
return op.Mul(a, b);
}
public T Div<T>(T a, T b) {
var op = new Operation<T>();
return op.Div(a, b);
}
public T Mod<T>(T a, T b) {
var op = new Operation<T>();
return op.Mod(a, b);
}
public bool EQ<T>(T a, T b) {
var op = new Operation<T>();
return op.EQ(a, b);
}
public bool GT<T>(T a, T b) {
var op = new Operation<T>();
return op.GT(a, b);
}
public bool GE<T>(T a, T b) {
var op = new Operation<T>();
return op.GE(a, b);
}
public bool LT<T>(T a, T b) {
var op = new Operation<T>();
return op.LT(a, b);
}
public bool LE<T>(T a, T b) {
var op = new Operation<T>();
return op.LE(a, b);
}
}
class TYPE {
public bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); }
public T convertType<T, U>(U v) {
return (T)Convert.ChangeType(v, typeof(T));
}
public T suitType<T>(string s) {
if (typeEQ<T, int>())
return convertType<T, int>(int.Parse(s));
if (typeEQ<T, long>())
return convertType<T, long>(long.Parse(s));
if (typeEQ<T, double>())
return convertType<T, double>(double.Parse(s));
if (typeEQ<T, char>())
return convertType<T, char>(char.Parse(s));
return convertType<T, string>(s);
}
}
class PQueue<T>
where T : IComparable {
public List<T> heap;
private Comparison<T> comp;
private IComparer<T> comparer;
private int size = 0;
private int type;
public PQueue(int type = 0) : this(Comparer<T>.Default) { this.type = type; }
public PQueue(IComparer<T> comparer) : this(16, comparer.Compare) {
this.comparer = comparer;
}
public PQueue(Comparison<T> comparison) : this(16, comparison) {}
public PQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.comp = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (Compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && Compare(heap[b], heap[a]) < 0)
a = b;
if (Compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
public bool Empty() { return !Any(); }
public bool Contains(T v) { return heap.Contains(v); }
private int Compare(T x, T y) {
return type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
}
#endregion
#region other
class Mat {
OP op;
public Mat() { op = new OP(); }
public int mod = 1000000007; // 10^9+7
public long Pow(long a, long b) {
if (b == 0)
return 1;
if (b % 2 == 1)
return (a % mod * Pow(a % mod, b - 1) % mod) % mod;
else
return Pow(a * a % mod, b / 2) % mod;
}
public long oldFact(long n) { // 1e4
return (n != 0) ? (n % mod * (Fact(n - 1) % mod) % mod) : 1;
}
public long Fact(long n) {
long ret = 1;
for (long i = 1; i <= n; i++)
ret = (ret * i) % mod;
return ret;
}
public long C(long n, long r) {
if (r == 0 || n == r)
return 1;
else if (n == 0)
return 0;
else if (n < 0 || n < r)
throw new ArgumentException("n,r invalid");
else
return (Fact(n) % mod *
Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) %
mod;
}
public bool isPrime(long n) {
if (n == 2)
return true;
if (n < 2 || n % 2 == 0)
return false;
for (long v = 3; v <= (long)Math.Sqrt(n); v += 2)
if (n % v == 0)
return false;
return true;
}
public long LCM(long a, long b) { return a * (b / GCD(a, b)); }
public long LCM(params long[] a) { return a.Aggregate((v, n) => LCM(v, n)); }
public long GCD(long a, long b) {
if (a < b)
Swap(ref a, ref b);
return b == 0 ? a : GCD(b, a % b);
}
public long GCD(params long[] array) {
return array.Aggregate((v, next) => GCD(v, next));
}
public void Swap<T>(ref T a, ref T b) {
T tmp = a;
a = b;
b = tmp;
}
public T Max<T>(params T[] v) { return v.Max(); }
public T Min<T>(params T[] v) { return v.Min(); }
public double Dis(int x1, int y1, int x2, int y2) {
return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2));
}
public int mDis(int x1, int y1, int x2, int y2) {
return Math.Abs(x1 - x2) + Math.Abs(y1 - y2);
}
public int Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; }
public int DigVal(int n, int dig) {
return (n % (int)Pow(10, dig)) / (int)Pow(10, dig - 1);
}
public int[] DigValArr(int n) {
int[] ret = new int[Digit(n)];
M.REP(ret.Length, i => ret[i] = DigVal(n, i + 1));
return ret;
}
public int Clamp(int n, int a, int b) {
return (n < a) ? a : (b < n) ? b : n;
}
public long Clamp(long n, long a, long b) {
return (n < a) ? a : (b < n) ? b : n;
}
public double Clamp(double n, double a, double b) {
return (n < a) ? a : (b < n) ? b : n;
}
public long Tousa(long a, long d, int n) { return a + (n - 1) * d; }
public long TousaSum(long a, long d, int n) {
return n * (2 * a + (n - 1) * d) / 2;
}
}
class AssociativeArray<T> { // hack:配列時要初期化
public Dictionary<T, int> dic;
public AssociativeArray() { dic = new Dictionary<T, int>(); }
public AssociativeArray(params T[] a) {
dic = new Dictionary<T, int>();
Add(a);
}
public void Add(params T[] a) {
M.REP(a.Length, i => {
if (!conK(a[i]))
dic[a[i]] = 0;
dic[a[i]]++;
});
}
public void Set(T k, int v) {
if (!dic.ContainsKey(k))
dic[k] = 0;
dic[k] = v;
}
public void Remove(params T[] a) {
M.REP(a.Length, i => {
if (conK(a[i]))
dic.Remove(a[i]);
});
}
public T[] Keys() { return dic.Keys.ToArray<T>(); }
public int Val(T k) { return (dic.ContainsKey(k)) ? dic[k] : 0; }
public int ValSum => dic.Values.Sum();
public int KeyNum => dic.Keys.Count;
public int MaxVal => dic.Values.Max();
public int MinVal => dic.Values.Min();
public T MaxKey => dic.First(d => d.Value == MaxVal).Key;
public T MinKey => dic.First(d => d.Value == MinVal).Key;
public bool conK(T k) { return dic.ContainsKey(k); }
public bool anyK(params T[] k) { return k.Any(key => conK(key)); }
public bool allK(params T[] k) { return k.All(key => conK(key)); }
public void Show() {
foreach (var v in dic) {
Console.WriteLine(v.Key + " : " + v.Value);
}
}
//:sort->array
}
class UnionFind {
public long[] parent;
public long[] depth;
public void Init(long n) {
parent = new long[n];
depth = new long[n];
M.REP(n, i => parent[i] = i);
}
public long Find(long x) {
return (parent[x] == x) ? x : parent[x] = Find(parent[x]);
}
public void Unite(long x, long y) {
x = Find(x);
y = Find(y);
if (x == y)
return;
if (depth[x] < depth[y])
parent[x] = y;
else {
parent[y] = x;
if (depth[x] == depth[y])
depth[x]++;
}
}
public bool Same(long a, long b) { return Find(a) == Find(b); }
}
class Time {
public bool isLeapYear(int y) {
return (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0));
}
}
#endregion
#region Graph
class Index {
public int[] Comp(int[] bef) {
int[] aft = new int[bef.Length];
var tmp = bef.Distinct()
.OrderBy(v => v)
.Select((v, i) => new { v, i })
.ToDictionary(p => p.v, p => p.i);
aft = bef.Select(v => tmp[v]).ToArray();
return aft;
}
}
class BasicGraph { //まとめよう
public List<Tuple<int, long>>[] G;
public void Init(int n) {
G = new List<Tuple<int, long>>[n + 1];
G.Length.REP(i => G[i] = new List<Tuple<int, long>>());
}
public void Dir(int[] f, int[] t) {
f.Length.REP(i => G[f[i]].Add(Tuple.Create(t[i], 1L)));
}
public void Dir(int[] f, int[] t, long[] c) {
f.Length.REP(i => G[f[i]].Add(Tuple.Create(t[i], c[i])));
}
public void NonDir(int[] f, int[] t) {
f.Length.REP(i => {
G[f[i]].Add(Tuple.Create(t[i], 1L));
G[t[i]].Add(Tuple.Create(f[i], 1L));
});
}
public void NonDir(int[] f, int[] t, long[] c) {
f.Length.REP(i => {
G[f[i]].Add(Tuple.Create(t[i], c[i]));
G[t[i]].Add(Tuple.Create(f[i], c[i]));
});
}
}
class TreeDis { // test
public List<Tuple<long, long>>[] g;
public long[] a2other;
private int type;
public TreeDis(int type = 0) { this.type = type; } // 0->bfs,other->dfs
public void Init(long n) {
g = new List<Tuple<long, long>>[n + 1];
M.REP(g.Length, i => g[i] = new List<Tuple<long, long>>());
}
public void Run(long[] a, long[] b) {
M.REP(a.Length, i => {
g[a[i]].Add(Tuple.Create(b[i], 1L));
g[b[i]].Add(Tuple.Create(a[i], 1L));
});
}
public void Run(long[] a, long[] b, long[] w) {
M.REP(a.Length, i => {
g[a[i]].Add(Tuple.Create(b[i], w[i]));
g[b[i]].Add(Tuple.Create(a[i], w[i]));
});
}
public long[] a2iArr(long a) {
a2other = new long[g.Count()];
if (type == 0)
BFS(a);
else
DFS(a);
return a2other;
}
private void BFS(long a) {
var q = new Queue<Tuple<long, long>>();
q.Enqueue(Tuple.Create(a, -1L));
while (q.Count > 0) {
var c = q.Dequeue();
foreach (var v in g[c.Item1]) {
if (v.Item1 == c.Item2)
continue;
a2other[v.Item1] = a2other[c.Item1] + v.Item2;
q.Enqueue(Tuple.Create(v.Item1, c.Item1));
}
}
}
private void DFS(long a) {
var s = new Stack<Tuple<long, long>>();
s.Push(Tuple.Create(a, -1L));
while (s.Count > 0) {
var c = s.Pop();
foreach (var v in g[c.Item1]) {
if (v.Item1 == c.Item2)
continue;
a2other[v.Item1] = a2other[c.Item1] + v.Item2;
s.Push(Tuple.Create(v.Item1, c.Item1));
}
}
}
}
class ShortestPath {
protected int I = -1;
protected long INF = (int)1e9;
public List<Tuple<int, long>>[] Adj;
public void Init(int n) {
I = n + 1;
Adj = new List<Tuple<int, long>>[I];
I.REP(i => Adj[i] = new List<Tuple<int, long>>());
}
public void AddPath(int f, int t, long c) {
Adj[f].Add(Tuple.Create(t, c));
Adj[t].Add(Tuple.Create(f, c));
}
public void AddPath(int[] f, int[] t, long[] c) {
f.Length.REP(i => AddPath(f[i], t[i], c[i]));
}
}
class Dijkstra : ShortestPath { //隣接対応後未検証
public long MinCost(int f, int t) {
long[] cost = new long[I];
cost.Set(INF);
cost[f] = 0;
var pq = new PQueue<Tuple<int, long>>();
pq.Enqueue(Tuple.Create(f, 0L)); //(from,cost)
while (pq.Count > 0) {
var cur = pq.Dequeue();
if (cost[cur.Item1] < cur.Item2)
continue;
Adj[cur.Item1].Count.REP(i => {
var tmp = Adj[cur.Item1][i];
if (cost[tmp.Item1] > cost[cur.Item1] + tmp.Item2) {
cost[tmp.Item1] = cost[cur.Item1] + tmp.Item2;
pq.Enqueue(Tuple.Create(tmp.Item1, cost[tmp.Item1]));
}
});
}
return cost[t];
}
}
class BellmanFord : ShortestPath {
public long MinCost(int f, int t) {
long[] cost = new long[I];
cost.Set(INF);
cost[f] = 0;
bool isUpdate = true;
while (isUpdate) {
isUpdate = false;
I.REP(i => Adj[i].Count.REP(j => {
var cur = Adj[i][j];
if (cost[cur.Item1] > cost[i] + cur.Item2) {
cost[cur.Item1] = cost[i] + cur.Item2;
isUpdate = true;
}
}));
}
return cost[t];
}
}
class WarshallFloyd { // TODO:update
private int E;
private int INF = (int)1e9;
public long[,] G;
public void Init(int n) {
E = n + 1;
G = new long[E, E];
G.Set(INF);
E.REP(i => G[i, i] = 0);
}
public void AddPath(int f, int t, long c) {
G[f, t] = c;
G[t, f] = c;
}
public void AddPath(int[] f, int[] t, long[] c) {
f.Length.REP(i => AddPath(f[i], t[i], c[i]));
}
public long[,] MinCostArr() {
E.REP(i => E.REP(
j => E.REP(k => G[j, k] = Math.Min(G[j, k], G[j, i] + G[i, k]))));
return G;
}
}
#endregion
#region Ex
static class StringEX { //文字
public static string Reversed(this string s) {
return string.Join("", s.Reverse());
}
public static string Repeat(this string s, int n) {
return string.Concat(Enumerable.Repeat(s, n).ToArray());
}
public static int toInt(this string s) {
int n;
return (int.TryParse(s.TrimStart('0'), out n)) ? n : 0;
}
public static int toInt(this char c) { return toInt(c.ToString()); }
public static int toInt(this char[] c) { return toInt(new string(c)); }
public static string toString(this char[] c) { return new string(c); }
}
static class NumericEx { //数値
public static string pad0<T>(this T v, int n) {
return v.ToString().PadLeft(n, '0');
}
public static double RoundOff(this double v, int n) {
return Math.Round(v, n - 1, MidpointRounding.AwayFromZero);
}
public static bool isOdd(this int v) { return v % 2 != 0; }
}
static class ArrayEX {
public static T[] Sort<T>(this T[] a) {
Array.Sort(a);
return a;
}
public static void Set<T>(this T[] a, T v) { M.REP(a.Length, i => a[i] = v); }
public static void Set<T>(this T[,] a, T v) {
M.REP(a.GetLength(0), i => M.REP(a.GetLength(1), j => a[i, j] = v));
}
}
static class BitEx {
public static bool Any(this BitArray b) {
foreach (bool f in b)
if (f)
return true;
return false;
}
public static bool All(this BitArray b) {
foreach (bool f in b)
if (!f)
return false;
return true;
}
public static bool None(this BitArray b) { return !Any(b); }
public static void Flip(this BitArray b, int index) {
b.Set(index, !b.Get(index));
}
}
static class M { // otherExへ移行
public static void REP(int n, Action<int> a) {
for (int i = 0; i < n; i++)
a(i);
}
public static void REP(long n, Action<long> a) {
for (long i = 0; i < n; i++)
a(i);
}
}
static class OtherEx {
public static void REP(this int v, Action<int> act) {
for (int i = 0; i < v; i++)
act(i);
}
}
#endregion
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace Program {
class MainClass {
// C#Lover///////////////////////////////////////////////////
int N;
long K;
// int[] A,B;
Tuple<long, long>[] AB;
void Solve() {
io.i(out N, out K);
AB = new Tuple<long, long>[N];
N.REP(i => AB[i] = Tuple.Create(io.Long, io.Long));
Array.Sort(AB);
long ans = AB[N - 1].Item1;
for (long i = 0, sumK = 0;; i++) {
sumK += AB[i].Item2;
if (sumK >= K) {
ans = AB[i].Item1;
break;
}
}
io.o(ans);
}
////////////////////////////////////////////////////////////
public static void Main(string[] args) { new MainClass().Stream(); }
IO io = new IO();
void Stream() {
Solve();
io.writeFlush();
}
// void Stream() { Test(); io.writeFlush(); }
void Test() {}
#region MockMacro
// Hack Update
// cannot use break,continue,goto
void FOR(int a, int b, Action<int> act) {
for (int i = a; i < b; i++)
act(i);
}
void REP(int n, Action<int> act) {
for (int i = 0; i < n; i++)
act(i);
}
#endregion
}
#region default
class IO {
TYPE tp;
string[] nextBuffer;
int BufferCnt;
char[] cs = new char[] { ' ' };
StreamWriter sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
public IO() {
nextBuffer = new string[0];
BufferCnt = 0;
Console.SetOut(sw);
tp = new TYPE();
}
public string Next() {
if (BufferCnt < nextBuffer.Length)
return nextBuffer[BufferCnt++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
BufferCnt = 0;
return nextBuffer[BufferCnt++];
}
public string String => Next();
public char Char => char.Parse(String);
public int Int => int.Parse(String);
public long Long => long.Parse(String);
public double Double => double.Parse(String);
public string[] arr => Console.ReadLine().Split(' ');
public char[] arrChar => Array.ConvertAll(arr, char.Parse);
public int[] arrInt => Array.ConvertAll(arr, int.Parse);
public long[] arrLong => Array.ConvertAll(arr, long.Parse);
public double[] arrDouble => Array.ConvertAll(arr, double.Parse);
public T i<T>() { return tp.suitType<T>(String); }
public void i<T>(out T v) { v = tp.suitType<T>(String); }
public void i<T, U>(out T v1, out U v2) {
i(out v1);
i(out v2);
}
public void i<T, U, V>(out T v1, out U v2, out V v3) {
i(out v1);
i(out v2);
i(out v3);
}
public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) {
i(out v1);
i(out v2);
i(out v3);
i(out v4);
}
public void i<T, U, V, W, X>(out T v1, out U v2, out V v3, out W v4,
out X v5) {
i(out v1);
i(out v2);
i(out v3);
i(out v4);
i(out v5);
}
public void ini<T>(out T[] a, int n) {
a = new T[n];
for (int i = 0; i < n; i++)
a[i] = tp.suitType<T>(String);
}
public void ini<T>(out T[] a, out T[] b, int n) {
a = new T[n];
b = new T[n];
for (int i = 0; i < n; i++) {
a[i] = i<T>();
b[i] = i<T>();
}
}
public void ini<T>(out T[,] a, int h, int w) {
a = new T[h, w];
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
a[i, j] = i<T>();
}
public void o<T>(T v) { Console.WriteLine(v); }
public void o<T>(params T[] a) { Array.ForEach(a, n => o(n)); }
public void ol<T>(T v) { Console.Write(v + " "); }
public void ol<T>(params T[] a) { o(connect<T>(a)); }
public void br() { o(""); }
public void writeFlush() { Console.Out.Flush(); }
private string connect<T>(params T[] s) { return string.Join(" ", s); }
}
class Operation<T> {
public Operation() {
var availableT = new Type[] { typeof(int), typeof(long), typeof(double) };
if (!availableT.Contains(typeof(T)))
throw new NotSupportedException();
var p1 = Expression.Parameter(typeof(T));
var p2 = Expression.Parameter(typeof(T));
Add = Expression.Lambda<Func<T, T, T>>(Expression.Add(p1, p2), p1, p2)
.Compile();
Sub = Expression.Lambda<Func<T, T, T>>(Expression.Subtract(p1, p2), p1, p2)
.Compile();
Mul = Expression.Lambda<Func<T, T, T>>(Expression.Multiply(p1, p2), p1, p2)
.Compile();
Div = Expression.Lambda<Func<T, T, T>>(Expression.Divide(p1, p2), p1, p2)
.Compile();
Mod = Expression.Lambda<Func<T, T, T>>(Expression.Modulo(p1, p2), p1, p2)
.Compile();
EQ = Expression.Lambda<Func<T, T, bool>>(Expression.Equal(p1, p2), p1, p2)
.Compile();
GT = Expression
.Lambda<Func<T, T, bool>>(Expression.GreaterThan(p1, p2), p1, p2)
.Compile();
GE = Expression
.Lambda<Func<T, T, bool>>(Expression.GreaterThanOrEqual(p1, p2),
p1, p2)
.Compile();
LT =
Expression.Lambda<Func<T, T, bool>>(Expression.LessThan(p1, p2), p1, p2)
.Compile();
LE = Expression
.Lambda<Func<T, T, bool>>(Expression.LessThanOrEqual(p1, p2), p1,
p2)
.Compile();
}
public Func<T, T, T> Add { get; private set; }
public Func<T, T, T> Sub { get; private set; }
public Func<T, T, T> Mul { get; private set; }
public Func<T, T, T> Div { get; private set; }
public Func<T, T, T> Mod { get; private set; }
public Func<T, T, bool> EQ { get; private set; }
public Func<T, T, bool> GT { get; private set; }
public Func<T, T, bool> GE { get; private set; }
public Func<T, T, bool> LT { get; private set; }
public Func<T, T, bool> LE { get; private set; }
}
class OP {
// Matを簡潔に...
public T Add<T>(T a, T b) {
var op = new Operation<T>();
return op.Add(a, b);
}
public T Sub<T>(T a, T b) {
var op = new Operation<T>();
return op.Sub(a, b);
}
public T Mul<T>(T a, T b) {
var op = new Operation<T>();
return op.Mul(a, b);
}
public T Div<T>(T a, T b) {
var op = new Operation<T>();
return op.Div(a, b);
}
public T Mod<T>(T a, T b) {
var op = new Operation<T>();
return op.Mod(a, b);
}
public bool EQ<T>(T a, T b) {
var op = new Operation<T>();
return op.EQ(a, b);
}
public bool GT<T>(T a, T b) {
var op = new Operation<T>();
return op.GT(a, b);
}
public bool GE<T>(T a, T b) {
var op = new Operation<T>();
return op.GE(a, b);
}
public bool LT<T>(T a, T b) {
var op = new Operation<T>();
return op.LT(a, b);
}
public bool LE<T>(T a, T b) {
var op = new Operation<T>();
return op.LE(a, b);
}
}
class TYPE {
public bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); }
public T convertType<T, U>(U v) {
return (T)Convert.ChangeType(v, typeof(T));
}
public T suitType<T>(string s) {
if (typeEQ<T, int>())
return convertType<T, int>(int.Parse(s));
if (typeEQ<T, long>())
return convertType<T, long>(long.Parse(s));
if (typeEQ<T, double>())
return convertType<T, double>(double.Parse(s));
if (typeEQ<T, char>())
return convertType<T, char>(char.Parse(s));
return convertType<T, string>(s);
}
}
class PQueue<T>
where T : IComparable {
public List<T> heap;
private Comparison<T> comp;
private IComparer<T> comparer;
private int size = 0;
private int type;
public PQueue(int type = 0) : this(Comparer<T>.Default) { this.type = type; }
public PQueue(IComparer<T> comparer) : this(16, comparer.Compare) {
this.comparer = comparer;
}
public PQueue(Comparison<T> comparison) : this(16, comparison) {}
public PQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.comp = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (Compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && Compare(heap[b], heap[a]) < 0)
a = b;
if (Compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
public bool Empty() { return !Any(); }
public bool Contains(T v) { return heap.Contains(v); }
private int Compare(T x, T y) {
return type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
}
#endregion
#region other
class Mat {
OP op;
public Mat() { op = new OP(); }
public int mod = 1000000007; // 10^9+7
public long Pow(long a, long b) {
if (b == 0)
return 1;
if (b % 2 == 1)
return (a % mod * Pow(a % mod, b - 1) % mod) % mod;
else
return Pow(a * a % mod, b / 2) % mod;
}
public long oldFact(long n) { // 1e4
return (n != 0) ? (n % mod * (Fact(n - 1) % mod) % mod) : 1;
}
public long Fact(long n) {
long ret = 1;
for (long i = 1; i <= n; i++)
ret = (ret * i) % mod;
return ret;
}
public long C(long n, long r) {
if (r == 0 || n == r)
return 1;
else if (n == 0)
return 0;
else if (n < 0 || n < r)
throw new ArgumentException("n,r invalid");
else
return (Fact(n) % mod *
Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) %
mod;
}
public bool isPrime(long n) {
if (n == 2)
return true;
if (n < 2 || n % 2 == 0)
return false;
for (long v = 3; v <= (long)Math.Sqrt(n); v += 2)
if (n % v == 0)
return false;
return true;
}
public long LCM(long a, long b) { return a * (b / GCD(a, b)); }
public long LCM(params long[] a) { return a.Aggregate((v, n) => LCM(v, n)); }
public long GCD(long a, long b) {
if (a < b)
Swap(ref a, ref b);
return b == 0 ? a : GCD(b, a % b);
}
public long GCD(params long[] array) {
return array.Aggregate((v, next) => GCD(v, next));
}
public void Swap<T>(ref T a, ref T b) {
T tmp = a;
a = b;
b = tmp;
}
public T Max<T>(params T[] v) { return v.Max(); }
public T Min<T>(params T[] v) { return v.Min(); }
public double Dis(int x1, int y1, int x2, int y2) {
return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2));
}
public int mDis(int x1, int y1, int x2, int y2) {
return Math.Abs(x1 - x2) + Math.Abs(y1 - y2);
}
public int Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; }
public int DigVal(int n, int dig) {
return (n % (int)Pow(10, dig)) / (int)Pow(10, dig - 1);
}
public int[] DigValArr(int n) {
int[] ret = new int[Digit(n)];
M.REP(ret.Length, i => ret[i] = DigVal(n, i + 1));
return ret;
}
public int Clamp(int n, int a, int b) {
return (n < a) ? a : (b < n) ? b : n;
}
public long Clamp(long n, long a, long b) {
return (n < a) ? a : (b < n) ? b : n;
}
public double Clamp(double n, double a, double b) {
return (n < a) ? a : (b < n) ? b : n;
}
public long Tousa(long a, long d, int n) { return a + (n - 1) * d; }
public long TousaSum(long a, long d, int n) {
return n * (2 * a + (n - 1) * d) / 2;
}
}
class AssociativeArray<T> { // hack:配列時要初期化
public Dictionary<T, int> dic;
public AssociativeArray() { dic = new Dictionary<T, int>(); }
public AssociativeArray(params T[] a) {
dic = new Dictionary<T, int>();
Add(a);
}
public void Add(params T[] a) {
M.REP(a.Length, i => {
if (!conK(a[i]))
dic[a[i]] = 0;
dic[a[i]]++;
});
}
public void Set(T k, int v) {
if (!dic.ContainsKey(k))
dic[k] = 0;
dic[k] = v;
}
public void Remove(params T[] a) {
M.REP(a.Length, i => {
if (conK(a[i]))
dic.Remove(a[i]);
});
}
public T[] Keys() { return dic.Keys.ToArray<T>(); }
public int Val(T k) { return (dic.ContainsKey(k)) ? dic[k] : 0; }
public int ValSum => dic.Values.Sum();
public int KeyNum => dic.Keys.Count;
public int MaxVal => dic.Values.Max();
public int MinVal => dic.Values.Min();
public T MaxKey => dic.First(d => d.Value == MaxVal).Key;
public T MinKey => dic.First(d => d.Value == MinVal).Key;
public bool conK(T k) { return dic.ContainsKey(k); }
public bool anyK(params T[] k) { return k.Any(key => conK(key)); }
public bool allK(params T[] k) { return k.All(key => conK(key)); }
public void Show() {
foreach (var v in dic) {
Console.WriteLine(v.Key + " : " + v.Value);
}
}
//:sort->array
}
class UnionFind {
public long[] parent;
public long[] depth;
public void Init(long n) {
parent = new long[n];
depth = new long[n];
M.REP(n, i => parent[i] = i);
}
public long Find(long x) {
return (parent[x] == x) ? x : parent[x] = Find(parent[x]);
}
public void Unite(long x, long y) {
x = Find(x);
y = Find(y);
if (x == y)
return;
if (depth[x] < depth[y])
parent[x] = y;
else {
parent[y] = x;
if (depth[x] == depth[y])
depth[x]++;
}
}
public bool Same(long a, long b) { return Find(a) == Find(b); }
}
class Time {
public bool isLeapYear(int y) {
return (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0));
}
}
#endregion
#region Graph
class Index {
public int[] Comp(int[] bef) {
int[] aft = new int[bef.Length];
var tmp = bef.Distinct()
.OrderBy(v => v)
.Select((v, i) => new { v, i })
.ToDictionary(p => p.v, p => p.i);
aft = bef.Select(v => tmp[v]).ToArray();
return aft;
}
}
class BasicGraph { //まとめよう
public List<Tuple<int, long>>[] G;
public void Init(int n) {
G = new List<Tuple<int, long>>[n + 1];
G.Length.REP(i => G[i] = new List<Tuple<int, long>>());
}
public void Dir(int[] f, int[] t) {
f.Length.REP(i => G[f[i]].Add(Tuple.Create(t[i], 1L)));
}
public void Dir(int[] f, int[] t, long[] c) {
f.Length.REP(i => G[f[i]].Add(Tuple.Create(t[i], c[i])));
}
public void NonDir(int[] f, int[] t) {
f.Length.REP(i => {
G[f[i]].Add(Tuple.Create(t[i], 1L));
G[t[i]].Add(Tuple.Create(f[i], 1L));
});
}
public void NonDir(int[] f, int[] t, long[] c) {
f.Length.REP(i => {
G[f[i]].Add(Tuple.Create(t[i], c[i]));
G[t[i]].Add(Tuple.Create(f[i], c[i]));
});
}
}
class TreeDis { // test
public List<Tuple<long, long>>[] g;
public long[] a2other;
private int type;
public TreeDis(int type = 0) { this.type = type; } // 0->bfs,other->dfs
public void Init(long n) {
g = new List<Tuple<long, long>>[n + 1];
M.REP(g.Length, i => g[i] = new List<Tuple<long, long>>());
}
public void Run(long[] a, long[] b) {
M.REP(a.Length, i => {
g[a[i]].Add(Tuple.Create(b[i], 1L));
g[b[i]].Add(Tuple.Create(a[i], 1L));
});
}
public void Run(long[] a, long[] b, long[] w) {
M.REP(a.Length, i => {
g[a[i]].Add(Tuple.Create(b[i], w[i]));
g[b[i]].Add(Tuple.Create(a[i], w[i]));
});
}
public long[] a2iArr(long a) {
a2other = new long[g.Count()];
if (type == 0)
BFS(a);
else
DFS(a);
return a2other;
}
private void BFS(long a) {
var q = new Queue<Tuple<long, long>>();
q.Enqueue(Tuple.Create(a, -1L));
while (q.Count > 0) {
var c = q.Dequeue();
foreach (var v in g[c.Item1]) {
if (v.Item1 == c.Item2)
continue;
a2other[v.Item1] = a2other[c.Item1] + v.Item2;
q.Enqueue(Tuple.Create(v.Item1, c.Item1));
}
}
}
private void DFS(long a) {
var s = new Stack<Tuple<long, long>>();
s.Push(Tuple.Create(a, -1L));
while (s.Count > 0) {
var c = s.Pop();
foreach (var v in g[c.Item1]) {
if (v.Item1 == c.Item2)
continue;
a2other[v.Item1] = a2other[c.Item1] + v.Item2;
s.Push(Tuple.Create(v.Item1, c.Item1));
}
}
}
}
class ShortestPath {
protected int I = -1;
protected long INF = (int)1e9;
public List<Tuple<int, long>>[] Adj;
public void Init(int n) {
I = n + 1;
Adj = new List<Tuple<int, long>>[I];
I.REP(i => Adj[i] = new List<Tuple<int, long>>());
}
public void AddPath(int f, int t, long c) {
Adj[f].Add(Tuple.Create(t, c));
Adj[t].Add(Tuple.Create(f, c));
}
public void AddPath(int[] f, int[] t, long[] c) {
f.Length.REP(i => AddPath(f[i], t[i], c[i]));
}
}
class Dijkstra : ShortestPath { //隣接対応後未検証
public long MinCost(int f, int t) {
long[] cost = new long[I];
cost.Set(INF);
cost[f] = 0;
var pq = new PQueue<Tuple<int, long>>();
pq.Enqueue(Tuple.Create(f, 0L)); //(from,cost)
while (pq.Count > 0) {
var cur = pq.Dequeue();
if (cost[cur.Item1] < cur.Item2)
continue;
Adj[cur.Item1].Count.REP(i => {
var tmp = Adj[cur.Item1][i];
if (cost[tmp.Item1] > cost[cur.Item1] + tmp.Item2) {
cost[tmp.Item1] = cost[cur.Item1] + tmp.Item2;
pq.Enqueue(Tuple.Create(tmp.Item1, cost[tmp.Item1]));
}
});
}
return cost[t];
}
}
class BellmanFord : ShortestPath {
public long MinCost(int f, int t) {
long[] cost = new long[I];
cost.Set(INF);
cost[f] = 0;
bool isUpdate = true;
while (isUpdate) {
isUpdate = false;
I.REP(i => Adj[i].Count.REP(j => {
var cur = Adj[i][j];
if (cost[cur.Item1] > cost[i] + cur.Item2) {
cost[cur.Item1] = cost[i] + cur.Item2;
isUpdate = true;
}
}));
}
return cost[t];
}
}
class WarshallFloyd { // TODO:update
private int E;
private int INF = (int)1e9;
public long[,] G;
public void Init(int n) {
E = n + 1;
G = new long[E, E];
G.Set(INF);
E.REP(i => G[i, i] = 0);
}
public void AddPath(int f, int t, long c) {
G[f, t] = c;
G[t, f] = c;
}
public void AddPath(int[] f, int[] t, long[] c) {
f.Length.REP(i => AddPath(f[i], t[i], c[i]));
}
public long[,] MinCostArr() {
E.REP(i => E.REP(
j => E.REP(k => G[j, k] = Math.Min(G[j, k], G[j, i] + G[i, k]))));
return G;
}
}
#endregion
#region Ex
static class StringEX { //文字
public static string Reversed(this string s) {
return string.Join("", s.Reverse());
}
public static string Repeat(this string s, int n) {
return string.Concat(Enumerable.Repeat(s, n).ToArray());
}
public static int toInt(this string s) {
int n;
return (int.TryParse(s.TrimStart('0'), out n)) ? n : 0;
}
public static int toInt(this char c) { return toInt(c.ToString()); }
public static int toInt(this char[] c) { return toInt(new string(c)); }
public static string toString(this char[] c) { return new string(c); }
}
static class NumericEx { //数値
public static string pad0<T>(this T v, int n) {
return v.ToString().PadLeft(n, '0');
}
public static double RoundOff(this double v, int n) {
return Math.Round(v, n - 1, MidpointRounding.AwayFromZero);
}
public static bool isOdd(this int v) { return v % 2 != 0; }
}
static class ArrayEX {
public static T[] Sort<T>(this T[] a) {
Array.Sort(a);
return a;
}
public static void Set<T>(this T[] a, T v) { M.REP(a.Length, i => a[i] = v); }
public static void Set<T>(this T[,] a, T v) {
M.REP(a.GetLength(0), i => M.REP(a.GetLength(1), j => a[i, j] = v));
}
}
static class BitEx {
public static bool Any(this BitArray b) {
foreach (bool f in b)
if (f)
return true;
return false;
}
public static bool All(this BitArray b) {
foreach (bool f in b)
if (!f)
return false;
return true;
}
public static bool None(this BitArray b) { return !Any(b); }
public static void Flip(this BitArray b, int index) {
b.Set(index, !b.Get(index));
}
}
static class M { // otherExへ移行
public static void REP(int n, Action<int> a) {
for (int i = 0; i < n; i++)
a(i);
}
public static void REP(long n, Action<long> a) {
for (long i = 0; i < n; i++)
a(i);
}
}
static class OtherEx {
public static void REP(this int v, Action<int> act) {
for (int i = 0; i < v; i++)
act(i);
}
}
#endregion
}
|
[["-", 0, 235, 8, 201, 0, 124, 0, 198, 0, 21], ["+", 8, 201, 0, 235, 8, 201, 0, 124, 0, 35], ["+", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 0, 198, 39, 224, 39, 236, 237, 238, 0, 199], ["+", 0, 198, 39, 224, 39, 236, 237, 238, 0, 199], ["-", 12, 227, 39, 224, 39, 236, 237, 238, 0, 199], ["+", 12, 227, 39, 224, 39, 236, 237, 238, 0, 199], ["-", 12, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
| 8
| 6,774
| 17
|
using System.Linq;
using System;
class Program {
static void Main(string[] args) {
var input = System.Console.ReadLine().Trim().Split(' ');
var n = Int32.Parse(input[0]);
var k = Int32.Parse(input[1]);
var result = -1;
var abList = new int [n]
.Select(w => System.Console.ReadLine()
.Split(' ')
.Select(i => Int32.Parse(i))
.ToArray())
.OrderBy(w => w[0])
.ToList();
for (var i = 0; i < n; i++) {
k -= abList[i][1];
if (k <= 0) {
result = abList[i][0];
break;
}
}
System.Console.WriteLine(result);
}
}
|
using System.Linq;
using System;
class Program {
static void Main(string[] args) {
var input = System.Console.ReadLine().Trim().Split(' ');
var n = long.Parse(input[0]);
var k = long.Parse(input[1]);
long result = -1;
var abList = new int [n]
.Select(w => System.Console.ReadLine()
.Trim()
.Split(' ')
.Select(long.Parse)
.ToArray())
.OrderBy(w => w[0])
.ToList();
for (var i = 0; i < n; i++) {
k -= abList[i][1];
if (k <= 0) {
result = abList[i][0];
break;
}
}
System.Console.WriteLine(result);
// System.Console.Read();
}
}
|
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["-", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 28, 0, 218, 8, 213, 3, 4, 0, 24], ["-", 0, 218, 8, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 28, 0, 218, 8, 213, 3, 4, 0, 25]]
| 8
| 191
| 17
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
// using System.Numerics;
class Program {
static void Main() {
// SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
new Program().Solve();
Out.Flush();
}
Scanner cin = new Scanner();
Random rnd = new Random();
Stopwatch sw = new Stopwatch();
readonly int[] dd = { 0, 1, 0, -1, 0 };
readonly int mod = 1000000007;
readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
void Solve() {
var d = new long[100001];
int N = cin.Nextint;
int K = cin.Nextint;
for (int i = 0; i < N; i++) {
int a = cin.Nextint;
int b = cin.Nextint;
d[a] += b;
}
long cnt = 0;
for (int i = 1; i < d.Length; i++) {
if (cnt + d[i] >= K) {
WriteLine(i);
return;
}
cnt += d[i];
}
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string[] Scan {
get { return ReadLine().Split(); }
}
public int[] Scanint {
get { return Array.ConvertAll(Scan, int.Parse); }
}
public long[] Scanlong {
get { return Array.ConvertAll(Scan, long.Parse); }
}
public double[] Scandouble {
get { return Array.ConvertAll(Scan, double.Parse); }
}
public string Next {
get {
if (i < s.Length)
return s[i++];
string st = ReadLine();
while (st == "")
st = ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return Next;
}
}
public int Nextint {
get { return int.Parse(Next); }
}
public long Nextlong {
get { return long.Parse(Next); }
}
public double Nextdouble {
get { return double.Parse(Next); }
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
// using System.Numerics;
class Program {
static void Main() {
// SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
new Program().Solve();
Out.Flush();
}
Scanner cin = new Scanner();
Random rnd = new Random();
Stopwatch sw = new Stopwatch();
readonly int[] dd = { 0, 1, 0, -1, 0 };
readonly int mod = 1000000007;
readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
void Solve() {
var d = new long[100001];
int N = cin.Nextint;
var K = cin.Nextlong;
for (long i = 0; i < N; i++) {
long a = cin.Nextlong;
long b = cin.Nextlong;
d[a] += b;
}
long cnt = 0;
for (int i = 1; i < d.Length; i++) {
if (cnt + d[i] >= K) {
WriteLine(i);
return;
}
cnt += d[i];
}
}
}
class Scanner {
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string[] Scan {
get { return ReadLine().Split(); }
}
public int[] Scanint {
get { return Array.ConvertAll(Scan, int.Parse); }
}
public long[] Scanlong {
get { return Array.ConvertAll(Scan, long.Parse); }
}
public double[] Scandouble {
get { return Array.ConvertAll(Scan, double.Parse); }
}
public string Next {
get {
if (i < s.Length)
return s[i++];
string st = ReadLine();
while (st == "")
st = ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
i = 0;
return Next;
}
}
public int Nextint {
get { return int.Parse(Next); }
}
public long Nextlong {
get { return long.Parse(Next); }
}
public double Nextdouble {
get { return double.Parse(Next); }
}
}
|
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199]]
| 8
| 494
| 14
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main() {
var _ = Console.ReadLine().Split();
var n = int.Parse(_[0]);
var k = int.Parse(_[1]);
var inss = new List<Tuple<int, int>>();
for (var i = 0; i < n; i++) {
var __ = Console.ReadLine().Split();
var a = int.Parse(__[0]);
var b = int.Parse(__[1]);
inss.Add(Tuple.Create(a, b));
}
inss.Sort((x, y) => x.Item1.CompareTo(x.Item2));
var cnt = 0;
foreach (var ins in inss) {
cnt += ins.Item2;
if (cnt >= k) {
Console.WriteLine(ins.Item1);
return;
}
}
throw new Exception();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main() {
checked {
var _ = Console.ReadLine().Split();
var n = long.Parse(_[0]);
var k = long.Parse(_[1]);
var inss = new List<Tuple<long, long>>();
for (var i = 0; i < n; i++) {
var __ = Console.ReadLine().Split();
var a = long.Parse(__[0]);
var b = long.Parse(__[1]);
inss.Add(Tuple.Create(a, b));
}
inss.Sort((x, y) => x.Item1.CompareTo(y.Item1));
long cnt = 0;
foreach (var ins in inss) {
cnt += ins.Item2;
if (cnt >= k) {
Console.WriteLine(ins.Item1);
return;
}
}
throw new Exception();
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 287, 0, 292], ["+", 0, 195, 8, 196, 0, 287, 0, 196, 0, 45], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 39, 236, 237, 238, 0, 236, 237, 238, 0, 199], ["+", 39, 236, 237, 238, 0, 236, 237, 238, 0, 199], ["-", 8, 213, 3, 4, 0, 28, 0, 214, 205, 22], ["+", 8, 213, 3, 4, 0, 28, 0, 214, 205, 22], ["-", 8, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 8, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 287, 0, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 287, 0, 196, 0, 46]]
| 8
| 217
| 21
|
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;
class Program {
private static readonly Scanner sc = new Scanner();
static void Main(string[] args) {
int n = sc.Int;
int k = sc.Int;
int[] cnt = new int[100001];
for (int i = 0; i < n; i++) {
int a = sc.Int;
int b = sc.Int;
cnt[a] += b;
}
int j = 0;
int c = 0;
while (c < k)
c += cnt[j++];
Console.WriteLine(j - 1);
}
}
class Scanner {
private string[] _str = new string[0];
private int _i;
public string Str {
get {
if (_i >= _str.Length) {
_str = Console.ReadLine().Split(' ');
_i = 0;
}
return _str[_i++];
}
}
public int Int {
get { return int.Parse(Str); }
}
public long Long {
get { return long.Parse(Str); }
}
public double Double {
get { return double.Parse(Str); }
}
}
|
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;
class Program {
private static readonly Scanner sc = new Scanner();
static void Main(string[] args) {
long n = sc.Long;
long k = sc.Long;
long[] cnt = new long[100010];
for (int i = 0; i < n; i++) {
long a = sc.Long;
long b = sc.Long;
cnt[a] += b;
}
long j = 0;
long c = 0;
while (c < k)
c += cnt[j++];
Console.WriteLine(j - 1);
}
}
class Scanner {
private string[] _str = new string[0];
private int _i;
public string Str {
get {
if (_i >= _str.Length) {
_str = Console.ReadLine().Split(' ');
_i = 0;
}
return _str[_i++];
}
}
public int Int {
get { return int.Parse(Str); }
}
public long Long {
get { return long.Parse(Str); }
}
public double Double {
get { return double.Parse(Str); }
}
}
|
[["-", 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, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199]]
| 8
| 253
| 26
|
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Threading.Tasks;
/*
・概要
Bellman-Ford法は、
重み付き有向グラフにおける単一始点の最短経路問題を解くアルゴリズム。
辺の重みに負数が存在する場合に主に使う。
(cf. 辺の重みが非負数ならば、ダイクストラ法の方が高速)
・使用法
1. BellmanFordクラスのインスタンスを作成
引数は、頂点数N
(e.g. BellmanFord graph = new BellmanFord(N);)
2. 与えられた辺を追加
引数は、始点、終点、重み
(e.g. graph.AddEdge(start,goal,value);)
3. BellmanFord法で最短距離を決定する
負の閉路で無限ループし、最短距離が求まらない場合は、falseを返す
(e.g. bool found = graph.SetDist();)
4. (最短経路が見つかった場合)始点からの最短距離を取得する
引数は、目的地のインデックス
(e.g. long ans = graph.GetDist(N-1);)
・アルゴリズム(計算量は O (V * E):Vは頂点の数、Eは辺の数)
ループを回して、各ノードへの最短距離を更新し続ける。
・詳細
*/
class Program {
// Main
static void Main(string[] args) {
//読み込む
string[] S = Console.ReadLine().Split(' ');
int N = int.Parse(S[0]);
int M = int.Parse(S[1]);
// 1. BellmanFordクラスのインスタンスを作成
//引数は、頂点数N
BellmanFord graph = new BellmanFord(N);
// 2. 与えられた辺を追加
for (int i = 0; i < M; i++) {
string[] line = Console.ReadLine().Split(' ');
int a = int.Parse(line[0]) - 1;
int b = int.Parse(line[1]) - 1;
//この問題では最長距離を求めるので、重みの正負を逆転させる
long c = long.Parse(line[2]) * -1;
//辺を追加
/*
引数は、始点、終点、重み
*/
graph.AddEdge(a, b, c);
}
// 3. BellmanFord法で最短距離を決定する
/*
負の閉路で無限ループし、最短距離が求まらない場合は、falseを返す
*/
bool found = graph.SetDist();
//出力
//見つかった場合
if (found) {
// 4. 始点からの最短距離を取得する
//引数は、目的地のインデックス
long ans = graph.GetDist(N - 1);
//この問題では正負を逆転したので、元に戻す
ans = -1 * ans;
Console.WriteLine(ans);
}
//見つからなかった場合
else {
Console.WriteLine("inf");
}
}
}
// Bellman-Ford法を用いて、最短距離を求める為のクラス
class BellmanFord {
//最短距離の初期化に使う変数
/*
大き過ぎると、オーバーフローして大小比較にバグが生じるので注意!!!!
*/
static readonly long inf = 10000000000000;
//辺を保存する構造体
public struct Edge {
//始点
public int Start;
//終点
public int Goal;
//重み(負数もOK)
public long Value;
public Edge(int s, int g, long v) {
this.Start = s;
this.Goal = g;
this.Value = v;
}
}
//辺を保存するリスト
List<Edge> edgeList;
//各頂点への最短距離を保存する配列
long[] minDist;
//コンストラクタ
/*
引数は頂点数
*/
public BellmanFord(int vertex) {
this.edgeList = new List<Edge>();
//各頂点への最短距離をinfで初期化
//但し、当然、インデックス0(始点から始点)は除く
this.minDist = new long[vertex];
for (int i = 1; i < vertex; i++) {
minDist[i] = inf;
}
}
//辺を追加するメソッド
/*
引数は、始点、終点、重み
*/
public void AddEdge(int start, int goal, long value) {
Edge edge = new Edge(start, goal, value);
this.edgeList.Add(edge);
}
// Bellman-Ford法で、最短距離を求めるメソッド
/*
最短距離が求まる場合はtrueを、求まらない場合はfalseを返す
*/
public bool SetDist() {
//最短距離が求まるかのbool
bool found = true;
//頂点数と辺数
int V = this.minDist.Length;
int E = this.edgeList.Count();
//ループで最小値を更新
//各ノードへの到達最小値を更新し続ける
for (int i = 0; i < V; i++) {
for (int j = 0; j < E; j++) {
//当該頂点の始点、終点、重み
int start = edgeList[j].Start;
int goal = edgeList[j].Goal;
long value = edgeList[j].Value;
//最小値を更新できる場合(この辺を使った方が重みが少ない場合)
if (this.minDist[goal] > this.minDist[start] + value) {
this.minDist[goal] = this.minDist[start] + value;
//頂点の数と同じ回数ループしている場合、無限ループになる
//負の閉路があることを検知(マイナスの経路を延々とループ)
if (i == V - 1) {
found = false;
}
}
}
}
//見つかったかどうかを出力
return found;
}
//始点からの最短距離を出力
public long GetDist(int goal) { return this.minDist[goal]; }
}
|
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Threading.Tasks;
/*
・概要
Bellman-Ford法は、
重み付き有向グラフにおける単一始点の最短経路問題を解くアルゴリズム。
辺の重みに負数が存在する場合に主に使う。
(cf. 辺の重みが非負数ならば、ダイクストラ法の方が高速)
・使用法
1. BellmanFordクラスのインスタンスを作成
引数は、頂点数N、始点の番号start
(e.g. BellmanFord graph = new BellmanFord(N,start);)
2. 与えられた辺を追加
引数は、始点、終点、重み
(e.g. graph.AddEdge(start,goal,value);)
3. BellmanFord法で最短距離を決定する
負の閉路で無限ループし、最短距離が求まらない場合は、falseを返す
(e.g. bool found = graph.SetDist();)
4. (最短経路が見つかった場合)始点からの最短距離を取得する
引数は、目的地のインデックス
(e.g. long ans = graph.GetDist(N-1);)
・アルゴリズム(計算量は O (V * E):Vは頂点の数、Eは辺の数)
ループを回して、各ノードへの最短距離を更新し続ける。
・詳細
*/
class Program {
// Main
static void Main(string[] args) {
//読み込む
string[] S = Console.ReadLine().Split(' ');
int N = int.Parse(S[0]);
int M = int.Parse(S[1]);
// 1. BellmanFordクラスのインスタンスを作成
//引数は、頂点数N、始点の番号start
int start = 0;
BellmanFord graph = new BellmanFord(N, start);
// 2. 与えられた辺を追加
for (int i = 0; i < M; i++) {
string[] line = Console.ReadLine().Split(' ');
int a = int.Parse(line[0]) - 1;
int b = int.Parse(line[1]) - 1;
//この問題では最長距離を求めるので、重みの正負を逆転させる
long c = long.Parse(line[2]) * -1;
//辺を追加
/*
引数は、始点、終点、重み
*/
graph.AddEdge(a, b, c);
}
// 3. BellmanFord法で最短距離を決定する
/*
負の閉路で無限ループし、最短距離が求まらない場合は、falseを返す
*/
bool found = graph.SetDist();
//出力
//見つかった場合
if (found) {
// 4. 始点からの最短距離を取得する
//引数は、目的地のインデックス
long ans = graph.GetDist(N - 1);
//この問題では正負を逆転したので、元に戻す
ans = -1 * ans;
Console.WriteLine(ans);
}
//見つからなかった場合
else {
Console.WriteLine("inf");
}
}
}
// Bellman-Ford法を用いて、最短距離を求める為のクラス
class BellmanFord {
//最短距離の初期化に使う変数
/*
大き過ぎると、オーバーフローして大小比較にバグが生じるので注意!!!!
*/
static readonly long inf = 10000000000000;
//辺を保存する構造体
public struct Edge {
//始点
public int Start;
//終点
public int Goal;
//重み(負数もOK)
public long Value;
public Edge(int s, int g, long v) {
this.Start = s;
this.Goal = g;
this.Value = v;
}
}
//辺を保存するリスト
List<Edge> edgeList;
//各頂点への最短距離を保存する配列
long[] minDist;
//コンストラクタ
/*
引数は頂点数、始点の番号
*/
public BellmanFord(int vertex, int start) {
this.edgeList = new List<Edge>();
//各頂点への最短距離をinfで初期化
//但し、始点の場合には0とする
this.minDist = new long[vertex];
for (int i = 0; i < vertex; i++) {
if (i == start) {
continue;
} else {
minDist[i] = inf;
}
}
}
//辺を追加するメソッド
/*
引数は、始点、終点、重み
*/
public void AddEdge(int start, int goal, long value) {
Edge edge = new Edge(start, goal, value);
this.edgeList.Add(edge);
}
// Bellman-Ford法で、最短距離を求めるメソッド
/*
最短距離が求まる場合はtrueを、求まらない場合はfalseを返す
*/
public bool SetDist() {
//最短距離が求まるかのbool
bool found = true;
//頂点数と辺数
int V = this.minDist.Length;
int E = this.edgeList.Count();
//ループで最小値を更新
//各ノードへの到達最小値を更新し続ける
for (int i = 0; i < V; i++) {
for (int j = 0; j < E; j++) {
//当該頂点の始点、終点、重み
int start = edgeList[j].Start;
int goal = edgeList[j].Goal;
long value = edgeList[j].Value;
//最小値を更新できる場合(この辺を使った方が重みが少ない場合)
if (this.minDist[goal] > this.minDist[start] + value) {
this.minDist[goal] = this.minDist[start] + value;
// N回目でかつ最終地点が更新される場合、無限ループする、無限ループになる
//負の閉路があることを検知(マイナスの経路を延々とループ)
if (goal == V - 1 && i == V - 1) {
found = false;
}
}
}
}
//見つかったかどうかを出力
return found;
}
//始点からの最短距離を出力
public long GetDist(int goal) { return this.minDist[goal]; }
}
|
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 21], ["+", 0, 212, 0, 230, 3, 4, 0, 28, 0, 22], ["+", 0, 235, 8, 201, 0, 263, 54, 55, 0, 21], ["+", 8, 201, 0, 263, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 263, 54, 55, 0, 220, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 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, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 235, 8, 201, 0, 263, 8, 196, 0, 46], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98]]
| 8
| 625
| 31
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC061D {
class Program {
static void Main(string[] args) {
var NM = ReadLong();
long N = NM[0];
long M = NM[1];
long[] a = new long[M];
long[] b = new long[M];
long[] c = new long[M];
for (long i = 0; i < M; i++) {
var abc = ReadLong();
a[i] = abc[0] - 1;
b[i] = abc[1] - 1;
c[i] = abc[2];
}
long SMALL = long.MinValue / 2;
long[] cost = new long[N];
for (int i = 0; i < N; i++) {
cost[i] = SMALL;
}
cost[0] = 0;
bool isNegative = false;
for (int j = 0; j < N; j++) {
if (j == N - 1) {
isNegative = true;
break;
}
bool update = false;
for (int i = 0; i < M; i++) {
long start = a[i];
long end = b[i];
long can = cost[start] + c[i];
if (can > cost[end]) {
cost[end] = can;
update = true;
}
}
if (!update)
break;
}
if (isNegative)
Console.WriteLine("inf");
else {
Console.WriteLine(cost[N - 1]);
}
Console.ReadKey();
}
static int[] ReadInt() {
int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
return ret;
}
static long[] ReadLong() {
long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
return ret;
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace ABC061D {
class Program {
static void Main(string[] args) {
var NM = ReadLong();
long N = NM[0];
long M = NM[1];
long[] a = new long[M];
long[] b = new long[M];
long[] c = new long[M];
for (long i = 0; i < M; i++) {
var abc = ReadLong();
a[i] = abc[0] - 1;
b[i] = abc[1] - 1;
c[i] = abc[2];
}
long SMALL = long.MinValue / 2;
long[] cost = new long[N];
for (int i = 0; i < N; i++) {
cost[i] = SMALL;
}
cost[0] = 0;
bool isNegative = false;
for (int j = 0; j < N; j++) {
bool update = false;
for (int i = 0; i < M; i++) {
long start = a[i];
long end = b[i];
long can = cost[start] + c[i];
if (can > cost[end]) {
cost[end] = can;
update = true;
//負の検出
if (j == N - 1 && end == N - 1) {
isNegative = true;
}
}
}
if (!update)
break;
}
if (isNegative)
Console.WriteLine("inf");
else {
Console.WriteLine(cost[N - 1]);
}
Console.ReadKey();
}
static int[] ReadInt() {
int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
return ret;
}
static long[] ReadLong() {
long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
return ret;
}
}
}
|
[["-", 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, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 64, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 423
| 36
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
class Program {
static void Main(string[] args) {
string[] cin = Console.ReadLine().Split();
int n = int.Parse(cin[0]);
int m = int.Parse(cin[1]);
var dist =
Enumerable.Repeat(long.MaxValue, n).ToList(); // 開始点からの距離dist
if (Bellman_ford(n, 0, m, dist))
Console.WriteLine("inf");
else
Console.WriteLine(-dist[n - 1]);
}
static bool Bellman_ford(int n, int s, int m, List<long> dist) {
// グラフの受け取りはこっちでやる
// a→b(コストc)
string[] cin;
int[] a = new int[m];
int[] b = new int[m];
long[] c = new long[m];
for (long i = 0; i < m; i++) {
cin = Console.ReadLine().Split();
a[i] = int.Parse(cin[0]) - 1;
b[i] = int.Parse(cin[1]) - 1;
c[i] = -long.Parse(cin[2]);
}
dist[s] = 0;
for (int i = 1; i < n; i++) {
for (int j = 0; j < m; j++) {
if (dist[b[j]] > dist[a[j]] + c[j])
dist[b[j]] = dist[a[j]] + c[j];
}
}
var dist2 = new List<long>(dist);
bool[] negative = new bool[n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (dist2[b[j]] > dist2[a[j]] + c[j]) {
dist2[b[j]] = dist2[a[j]] + c[j];
negative[b[j]] = true;
}
if (negative[a[j]])
negative[b[j]] = true;
}
}
if (negative[n - 1])
return true;
else
return false;
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
class Program {
static void Main(string[] args) {
string[] cin = Console.ReadLine().Split();
int n = int.Parse(cin[0]);
int m = int.Parse(cin[1]);
var dist =
Enumerable.Repeat(long.MaxValue, n).ToList(); // 開始点からの距離dist
if (Bellman_ford(n, 0, m, dist))
Console.WriteLine("inf");
else
Console.WriteLine(-dist[n - 1]);
}
static bool Bellman_ford(int n, int s, int m, List<long> dist) {
// グラフの受け取りはこっちでやる
// a→b(コストc)
string[] cin;
int[] a = new int[m];
int[] b = new int[m];
long[] c = new long[m];
for (long i = 0; i < m; i++) {
cin = Console.ReadLine().Split();
a[i] = int.Parse(cin[0]) - 1;
b[i] = int.Parse(cin[1]) - 1;
c[i] = -long.Parse(cin[2]);
}
dist[s] = 0;
for (int i = 1; i < n; i++) {
for (int j = 0; j < m; j++) {
if (dist[a[j]] != long.MaxValue && dist[b[j]] > dist[a[j]] + c[j])
dist[b[j]] = dist[a[j]] + c[j];
}
}
var dist2 = new List<long>(dist);
bool[] negative = new bool[n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (dist2[a[j]] != long.MaxValue && dist2[b[j]] > dist2[a[j]] + c[j]) {
dist2[b[j]] = dist2[a[j]] + c[j];
negative[b[j]] = true;
}
if (negative[a[j]])
negative[b[j]] = true;
}
}
if (negative[n - 1])
return true;
else
return false;
}
}
|
[["+", 31, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["+", 0, 57, 15, 16, 31, 16, 12, 214, 205, 199], ["+", 0, 57, 15, 16, 31, 16, 12, 214, 0, 131], ["+", 0, 57, 15, 16, 31, 16, 12, 214, 141, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70]]
| 8
| 500
| 24
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace Practice {
class Program {
static void Main(string[] args) { Solve(); }
private const int MOD = 1000000007;
private struct Node {
public long v;
public long c;
}
private static List<Node>[] g;
private static long[] dist;
static void Solve() {
var o = ReadAndParseLongArr();
var n = o[0];
var m = o[1];
g = new List<Node>[n];
for (int i = 0; i < g.Length; ++i) {
g[i] = new List<Node>();
}
for (int i = 0; i < m; ++i) {
o = ReadAndParseLongArr();
var a = o[0] - 1;
var b = o[1] - 1;
var c = -o[2];
g[a].Add(new Node() { v = b, c = c });
}
bool positive = BellmanFord(n, 0);
var ans = dist[n - 1];
if (positive) {
Console.WriteLine(-ans);
} else {
Console.WriteLine("inf");
}
}
private static bool BellmanFord(long n, long s) {
dist = new long[n];
for (int i = 0; i < n; ++i) {
dist[i] = long.MaxValue;
}
dist[s] = 0;
for (int loop = 0; loop < n; ++loop) {
for (int v = 0; v < n; ++v) {
foreach (var node in g[v]) {
if (dist[v] == long.MaxValue) {
continue;
}
if (dist[node.v] > dist[v] + node.c) {
if (loop == n - 1) {
return false;
}
dist[node.v] = dist[v] + node.c;
}
}
}
}
return true;
}
private static bool Negative2() {
bool[] negatives = new bool[g.Length];
for (int loop = 0; loop < g.Length; ++loop) {
for (int v = 0; v < g.Length; ++v) {
if (dist[v] == long.MaxValue) {
continue;
}
var list = g[v];
foreach (var node in list) {
if (dist[node.v] > dist[v] + node.c) {
dist[node.v] = dist[v] + node.c;
negatives[node.v] = true;
}
if (negatives[v] == true) {
negatives[node.v] = true;
}
}
}
}
return negatives[g.Length - 1];
}
private static bool Negative() {
for (int v = 0; v < g.Length; ++v) {
var list = g[v];
foreach (var node in list) {
// if (dist[v] == long.MaxValue) { continue; }
if (dist[v] + node.c < dist[node.v]) {
return true;
}
}
}
return false;
}
#region よく使う便利関数
private static bool isPrime(long x) {
if (x == 2) {
return true;
}
if (x < 2 || x % 2 == 0) {
return false;
}
long i = 3;
while (i * i <= x) {
if (x % i == 0) {
return false;
}
i = i + 2;
}
return true;
}
private static long lcm(long x, long y) { return x / gcd(x, y) * y; }
private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; }
private static long pow(long x, long n) {
if (n == 0) {
return 1;
}
long res = pow(x * x % MOD, n / 2);
if (n % 2 == 1) {
res = res * x % MOD;
}
return res;
}
private static int ReadAndParseInt() { return int.Parse(Console.ReadLine()); }
private static int[] ReadAndParseIntArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
private static long ReadAndParseLong() {
return long.Parse(Console.ReadLine());
}
private static long[] ReadAndParseLongArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
}
private static void Swap<T>(ref T x, ref T y) {
T t = x;
x = y;
y = t;
}
/// <summary>
/// 指定した値以上の先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値以上の先頭のインデクス</returns>
public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int LowerBound<T>(IReadOnlyList<T> arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
/// <summary>
/// 指定した値より大きい先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値より大きい先頭のインデクス</returns>
public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int UpperBound<T>(IReadOnlyList<T> arr, T value) {
return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
#endregion
}
public class DisjointSet {
private int[] rank;
private int[] p;
private int[] size;
public DisjointSet(int n) {
rank = new int[n];
p = new int[n];
size = new int[n];
for (int i = 0; i < n; ++i) {
MakeSet(i);
}
}
public void MakeSet(int x) {
p[x] = x;
rank[x] = 0;
size[x] = 1;
}
public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); }
public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); }
public void Link(int x, int y) {
if (rank[x] > rank[y]) {
p[y] = x;
size[x] += size[y];
size[y] = 0;
} else {
p[x] = y;
size[y] += size[x];
size[x] = 0;
if (rank[x] == rank[y]) {
rank[y]++;
}
}
}
public int FindSet(int x) {
if (x != p[x]) {
p[x] = FindSet(p[x]);
}
return p[x];
}
public int Size(int x) {
int root = FindSet(x);
return size[root];
}
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
namespace Practice {
class Program {
static void Main(string[] args) { Solve(); }
private const int MOD = 1000000007;
private struct Node {
public long v;
public long c;
}
private static List<Node>[] g;
private static long[] dist;
static void Solve() {
var o = ReadAndParseLongArr();
var n = o[0];
var m = o[1];
g = new List<Node>[n];
for (int i = 0; i < g.Length; ++i) {
g[i] = new List<Node>();
}
for (int i = 0; i < m; ++i) {
o = ReadAndParseLongArr();
var a = o[0] - 1;
var b = o[1] - 1;
var c = -o[2];
g[a].Add(new Node() { v = b, c = c });
}
bool positive = BellmanFord(n, 0);
var ans = dist[n - 1];
if (positive) {
Console.WriteLine(-ans);
} else {
Console.WriteLine("inf");
}
}
private static bool BellmanFord(long n, long s) {
dist = new long[n];
for (int i = 0; i < n; ++i) {
dist[i] = long.MaxValue;
}
dist[s] = 0;
for (int loop = 0; loop < n; ++loop) {
for (int v = 0; v < n; ++v) {
foreach (var node in g[v]) {
if (dist[v] == long.MaxValue) {
continue;
}
if (dist[node.v] > dist[v] + node.c) {
if (loop == n - 1 && node.v == n - 1) {
return false;
}
dist[node.v] = dist[v] + node.c;
}
}
}
}
return true;
}
private static bool Negative2() {
bool[] negatives = new bool[g.Length];
for (int loop = 0; loop < g.Length; ++loop) {
for (int v = 0; v < g.Length; ++v) {
if (dist[v] == long.MaxValue) {
continue;
}
var list = g[v];
foreach (var node in list) {
if (dist[node.v] > dist[v] + node.c) {
dist[node.v] = dist[v] + node.c;
negatives[node.v] = true;
}
if (negatives[v] == true) {
negatives[node.v] = true;
}
}
}
}
return negatives[g.Length - 1];
}
private static bool Negative() {
for (int v = 0; v < g.Length; ++v) {
var list = g[v];
foreach (var node in list) {
// if (dist[v] == long.MaxValue) { continue; }
if (dist[v] + node.c < dist[node.v]) {
return true;
}
}
}
return false;
}
#region よく使う便利関数
private static bool isPrime(long x) {
if (x == 2) {
return true;
}
if (x < 2 || x % 2 == 0) {
return false;
}
long i = 3;
while (i * i <= x) {
if (x % i == 0) {
return false;
}
i = i + 2;
}
return true;
}
private static long lcm(long x, long y) { return x / gcd(x, y) * y; }
private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; }
private static long pow(long x, long n) {
if (n == 0) {
return 1;
}
long res = pow(x * x % MOD, n / 2);
if (n % 2 == 1) {
res = res * x % MOD;
}
return res;
}
private static int ReadAndParseInt() { return int.Parse(Console.ReadLine()); }
private static int[] ReadAndParseIntArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
}
private static long ReadAndParseLong() {
return long.Parse(Console.ReadLine());
}
private static long[] ReadAndParseLongArr() {
return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
}
private static void Swap<T>(ref T x, ref T y) {
T t = x;
x = y;
y = t;
}
/// <summary>
/// 指定した値以上の先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値以上の先頭のインデクス</returns>
public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) < 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int LowerBound<T>(IReadOnlyList<T> arr, T value)
where T : IComparable {
return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
/// <summary>
/// 指定した値より大きい先頭のインデクスを返す
/// </summary>
/// <typeparam name="T">比較する値の型</typeparam>
/// <param name="arr">対象の配列(※ソート済みであること)</param>
/// <param name="start">開始インデクス [inclusive]</param>
/// <param name="end">終了インデクス [exclusive]</param>
/// <param name="value">検索する値</param>
/// <param name="comparer">比較関数(インターフェイス)</param>
/// <returns>指定した値より大きい先頭のインデクス</returns>
public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end,
T value, IComparer<T> comparer) {
int low = start;
int high = end;
int mid;
while (low < high) {
mid = ((high - low) >> 1) + low;
if (comparer.Compare(arr[mid], value) <= 0)
low = mid + 1;
else
high = mid;
}
return low;
}
//引数省略のオーバーロード
public static int UpperBound<T>(IReadOnlyList<T> arr, T value) {
return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default);
}
#endregion
}
public class DisjointSet {
private int[] rank;
private int[] p;
private int[] size;
public DisjointSet(int n) {
rank = new int[n];
p = new int[n];
size = new int[n];
for (int i = 0; i < n; ++i) {
MakeSet(i);
}
}
public void MakeSet(int x) {
p[x] = x;
rank[x] = 0;
size[x] = 1;
}
public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); }
public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); }
public void Link(int x, int y) {
if (rank[x] > rank[y]) {
p[y] = x;
size[x] += size[y];
size[y] = 0;
} else {
p[x] = y;
size[y] += size[x];
size[x] = 0;
if (rank[x] == rank[y]) {
rank[y]++;
}
}
}
public int FindSet(int x) {
if (x != p[x]) {
p[x] = FindSet(p[x]);
}
return p[x];
}
public int Size(int x) {
int root = FindSet(x);
return size[root];
}
}
}
|
[["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 205, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 0, 131], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 141, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 12, 203]]
| 8
| 1,607
| 8
|
using System;
class Program {
static void Main() {
long[] s = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
long[] h = new long[s[0] + 1];
for (int i = 1; i <= s[0]; i++) {
h[i] = long.MinValue;
}
h[1] = 0;
long[][] arr = new long[s[1]][];
for (int i = 0; i < s[1]; i++) {
arr[i] = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
}
long l = 0;
bool b = true;
while (b && l <= s[0]) {
l++;
b = false;
for (int i = 0; i < s[1]; i++) {
if (h[arr[i][0]] != long.MinValue &&
h[arr[i][1]] < h[arr[i][0]] + arr[i][2]) {
h[arr[i][1]] = h[arr[i][0]] + arr[i][2];
b = true;
}
}
}
Console.WriteLine("{0}", l > s[0] ? "inf" : h[s[0]].ToString());
}
}
|
using System;
class Program {
static void Main() {
long[] s = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
long[] h = new long[s[0] + 1];
for (int i = 1; i <= s[0]; i++) {
h[i] = long.MinValue;
}
h[1] = 0;
long[][] arr = new long[s[1]][];
for (int i = 0; i < s[1]; i++) {
arr[i] = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
}
long l = 0;
bool b = false;
while (l <= s[0] + 1) {
l++;
for (int i = 0; i < s[1]; i++) {
if (h[arr[i][0]] != long.MinValue &&
h[arr[i][1]] < h[arr[i][0]] + arr[i][2]) {
h[arr[i][1]] = h[arr[i][0]] + arr[i][2];
if (l > s[0] && arr[i][1] == s[0]) {
b = true;
}
}
}
}
Console.WriteLine("{0}", b ? "inf" : h[s[0]].ToString());
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 211, 0, 146], ["+", 0, 198, 0, 200, 0, 212, 0, 211, 0, 147], ["-", 0, 195, 8, 196, 0, 52, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 98], ["+", 8, 196, 0, 52, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 52, 15, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 196, 0, 1, 0, 11, 12, 211, 0, 147], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 0, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98], ["+", 15, 16, 12, 16, 31, 204, 205, 204, 205, 22], ["+", 12, 16, 31, 204, 205, 204, 206, 207, 0, 70], ["+", 31, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 12, 16, 31, 204, 205, 204, 206, 207, 0, 73], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["-", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 47], ["-", 0, 28, 0, 41, 15, 16, 12, 204, 205, 22], ["-", 0, 41, 15, 16, 12, 204, 206, 207, 0, 70], ["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 41, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 15, 22]]
| 8
| 314
| 41
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace Program {
class MainClass {
// C#Lover///////////////////////////////////////////////////
int N, M;
int[] a, b;
long[] c;
void Solve() {
io.i(out N, out M);
a = new int[M];
b = new int[M];
c = new long[M];
M.REP(i => {
a[i] = io.Int;
b[i] = io.Int;
c[i] = io.Long * -1;
});
var bf = new BellmanFord(false);
bf.Init(N);
bf.AddPath(a, b, c);
bf.MinCost(1, N);
io.o(bf.loopExist() ? "inf" : (bf.cost[N] * (-1)).ToString());
}
////////////////////////////////////////////////////////////
public static void Main(string[] args) { new MainClass().Stream(); }
IO io = new IO();
void Stream() {
Solve();
io.writeFlush();
}
// void Stream() { Test(); io.writeFlush(); }
void Test() {
List<int> li1 = new List<int>() { 1, 2, 3 };
List<int> li2 = new List<int>(li1) { 4, 5, 6 };
io.ol(li2.ToArray());
}
#region MockMacro
// cannot use break,continue,goto
void FOR(int a, int b, Action<int> act) {
for (int i = a; i < b; i++)
act(i);
}
void FORR(int a, int b, Action<int> act) {
for (int i = a - 1; i >= b; i--)
act(i);
}
#endregion
}
#region default
class IO {
TYPE tp;
string[] nextBuffer;
int BufferCnt;
char[] cs = new char[] { ' ' };
StreamWriter sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
public IO() {
nextBuffer = new string[0];
BufferCnt = 0;
Console.SetOut(sw);
tp = new TYPE();
}
public string Next() {
if (BufferCnt < nextBuffer.Length)
return nextBuffer[BufferCnt++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
BufferCnt = 0;
return nextBuffer[BufferCnt++];
}
public string String => Next();
public char Char => char.Parse(String);
public int Int => int.Parse(String);
public long Long => long.Parse(String);
public double Double => double.Parse(String);
public string[] arr => Console.ReadLine().Split(' ');
public char[] arrChar => Array.ConvertAll(arr, char.Parse);
public int[] arrInt => Array.ConvertAll(arr, int.Parse);
public long[] arrLong => Array.ConvertAll(arr, long.Parse);
public double[] arrDouble => Array.ConvertAll(arr, double.Parse);
public T i<T>() { return tp.suitType<T>(String); }
public void i<T>(out T v) { v = tp.suitType<T>(String); }
public void i<T, U>(out T v1, out U v2) {
i(out v1);
i(out v2);
}
public void i<T, U, V>(out T v1, out U v2, out V v3) {
i(out v1);
i(out v2);
i(out v3);
}
public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) {
i(out v1);
i(out v2);
i(out v3);
i(out v4);
}
public void i<T, U, V, W, X>(out T v1, out U v2, out V v3, out W v4,
out X v5) {
i(out v1);
i(out v2);
i(out v3);
i(out v4);
i(out v5);
}
public void ini<T>(out T[] a, int n) {
a = new T[n];
for (int i = 0; i < n; i++)
a[i] = tp.suitType<T>(String);
}
public void ini<T>(out T[] a, out T[] b, int n) {
a = new T[n];
b = new T[n];
for (int i = 0; i < n; i++) {
a[i] = i<T>();
b[i] = i<T>();
}
}
public void ini<T>(out T[,] a, int h, int w) {
a = new T[h, w];
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
a[i, j] = i<T>();
}
public void o<T>(T v) { Console.WriteLine(v); }
public void o<T>(params T[] a) { Array.ForEach(a, n => o(n)); }
public void o<T>(T[,] a) {
a.GetLength(0).REP(i => {
a.GetLength(1).REP(j => or(a[i, j] + " "));
br();
});
}
public void ol<T>(T v) { Console.Write(v + " "); }
public void ol<T>(params T[] a) { o(connect<T>(a)); }
public void or<T>(T a) { Console.Write(a); }
public void br() { o(""); }
public void writeFlush() { Console.Out.Flush(); }
private string connect<T>(params T[] s) { return string.Join(" ", s); }
}
class TYPE {
public bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); }
public T convertType<T, U>(U v) {
return (T)Convert.ChangeType(v, typeof(T));
}
public T suitType<T>(string s) {
if (typeEQ<T, int>())
return convertType<T, int>(int.Parse(s));
if (typeEQ<T, long>())
return convertType<T, long>(long.Parse(s));
if (typeEQ<T, double>())
return convertType<T, double>(double.Parse(s));
if (typeEQ<T, char>())
return convertType<T, char>(char.Parse(s));
return convertType<T, string>(s);
}
}
class PQueue<T>
where T : IComparable {
public List<T> heap;
private Comparison<T> comp;
private IComparer<T> comparer;
private int size = 0;
private int type;
public PQueue(int type = 0) : this(Comparer<T>.Default) { this.type = type; }
public PQueue(IComparer<T> comparer) : this(16, comparer.Compare) {
this.comparer = comparer;
}
public PQueue(Comparison<T> comparison) : this(16, comparison) {}
public PQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.comp = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (Compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && Compare(heap[b], heap[a]) < 0)
a = b;
if (Compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
public bool Empty() { return !Any(); }
public bool Contains(T v) { return heap.Contains(v); }
private int Compare(T x, T y) {
return type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
}
#endregion
#region other
class Mat {
public int mod = 1000000007; // 10^9+7
public long Pow(long a, long b) {
if (b == 0)
return 1;
if (b % 2 == 1)
return (a % mod * Pow(a % mod, b - 1) % mod) % mod;
else
return Pow(a * a % mod, b / 2) % mod;
}
public long Fact(long n) {
long ret = 1;
for (long i = 1; i <= n; i++)
ret = (ret * i) % mod;
return ret;
}
public long C(long n, long r) {
if (r == 0 || n == r)
return 1;
else if (n == 0)
return 0;
else if (n < 0 || n < r)
throw new ArgumentException("n,r invalid");
else
return (Fact(n) % mod *
Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) %
mod;
}
public long DupC(long n, long r) { return C(n + r - 1, r); }
public long P(long n, long r) { return Fact(n) / (Fact(n - r)); } // test
public bool isPrime(long n) {
if (n == 2)
return true;
if (n < 2 || n % 2 == 0)
return false;
for (long v = 3; v <= (long)Math.Sqrt(n); v += 2)
if (n % v == 0)
return false;
return true;
}
public long LCM(long a, long b) { return a * (b / GCD(a, b)); }
public long LCM(params long[] a) { return a.Aggregate((v, n) => LCM(v, n)); }
public long GCD(long a, long b) {
if (a < b)
Swap(ref a, ref b);
return b == 0 ? a : GCD(b, a % b);
}
public long GCD(params long[] array) {
return array.Aggregate((v, n) => GCD(v, n));
}
public T Max<T>(params T[] a) { return a.Max(); }
public T Min<T>(params T[] a) { return a.Min(); }
public void Swap<T>(ref T a, ref T b) {
T tmp = a;
a = b;
b = tmp;
}
public double Dis(int x1, int y1, int x2, int y2) {
return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2));
}
public int mDis(int x1, int y1, int x2, int y2) {
return Math.Abs(x1 - x2) + Math.Abs(y1 - y2);
}
public int Dig2Num(IEnumerable<int> enu) { // test
int ret = 0;
foreach (var v in enu) {
ret *= 10;
ret += v;
}
return ret;
}
public int Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; }
public int DigVal(int n, int dig) {
return (n % (int)Pow(10, dig)) / (int)Pow(10, dig - 1);
}
public int[] DigValArr(int n) {
int[] ret = new int[Digit(n)];
ret.Length.REP(i => ret[i] = DigVal(n, i + 1));
return ret;
}
public long Tousa(long a, long d, int n) { return a + (n - 1) * d; }
public long TousaSum(long a, long d, int n) {
return n * (2 * a + (n - 1) * d) / 2;
}
public IEnumerable<int[]> eunP(int[] Arr, int Use = -1) { //列挙順列
Use = (Use != -1) ? Use : Arr.Length;
if (Use == 0 || Arr.Length < Use)
yield break;
var s = new Stack<List<int>>();
Arr.Length.REPR(i => s.Push(new List<int>() { i }));
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Count == Use) {
var ret = new List<int>();
cur.ForEach(X => ret.Add(Arr[X]));
yield return ret.ToArray();
} else
Arr.Length.REPR(i => {
if (!cur.Contains(i))
s.Push(new List<int>(cur) { i });
});
}
}
public IEnumerable<int[]> enuC(int[] Arr, int Use = -1) { //列挙組み合わせ
Use = (Use != -1) ? Use : Arr.Length;
if (Use == 0 || Arr.Length < Use)
yield break;
var s = new Stack<Tuple<int, List<int>>>();
Arr.Length.REPR(i => s.Push(Tuple.Create(i, new List<int>() { Arr[i] })));
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Item2.Count == Use)
yield return cur.Item2.ToArray();
else
for (int i = Arr.GetUpperBound(0); i > cur.Item1; i--)
s.Push(Tuple.Create(i, new List<int>(cur.Item2) { Arr[i] }));
}
}
public IEnumerable<int[]> eunDupP(int[] Arr, int Use = -1) { //列挙重複順列
Use = (Use != -1) ? Use : Arr.Length;
if (Use == 0)
yield break;
var s = new Stack<List<int>>();
Arr.Length.REPR(i => s.Push(new List<int>() { Arr[i] }));
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Count == Use)
yield return cur.ToArray();
else
Arr.Length.REPR(i => s.Push(new List<int>(cur) { Arr[i] }));
}
}
public IEnumerable<int[]> enuDupC(int[] Arr, int Use = -1) { //列挙組み合わせ
Use = (Use != -1) ? Use : Arr.Length;
if (Use == 0)
yield break;
var s = new Stack<Tuple<int, List<int>>>();
Arr.Length.REPR(i => s.Push(Tuple.Create(i, new List<int>() { Arr[i] })));
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Item2.Count == Use)
yield return cur.Item2.ToArray();
else
for (int i = Arr.GetUpperBound(0); i >= cur.Item1; i--)
s.Push(Tuple.Create(i, new List<int>(cur.Item2) { Arr[i] }));
}
}
public IEnumerable<long[]> enuPart(string str) {
var s = new Stack<Tuple<string, List<long>, int>>();
s.Push(Tuple.Create(str[0].ToString(), new List<long>(), 1));
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Item3 >= str.Length) {
yield return (new List<long>(cur.Item2) { cur.Item1.toLong() })
.ToArray();
} else {
//繋げる
s.Push(Tuple.Create(cur.Item1 + str[cur.Item3],
new List<long>(cur.Item2), cur.Item3 + 1));
//繋がない
s.Push(Tuple.Create(str[cur.Item3].ToString(),
new List<long>(cur.Item2) { cur.Item1.toLong() },
cur.Item3 + 1));
}
}
}
}
class AssociativeArray<T>
: IEnumerable { // hack:KeyValuePairの利用に制限がかかる
public Dictionary<T, int> dic;
public AssociativeArray() { dic = new Dictionary<T, int>(); }
public AssociativeArray(params T[] a) {
dic = new Dictionary<T, int>();
Add(a);
}
public void Add(params T[] a) {
a.Length.REP(i => {
if (!conK(a[i]))
dic[a[i]] = 0;
dic[a[i]]++;
});
}
public void Set(T k, int v) {
if (!dic.ContainsKey(k))
dic[k] = 0;
dic[k] = v;
}
public void Remove(params T[] a) {
a.Length.REP(i => {
if (conK(a[i]))
dic.Remove(a[i]);
});
}
public T[] Keys() { return dic.Keys.ToArray<T>(); }
public int Val(T k) { return (dic.ContainsKey(k)) ? dic[k] : 0; }
public int ValSum => dic.Values.Sum();
public int KeyNum => dic.Keys.Count;
public int MaxVal => dic.Values.Max();
public int MinVal => dic.Values.Min();
public T MaxKey => dic.First(d => d.Value == MaxVal).Key;
public T MinKey => dic.First(d => d.Value == MinVal).Key;
public bool conK(T k) { return dic.ContainsKey(k); }
public bool anyK(params T[] k) { return k.Any(key => conK(key)); }
public bool allK(params T[] k) { return k.All(key => conK(key)); }
public void Show() {
foreach (var v in dic) {
Console.WriteLine(v.Key + " : " + v.Value);
}
}
public IEnumerator GetEnumerator() {
foreach (var kp in dic)
yield return kp;
}
//:sort->array
}
class UnionFind {
public int[] parent;
public int[] depth;
public void Init(int n) {
parent = new int[n];
depth = new int[n];
n.REP(i => parent[i] = i);
}
public int Find(int x) {
return (parent[x] == x) ? x : parent[x] = Find(parent[x]);
}
public void Unite(int x, int y) {
x = Find(x);
y = Find(y);
if (x == y)
return;
if (depth[x] < depth[y])
parent[x] = y;
else {
parent[y] = x;
if (depth[x] == depth[y])
depth[x]++;
}
}
public bool Same(int a, int b) { return Find(a) == Find(b); }
}
class Time {
public bool isLeapYear(int y) {
return (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0));
}
}
#endregion
#region Graph
class Index {
public int[] Comp(int[] bef) {
int[] aft = new int[bef.Length];
var tmp = bef.Distinct()
.OrderBy(v => v)
.Select((v, i) => new { v, i })
.ToDictionary(p => p.v, p => p.i);
aft = bef.Select(v => tmp[v]).ToArray();
return aft;
}
}
class BasicGraph { //けす
public List<Tuple<int, long>>[] G;
public void Init(int n) {
G = new List<Tuple<int, long>>[n + 1];
G.Length.REP(i => G[i] = new List<Tuple<int, long>>());
}
public void Dir(int[] f, int[] t) {
f.Length.REP(i => G[f[i]].Add(Tuple.Create(t[i], 1L)));
}
public void Dir(int[] f, int[] t, long[] c) {
f.Length.REP(i => G[f[i]].Add(Tuple.Create(t[i], c[i])));
}
public void NonDir(int[] f, int[] t) {
f.Length.REP(i => {
G[f[i]].Add(Tuple.Create(t[i], 1L));
G[t[i]].Add(Tuple.Create(f[i], 1L));
});
}
public void NonDir(int[] f, int[] t, long[] c) {
f.Length.REP(i => {
G[f[i]].Add(Tuple.Create(t[i], c[i]));
G[t[i]].Add(Tuple.Create(f[i], c[i]));
});
}
}
class TreeDis { // test
public List<Tuple<long, long>>[] g;
public long[] a2other;
private int type;
public TreeDis(int type = 0) { this.type = type; } // 0->bfs,other->dfs
public void Init(long n) {
g = new List<Tuple<long, long>>[n + 1];
g.Length.REP(i => g[i] = new List<Tuple<long, long>>());
}
public void Run(long[] a, long[] b) {
a.Length.REP(i => {
g[a[i]].Add(Tuple.Create(b[i], 1L));
g[b[i]].Add(Tuple.Create(a[i], 1L));
});
}
public void Run(long[] a, long[] b, long[] w) {
a.Length.REP(i => {
g[a[i]].Add(Tuple.Create(b[i], w[i]));
g[b[i]].Add(Tuple.Create(a[i], w[i]));
});
}
public long[] a2iArr(long a) {
a2other = new long[g.Count()];
if (type == 0)
BFS(a);
else
DFS(a);
return a2other;
}
private void BFS(long a) {
var q = new Queue<Tuple<long, long>>();
q.Enqueue(Tuple.Create(a, -1L));
while (q.Count > 0) {
var c = q.Dequeue();
foreach (var v in g[c.Item1]) {
if (v.Item1 == c.Item2)
continue;
a2other[v.Item1] = a2other[c.Item1] + v.Item2;
q.Enqueue(Tuple.Create(v.Item1, c.Item1));
}
}
}
private void DFS(long a) {
var s = new Stack<Tuple<long, long>>();
s.Push(Tuple.Create(a, -1L));
while (s.Count > 0) {
var c = s.Pop();
foreach (var v in g[c.Item1]) {
if (v.Item1 == c.Item2)
continue;
a2other[v.Item1] = a2other[c.Item1] + v.Item2;
s.Push(Tuple.Create(v.Item1, c.Item1));
}
}
}
}
class ShortestPath {
public long INF = (int)1e9;
protected int I = -1;
public long[] cost;
protected List<Tuple<int, long>>[] Adj;
protected bool isNonDir = true;
public void Init(int n) {
I = n + 1;
Adj = new List<Tuple<int, long>>[I];
I.REP(i => Adj[i] = new List<Tuple<int, long>>());
}
public void AddPath(int f, int t, long c) {
if (isNonDir) {
Adj[f].Add(Tuple.Create(t, c));
Adj[t].Add(Tuple.Create(f, c));
} else {
Adj[f].Add(Tuple.Create(t, c));
}
}
public void AddPath(int[] f, int[] t, long[] c) {
f.Length.REP(i => AddPath(f[i], t[i], c[i]));
}
}
class Dijkstra : ShortestPath { //隣接対応後検証不足,有向
public long MinCost(int f, int t) {
cost = new long[I];
cost.Set(INF);
cost[f] = 0;
var pq = new PQueue<Tuple<int, long>>();
pq.Enqueue(Tuple.Create(f, 0L)); //(from,cost)
while (pq.Count > 0) {
var cur = pq.Dequeue();
if (cost[cur.Item1] < cur.Item2)
continue;
Adj[cur.Item1].Count.REP(i => {
var tmp = Adj[cur.Item1][i];
if (cost[tmp.Item1] > cost[cur.Item1] + tmp.Item2) {
cost[tmp.Item1] = cost[cur.Item1] + tmp.Item2;
pq.Enqueue(Tuple.Create(tmp.Item1, cost[tmp.Item1]));
}
});
}
return cost[t];
}
}
class BellmanFord : ShortestPath {
private bool[] neg;
public BellmanFord() {}
public BellmanFord(bool isNonDir) { this.isNonDir = isNonDir; }
public long MinCost(int f, int t) {
cost = new long[I];
cost.Set(INF);
neg = new bool[I];
bool isUpdate = true;
cost[f] = 0;
/*
while (isUpdate && !neg[I-1]) {
isUpdate = false;
I.REP(i => Adj[i].Count.REP(j => {
var cur = Adj[i][j];
if (cost[cur.Item1] > cost[i] + cur.Item2) {
cost[cur.Item1] = cost[i] + cur.Item2;
isUpdate = true;
neg[cur.Item1] = true;
}
if (neg[i])
neg[cur.Item1] = true;
}));
isUpdate = true;
}*/
for (int i = 0; i < I - 1; i++) {
I.REP(j => Adj[j].Count.REP(k => {
var cur = Adj[j][k];
if (cost[cur.Item1] > cost[j] + cur.Item2) {
cost[cur.Item1] = cost[j] + cur.Item2;
}
}));
}
for (int i = 0; i < I; i++) {
I.REP(j => Adj[j].Count.REP(k => {
var cur = Adj[j][k];
if (cost[cur.Item1] > cost[j] + cur.Item2) {
cost[cur.Item1] = cost[j] + cur.Item2;
neg[cur.Item1] = true;
}
if (neg[j])
neg[cur.Item1] = true;
}));
}
return cost[t];
}
public bool loopExist() { return neg[I - 1]; }
}
class WarshallFloyd { //そのうちAdjとどっちがいいか...TODO:ジェネリック
private int E;
private int INF = (int)1e9;
public long[,] G;
public void Init(int n) {
E = n + 1;
G = new long[E, E];
G.Set(INF);
E.REP(i => G[i, i] = 0);
}
public void AddPath(int f, int t, long c) {
G[f, t] = c;
G[t, f] = c;
}
public void AddPath(int[] f, int[] t) {
f.Length.REP(i => AddPath(f[i], t[i], 1));
}
public void AddPath(int[] f, int[] t, long[] c) {
f.Length.REP(i => AddPath(f[i], t[i], c[i]));
}
public void Run() { G = MinCostArr(); }
public long[,] MinCostArr() {
E.REP(i => E.REP(
j => E.REP(k => G[j, k] = Math.Min(G[j, k], G[j, i] + G[i, k]))));
return G;
}
}
#endregion
#region Ex
static class StringEX { //文字
public static string Reversed(this string s) {
return string.Join("", s.Reverse());
}
public static string Repeat(this string s, int n) {
return string.Concat(Enumerable.Repeat(s, n).ToArray());
}
public static int toInt(this string s) {
int n;
return (int.TryParse(s.TrimStart('0'), out n)) ? n : 0;
}
public static int toInt(this char c) { return toInt(c.ToString()); }
public static int toInt(this char[] c) { return toInt(new string(c)); }
public static long toLong(this string s) {
long n;
return (long.TryParse(s.TrimStart('0'), out n)) ? n : (long)0;
}
public static long toLong(this char c) { return toLong(c.ToString()); }
public static long toLong(this char[] c) { return toLong(new string(c)); }
public static string toString(this char[] c) { return new string(c); }
}
static class NumericEx { //数値
public static string pad0<T>(this T v, int n) {
return v.ToString().PadLeft(n, '0');
}
public static double RoundOff(this double v, int n) {
return Math.Round(v, n - 1, MidpointRounding.AwayFromZero);
}
public static bool Odd(this int v) { return v % 2 != 0; }
public static bool Odd(this long v) { return v % 2 != 0; }
public static void REP(this int v, Action<int> act) {
for (int i = 0; i < v; ++i)
act(i);
}
public static void REPR(this int v, Action<int> act) {
for (int i = v - 1; i >= 0; --i)
act(i);
}
}
static class ArrayEX {
public static T[] Sort<T>(this T[] a) {
Array.Sort(a);
return a;
}
public static T[] SortR<T>(this T[] a) {
Array.Sort(a);
Array.Reverse(a);
return a;
}
public static void Set<T>(this T[] a, T v) { a.Length.REP(i => a[i] = v); }
public static void Set<T>(this T[,] a, T v) {
a.GetLength(0).REP(i => a.GetLength(1).REP(j => a[i, j] = v));
}
}
static class BitEx {
public static bool Any(this BitArray b) {
foreach (bool f in b)
if (f)
return true;
return false;
}
public static bool All(this BitArray b) {
foreach (bool f in b)
if (!f)
return false;
return true;
}
public static bool None(this BitArray b) { return !Any(b); }
public static void Flip(this BitArray b, int index) {
b.Set(index, !b.Get(index));
}
}
static class TestEx {
// operator
}
#endregion
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace Program {
class MainClass {
// C#Lover///////////////////////////////////////////////////
int N, M;
int[] a, b;
long[] c;
void Solve() {
io.i(out N, out M);
a = new int[M];
b = new int[M];
c = new long[M];
M.REP(i => {
a[i] = io.Int;
b[i] = io.Int;
c[i] = io.Long * -1;
});
var bf = new BellmanFord(false);
bf.Init(N);
bf.AddPath(a, b, c);
bf.MinCost(1, N);
io.o(bf.loopExist() ? "inf" : (bf.cost[N] * (-1)).ToString());
}
////////////////////////////////////////////////////////////
public static void Main(string[] args) { new MainClass().Stream(); }
IO io = new IO();
void Stream() {
Solve();
io.writeFlush();
}
// void Stream() { Test(); io.writeFlush(); }
void Test() {
List<int> li1 = new List<int>() { 1, 2, 3 };
List<int> li2 = new List<int>(li1) { 4, 5, 6 };
io.ol(li2.ToArray());
}
#region MockMacro
// cannot use break,continue,goto
void FOR(int a, int b, Action<int> act) {
for (int i = a; i < b; i++)
act(i);
}
void FORR(int a, int b, Action<int> act) {
for (int i = a - 1; i >= b; i--)
act(i);
}
#endregion
}
#region default
class IO {
TYPE tp;
string[] nextBuffer;
int BufferCnt;
char[] cs = new char[] { ' ' };
StreamWriter sw =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
public IO() {
nextBuffer = new string[0];
BufferCnt = 0;
Console.SetOut(sw);
tp = new TYPE();
}
public string Next() {
if (BufferCnt < nextBuffer.Length)
return nextBuffer[BufferCnt++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
BufferCnt = 0;
return nextBuffer[BufferCnt++];
}
public string String => Next();
public char Char => char.Parse(String);
public int Int => int.Parse(String);
public long Long => long.Parse(String);
public double Double => double.Parse(String);
public string[] arr => Console.ReadLine().Split(' ');
public char[] arrChar => Array.ConvertAll(arr, char.Parse);
public int[] arrInt => Array.ConvertAll(arr, int.Parse);
public long[] arrLong => Array.ConvertAll(arr, long.Parse);
public double[] arrDouble => Array.ConvertAll(arr, double.Parse);
public T i<T>() { return tp.suitType<T>(String); }
public void i<T>(out T v) { v = tp.suitType<T>(String); }
public void i<T, U>(out T v1, out U v2) {
i(out v1);
i(out v2);
}
public void i<T, U, V>(out T v1, out U v2, out V v3) {
i(out v1);
i(out v2);
i(out v3);
}
public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) {
i(out v1);
i(out v2);
i(out v3);
i(out v4);
}
public void i<T, U, V, W, X>(out T v1, out U v2, out V v3, out W v4,
out X v5) {
i(out v1);
i(out v2);
i(out v3);
i(out v4);
i(out v5);
}
public void ini<T>(out T[] a, int n) {
a = new T[n];
for (int i = 0; i < n; i++)
a[i] = tp.suitType<T>(String);
}
public void ini<T>(out T[] a, out T[] b, int n) {
a = new T[n];
b = new T[n];
for (int i = 0; i < n; i++) {
a[i] = i<T>();
b[i] = i<T>();
}
}
public void ini<T>(out T[,] a, int h, int w) {
a = new T[h, w];
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
a[i, j] = i<T>();
}
public void o<T>(T v) { Console.WriteLine(v); }
public void o<T>(params T[] a) { Array.ForEach(a, n => o(n)); }
public void o<T>(T[,] a) {
a.GetLength(0).REP(i => {
a.GetLength(1).REP(j => or(a[i, j] + " "));
br();
});
}
public void ol<T>(T v) { Console.Write(v + " "); }
public void ol<T>(params T[] a) { o(connect<T>(a)); }
public void or<T>(T a) { Console.Write(a); }
public void br() { o(""); }
public void writeFlush() { Console.Out.Flush(); }
private string connect<T>(params T[] s) { return string.Join(" ", s); }
}
class TYPE {
public bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); }
public T convertType<T, U>(U v) {
return (T)Convert.ChangeType(v, typeof(T));
}
public T suitType<T>(string s) {
if (typeEQ<T, int>())
return convertType<T, int>(int.Parse(s));
if (typeEQ<T, long>())
return convertType<T, long>(long.Parse(s));
if (typeEQ<T, double>())
return convertType<T, double>(double.Parse(s));
if (typeEQ<T, char>())
return convertType<T, char>(char.Parse(s));
return convertType<T, string>(s);
}
}
class PQueue<T>
where T : IComparable {
public List<T> heap;
private Comparison<T> comp;
private IComparer<T> comparer;
private int size = 0;
private int type;
public PQueue(int type = 0) : this(Comparer<T>.Default) { this.type = type; }
public PQueue(IComparer<T> comparer) : this(16, comparer.Compare) {
this.comparer = comparer;
}
public PQueue(Comparison<T> comparison) : this(16, comparison) {}
public PQueue(int capacity, Comparison<T> comparison) {
this.heap = new List<T>(capacity);
this.comp = comparison;
}
public void Enqueue(T item) {
this.heap.Add(item);
var i = size++;
while (i > 0) {
var p = (i - 1) >> 1;
if (Compare(this.heap[p], item) <= 0)
break;
this.heap[i] = heap[p];
i = p;
}
this.heap[i] = item;
}
public T Dequeue() {
var ret = this.heap[0];
var x = this.heap[--size];
var i = 0;
while ((i << 1) + 1 < size) {
var a = (i << 1) + 1;
var b = (i << 1) + 2;
if (b < size && Compare(heap[b], heap[a]) < 0)
a = b;
if (Compare(heap[a], x) >= 0)
break;
heap[i] = heap[a];
i = a;
}
heap[i] = x;
heap.RemoveAt(size);
return ret;
}
public T Peek() { return heap[0]; }
public int Count {
get { return size; }
}
public bool Any() { return size > 0; }
public bool Empty() { return !Any(); }
public bool Contains(T v) { return heap.Contains(v); }
private int Compare(T x, T y) {
return type == 0 ? x.CompareTo(y) : y.CompareTo(x);
}
}
#endregion
#region other
class Mat {
public int mod = 1000000007; // 10^9+7
public long Pow(long a, long b) {
if (b == 0)
return 1;
if (b % 2 == 1)
return (a % mod * Pow(a % mod, b - 1) % mod) % mod;
else
return Pow(a * a % mod, b / 2) % mod;
}
public long Fact(long n) {
long ret = 1;
for (long i = 1; i <= n; i++)
ret = (ret * i) % mod;
return ret;
}
public long C(long n, long r) {
if (r == 0 || n == r)
return 1;
else if (n == 0)
return 0;
else if (n < 0 || n < r)
throw new ArgumentException("n,r invalid");
else
return (Fact(n) % mod *
Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) %
mod;
}
public long DupC(long n, long r) { return C(n + r - 1, r); }
public long P(long n, long r) { return Fact(n) / (Fact(n - r)); } // test
public bool isPrime(long n) {
if (n == 2)
return true;
if (n < 2 || n % 2 == 0)
return false;
for (long v = 3; v <= (long)Math.Sqrt(n); v += 2)
if (n % v == 0)
return false;
return true;
}
public long LCM(long a, long b) { return a * (b / GCD(a, b)); }
public long LCM(params long[] a) { return a.Aggregate((v, n) => LCM(v, n)); }
public long GCD(long a, long b) {
if (a < b)
Swap(ref a, ref b);
return b == 0 ? a : GCD(b, a % b);
}
public long GCD(params long[] array) {
return array.Aggregate((v, n) => GCD(v, n));
}
public T Max<T>(params T[] a) { return a.Max(); }
public T Min<T>(params T[] a) { return a.Min(); }
public void Swap<T>(ref T a, ref T b) {
T tmp = a;
a = b;
b = tmp;
}
public double Dis(int x1, int y1, int x2, int y2) {
return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2));
}
public int mDis(int x1, int y1, int x2, int y2) {
return Math.Abs(x1 - x2) + Math.Abs(y1 - y2);
}
public int Dig2Num(IEnumerable<int> enu) { // test
int ret = 0;
foreach (var v in enu) {
ret *= 10;
ret += v;
}
return ret;
}
public int Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; }
public int DigVal(int n, int dig) {
return (n % (int)Pow(10, dig)) / (int)Pow(10, dig - 1);
}
public int[] DigValArr(int n) {
int[] ret = new int[Digit(n)];
ret.Length.REP(i => ret[i] = DigVal(n, i + 1));
return ret;
}
public long Tousa(long a, long d, int n) { return a + (n - 1) * d; }
public long TousaSum(long a, long d, int n) {
return n * (2 * a + (n - 1) * d) / 2;
}
public IEnumerable<int[]> eunP(int[] Arr, int Use = -1) { //列挙順列
Use = (Use != -1) ? Use : Arr.Length;
if (Use == 0 || Arr.Length < Use)
yield break;
var s = new Stack<List<int>>();
Arr.Length.REPR(i => s.Push(new List<int>() { i }));
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Count == Use) {
var ret = new List<int>();
cur.ForEach(X => ret.Add(Arr[X]));
yield return ret.ToArray();
} else
Arr.Length.REPR(i => {
if (!cur.Contains(i))
s.Push(new List<int>(cur) { i });
});
}
}
public IEnumerable<int[]> enuC(int[] Arr, int Use = -1) { //列挙組み合わせ
Use = (Use != -1) ? Use : Arr.Length;
if (Use == 0 || Arr.Length < Use)
yield break;
var s = new Stack<Tuple<int, List<int>>>();
Arr.Length.REPR(i => s.Push(Tuple.Create(i, new List<int>() { Arr[i] })));
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Item2.Count == Use)
yield return cur.Item2.ToArray();
else
for (int i = Arr.GetUpperBound(0); i > cur.Item1; i--)
s.Push(Tuple.Create(i, new List<int>(cur.Item2) { Arr[i] }));
}
}
public IEnumerable<int[]> eunDupP(int[] Arr, int Use = -1) { //列挙重複順列
Use = (Use != -1) ? Use : Arr.Length;
if (Use == 0)
yield break;
var s = new Stack<List<int>>();
Arr.Length.REPR(i => s.Push(new List<int>() { Arr[i] }));
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Count == Use)
yield return cur.ToArray();
else
Arr.Length.REPR(i => s.Push(new List<int>(cur) { Arr[i] }));
}
}
public IEnumerable<int[]> enuDupC(int[] Arr, int Use = -1) { //列挙組み合わせ
Use = (Use != -1) ? Use : Arr.Length;
if (Use == 0)
yield break;
var s = new Stack<Tuple<int, List<int>>>();
Arr.Length.REPR(i => s.Push(Tuple.Create(i, new List<int>() { Arr[i] })));
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Item2.Count == Use)
yield return cur.Item2.ToArray();
else
for (int i = Arr.GetUpperBound(0); i >= cur.Item1; i--)
s.Push(Tuple.Create(i, new List<int>(cur.Item2) { Arr[i] }));
}
}
public IEnumerable<long[]> enuPart(string str) {
var s = new Stack<Tuple<string, List<long>, int>>();
s.Push(Tuple.Create(str[0].ToString(), new List<long>(), 1));
while (s.Count > 0) {
var cur = s.Pop();
if (cur.Item3 >= str.Length) {
yield return (new List<long>(cur.Item2) { cur.Item1.toLong() })
.ToArray();
} else {
//繋げる
s.Push(Tuple.Create(cur.Item1 + str[cur.Item3],
new List<long>(cur.Item2), cur.Item3 + 1));
//繋がない
s.Push(Tuple.Create(str[cur.Item3].ToString(),
new List<long>(cur.Item2) { cur.Item1.toLong() },
cur.Item3 + 1));
}
}
}
}
class AssociativeArray<T>
: IEnumerable { // hack:KeyValuePairの利用に制限がかかる
public Dictionary<T, int> dic;
public AssociativeArray() { dic = new Dictionary<T, int>(); }
public AssociativeArray(params T[] a) {
dic = new Dictionary<T, int>();
Add(a);
}
public void Add(params T[] a) {
a.Length.REP(i => {
if (!conK(a[i]))
dic[a[i]] = 0;
dic[a[i]]++;
});
}
public void Set(T k, int v) {
if (!dic.ContainsKey(k))
dic[k] = 0;
dic[k] = v;
}
public void Remove(params T[] a) {
a.Length.REP(i => {
if (conK(a[i]))
dic.Remove(a[i]);
});
}
public T[] Keys() { return dic.Keys.ToArray<T>(); }
public int Val(T k) { return (dic.ContainsKey(k)) ? dic[k] : 0; }
public int ValSum => dic.Values.Sum();
public int KeyNum => dic.Keys.Count;
public int MaxVal => dic.Values.Max();
public int MinVal => dic.Values.Min();
public T MaxKey => dic.First(d => d.Value == MaxVal).Key;
public T MinKey => dic.First(d => d.Value == MinVal).Key;
public bool conK(T k) { return dic.ContainsKey(k); }
public bool anyK(params T[] k) { return k.Any(key => conK(key)); }
public bool allK(params T[] k) { return k.All(key => conK(key)); }
public void Show() {
foreach (var v in dic) {
Console.WriteLine(v.Key + " : " + v.Value);
}
}
public IEnumerator GetEnumerator() {
foreach (var kp in dic)
yield return kp;
}
//:sort->array
}
class UnionFind {
public int[] parent;
public int[] depth;
public void Init(int n) {
parent = new int[n];
depth = new int[n];
n.REP(i => parent[i] = i);
}
public int Find(int x) {
return (parent[x] == x) ? x : parent[x] = Find(parent[x]);
}
public void Unite(int x, int y) {
x = Find(x);
y = Find(y);
if (x == y)
return;
if (depth[x] < depth[y])
parent[x] = y;
else {
parent[y] = x;
if (depth[x] == depth[y])
depth[x]++;
}
}
public bool Same(int a, int b) { return Find(a) == Find(b); }
}
class Time {
public bool isLeapYear(int y) {
return (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0));
}
}
#endregion
#region Graph
class Index {
public int[] Comp(int[] bef) {
int[] aft = new int[bef.Length];
var tmp = bef.Distinct()
.OrderBy(v => v)
.Select((v, i) => new { v, i })
.ToDictionary(p => p.v, p => p.i);
aft = bef.Select(v => tmp[v]).ToArray();
return aft;
}
}
class BasicGraph { //けす
public List<Tuple<int, long>>[] G;
public void Init(int n) {
G = new List<Tuple<int, long>>[n + 1];
G.Length.REP(i => G[i] = new List<Tuple<int, long>>());
}
public void Dir(int[] f, int[] t) {
f.Length.REP(i => G[f[i]].Add(Tuple.Create(t[i], 1L)));
}
public void Dir(int[] f, int[] t, long[] c) {
f.Length.REP(i => G[f[i]].Add(Tuple.Create(t[i], c[i])));
}
public void NonDir(int[] f, int[] t) {
f.Length.REP(i => {
G[f[i]].Add(Tuple.Create(t[i], 1L));
G[t[i]].Add(Tuple.Create(f[i], 1L));
});
}
public void NonDir(int[] f, int[] t, long[] c) {
f.Length.REP(i => {
G[f[i]].Add(Tuple.Create(t[i], c[i]));
G[t[i]].Add(Tuple.Create(f[i], c[i]));
});
}
}
class TreeDis { // test
public List<Tuple<long, long>>[] g;
public long[] a2other;
private int type;
public TreeDis(int type = 0) { this.type = type; } // 0->bfs,other->dfs
public void Init(long n) {
g = new List<Tuple<long, long>>[n + 1];
g.Length.REP(i => g[i] = new List<Tuple<long, long>>());
}
public void Run(long[] a, long[] b) {
a.Length.REP(i => {
g[a[i]].Add(Tuple.Create(b[i], 1L));
g[b[i]].Add(Tuple.Create(a[i], 1L));
});
}
public void Run(long[] a, long[] b, long[] w) {
a.Length.REP(i => {
g[a[i]].Add(Tuple.Create(b[i], w[i]));
g[b[i]].Add(Tuple.Create(a[i], w[i]));
});
}
public long[] a2iArr(long a) {
a2other = new long[g.Count()];
if (type == 0)
BFS(a);
else
DFS(a);
return a2other;
}
private void BFS(long a) {
var q = new Queue<Tuple<long, long>>();
q.Enqueue(Tuple.Create(a, -1L));
while (q.Count > 0) {
var c = q.Dequeue();
foreach (var v in g[c.Item1]) {
if (v.Item1 == c.Item2)
continue;
a2other[v.Item1] = a2other[c.Item1] + v.Item2;
q.Enqueue(Tuple.Create(v.Item1, c.Item1));
}
}
}
private void DFS(long a) {
var s = new Stack<Tuple<long, long>>();
s.Push(Tuple.Create(a, -1L));
while (s.Count > 0) {
var c = s.Pop();
foreach (var v in g[c.Item1]) {
if (v.Item1 == c.Item2)
continue;
a2other[v.Item1] = a2other[c.Item1] + v.Item2;
s.Push(Tuple.Create(v.Item1, c.Item1));
}
}
}
}
class ShortestPath {
public long INF = (long)1e15;
protected int I = -1;
public long[] cost;
protected List<Tuple<int, long>>[] Adj;
protected bool isNonDir = true;
public void Init(int n) {
I = n + 1;
Adj = new List<Tuple<int, long>>[I];
I.REP(i => Adj[i] = new List<Tuple<int, long>>());
}
public void AddPath(int f, int t, long c) {
if (isNonDir) {
Adj[f].Add(Tuple.Create(t, c));
Adj[t].Add(Tuple.Create(f, c));
} else {
Adj[f].Add(Tuple.Create(t, c));
}
}
public void AddPath(int[] f, int[] t, long[] c) {
f.Length.REP(i => AddPath(f[i], t[i], c[i]));
}
}
class Dijkstra : ShortestPath { //隣接対応後検証不足,有向
public long MinCost(int f, int t) {
cost = new long[I];
cost.Set(INF);
cost[f] = 0;
var pq = new PQueue<Tuple<int, long>>();
pq.Enqueue(Tuple.Create(f, 0L)); //(from,cost)
while (pq.Count > 0) {
var cur = pq.Dequeue();
if (cost[cur.Item1] < cur.Item2)
continue;
Adj[cur.Item1].Count.REP(i => {
var tmp = Adj[cur.Item1][i];
if (cost[tmp.Item1] > cost[cur.Item1] + tmp.Item2) {
cost[tmp.Item1] = cost[cur.Item1] + tmp.Item2;
pq.Enqueue(Tuple.Create(tmp.Item1, cost[tmp.Item1]));
}
});
}
return cost[t];
}
}
class BellmanFord : ShortestPath {
private bool[] neg;
public BellmanFord() {}
public BellmanFord(bool isNonDir) { this.isNonDir = isNonDir; }
public long MinCost(int f, int t) {
cost = new long[I];
cost.Set(INF);
cost[f] = 0;
neg = new bool[I];
for (int i = 0; i < I - 1; i++) {
I.REP(j => Adj[j].Count.REP(k => {
var cur = Adj[j][k];
if (cost[cur.Item1] > cost[j] + cur.Item2)
cost[cur.Item1] = cost[j] + cur.Item2;
}));
}
for (int i = 0; i < I; i++) {
I.REP(j => Adj[j].Count.REP(k => {
var cur = Adj[j][k];
if (cost[cur.Item1] > cost[j] + cur.Item2) {
cost[cur.Item1] = cost[j] + cur.Item2;
neg[cur.Item1] = true;
}
if (neg[j])
neg[cur.Item1] = true;
}));
}
return cost[t];
}
public bool loopExist() { return neg[I - 1]; }
}
class WarshallFloyd { //そのうちAdjとどっちがいいか...TODO:ジェネリック
private int E;
private int INF = (int)1e9;
public long[,] G;
public void Init(int n) {
E = n + 1;
G = new long[E, E];
G.Set(INF);
E.REP(i => G[i, i] = 0);
}
public void AddPath(int f, int t, long c) {
G[f, t] = c;
G[t, f] = c;
}
public void AddPath(int[] f, int[] t) {
f.Length.REP(i => AddPath(f[i], t[i], 1));
}
public void AddPath(int[] f, int[] t, long[] c) {
f.Length.REP(i => AddPath(f[i], t[i], c[i]));
}
public void Run() { G = MinCostArr(); }
public long[,] MinCostArr() {
E.REP(i => E.REP(
j => E.REP(k => G[j, k] = Math.Min(G[j, k], G[j, i] + G[i, k]))));
return G;
}
}
#endregion
#region Ex
static class StringEX { //文字
public static string Reversed(this string s) {
return string.Join("", s.Reverse());
}
public static string Repeat(this string s, int n) {
return string.Concat(Enumerable.Repeat(s, n).ToArray());
}
public static int toInt(this string s) {
int n;
return (int.TryParse(s.TrimStart('0'), out n)) ? n : 0;
}
public static int toInt(this char c) { return toInt(c.ToString()); }
public static int toInt(this char[] c) { return toInt(new string(c)); }
public static long toLong(this string s) {
long n;
return (long.TryParse(s.TrimStart('0'), out n)) ? n : (long)0;
}
public static long toLong(this char c) { return toLong(c.ToString()); }
public static long toLong(this char[] c) { return toLong(new string(c)); }
public static string toString(this char[] c) { return new string(c); }
}
static class NumericEx { //数値
public static string pad0<T>(this T v, int n) {
return v.ToString().PadLeft(n, '0');
}
public static double RoundOff(this double v, int n) {
return Math.Round(v, n - 1, MidpointRounding.AwayFromZero);
}
public static bool Odd(this int v) { return v % 2 != 0; }
public static bool Odd(this long v) { return v % 2 != 0; }
public static void REP(this int v, Action<int> act) {
for (int i = 0; i < v; ++i)
act(i);
}
public static void REPR(this int v, Action<int> act) {
for (int i = v - 1; i >= 0; --i)
act(i);
}
}
static class ArrayEX {
public static T[] Sort<T>(this T[] a) {
Array.Sort(a);
return a;
}
public static T[] SortR<T>(this T[] a) {
Array.Sort(a);
Array.Reverse(a);
return a;
}
public static void Set<T>(this T[] a, T v) { a.Length.REP(i => a[i] = v); }
public static void Set<T>(this T[,] a, T v) {
a.GetLength(0).REP(i => a.GetLength(1).REP(j => a[i, j] = v));
}
}
static class BitEx {
public static bool Any(this BitArray b) {
foreach (bool f in b)
if (f)
return true;
return false;
}
public static bool All(this BitArray b) {
foreach (bool f in b)
if (!f)
return false;
return true;
}
public static bool None(this BitArray b) { return !Any(b); }
public static void Flip(this BitArray b, int index) {
b.Set(index, !b.Get(index));
}
}
static class TestEx {
// operator
}
#endregion
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 51, 250], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 51, 250], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 211, 0, 146], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 218, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 218, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 7,215
| 25
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
class Program {
public void Proc() {
Reader.IsDebug = false;
int[] inpt =
Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
int pointCount = inpt[0];
canReach = new bool[pointCount + 1];
for (int i = 0; i < inpt[1]; i++) {
long[] inpt2 =
Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
int fromPoint = (int)inpt2[0];
int toPoint = (int)inpt2[1];
if (!Road.ContainsKey(fromPoint)) {
Road.Add(fromPoint, new Dictionary<int, long>());
}
Road[fromPoint][toPoint] = inpt2[2];
if (!RoadRev.ContainsKey(toPoint)) {
RoadRev.Add(toPoint, new Dictionary<int, long>());
}
RoadRev[toPoint][fromPoint] = inpt2[2];
}
// ゴール頂点を含むループがあるか確認
Queue<int> que = new Queue<int>();
canReach[pointCount] = true;
RoadRev[pointCount].ToList().ForEach(a => {
canReach[a.Key] = true;
que.Enqueue(a.Key);
});
while (que.Count > 0) {
int current = que.Dequeue();
if (!RoadRev.ContainsKey(current)) {
continue;
}
RoadRev[current].ToList().ForEach(a => {
if (!canReach[a.Key]) {
canReach[a.Key] = true;
que.Enqueue(a.Key);
}
});
}
bool[] flags = new bool[pointCount + 1];
flags[1] = true;
long ans = GetAns(1, flags);
if (ans == long.MaxValue) {
Console.WriteLine("inf");
} else {
Console.WriteLine(ans);
}
}
private Dictionary<int, Dictionary<int, long>> Road =
new Dictionary<int, Dictionary<int, long>>();
private Dictionary<int, Dictionary<int, long>> RoadRev =
new Dictionary<int, Dictionary<int, long>>();
private bool[] canReach;
private Dictionary<int, long> dic = new Dictionary<int, long>();
private long GetAns(int pos, bool[] flag) {
if (dic.ContainsKey(pos)) {
return dic[pos];
}
if (!Road.ContainsKey(pos)) {
if (pos == flag.Length - 1) {
dic.Add(pos, 0);
return 0;
} else {
dic.Add(pos, long.MinValue);
return long.MinValue;
}
}
long ans = long.MinValue;
if (pos == flag.Length - 1) {
ans = 0;
}
foreach (int nextPos in Road[pos].Keys) {
if (!canReach[nextPos]) {
continue;
}
if (flag[nextPos]) {
if (IsPositiveRoop(pos, nextPos)) {
ans = long.MaxValue;
break;
} else {
continue;
}
} else {
flag[nextPos] = true;
long rete = GetAns(nextPos, flag);
flag[nextPos] = false;
if (rete == long.MaxValue) {
ans = long.MaxValue;
break;
} else if (rete == long.MinValue) {
continue;
} else if (ans == long.MinValue) {
ans = rete + Road[pos][nextPos];
} else {
ans = Math.Max(ans, rete + Road[pos][nextPos]);
}
}
}
dic[pos] = ans;
return ans;
}
private bool IsPositiveRoop(int pos1, int pos2) {
Queue<int> que = new Queue<int>();
Nullable<long>[] score = new Nullable<long>[canReach.Length];
score[pos1] = 0;
que.Enqueue(pos1);
while (que.Count > 0) {
int current = que.Dequeue();
if (!Road.ContainsKey(current)) {
continue;
}
foreach (int next in Road[current].Keys) {
long nextVal = score[current].Value + Road[current][next];
if (score[next] == null || (score[next].Value < 0 && nextVal >= 0)) {
score[next] = nextVal;
if (next != pos2) {
que.Enqueue(next);
}
}
}
}
long max1 = score[pos2].Value;
score = new Nullable<long>[canReach.Length];
score[pos2] = 0;
que.Enqueue(pos2);
while (que.Count > 0) {
int current = que.Dequeue();
if (!Road.ContainsKey(current)) {
continue;
}
foreach (int next in Road[current].Keys) {
long nextVal = score[current].Value + Road[current][next];
if (score[next] == null || (score[next].Value < 0 && nextVal >= 0)) {
score[next] = nextVal;
if (next != pos1) {
que.Enqueue(next);
}
}
}
}
long max2 = score[pos1].Value;
return (max1 + max2 >= 0);
}
public class Reader {
public static bool IsDebug = true;
private static String PlainInput = @"
6 5
1 2 -1000000000
2 3 -1000000000
3 4 -1000000000
4 5 -1000000000
5 6 -1000000000
";
private static System.IO.StringReader Sr = null;
public static string ReadLine() {
if (IsDebug) {
if (Sr == null) {
Sr = new System.IO.StringReader(PlainInput.Trim());
}
return Sr.ReadLine();
} else {
return Console.ReadLine();
}
}
}
static void Main() {
Program prg = new Program();
prg.Proc();
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
class Program {
public void Proc() {
Reader.IsDebug = false;
int[] inpt =
Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
int pointCount = inpt[0];
canReach = new bool[pointCount + 1];
for (int i = 0; i < inpt[1]; i++) {
long[] inpt2 =
Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
int fromPoint = (int)inpt2[0];
int toPoint = (int)inpt2[1];
if (!Road.ContainsKey(fromPoint)) {
Road.Add(fromPoint, new Dictionary<int, long>());
}
Road[fromPoint][toPoint] = inpt2[2];
if (!RoadRev.ContainsKey(toPoint)) {
RoadRev.Add(toPoint, new Dictionary<int, long>());
}
RoadRev[toPoint][fromPoint] = inpt2[2];
}
// ゴール頂点を含むループがあるか確認
Queue<int> que = new Queue<int>();
canReach[pointCount] = true;
RoadRev[pointCount].ToList().ForEach(a => {
canReach[a.Key] = true;
que.Enqueue(a.Key);
});
while (que.Count > 0) {
int current = que.Dequeue();
if (!RoadRev.ContainsKey(current)) {
continue;
}
RoadRev[current].ToList().ForEach(a => {
if (!canReach[a.Key]) {
canReach[a.Key] = true;
que.Enqueue(a.Key);
}
});
}
bool[] flags = new bool[pointCount + 1];
flags[1] = true;
long ans = GetAns(1, flags);
if (ans == long.MaxValue) {
Console.WriteLine("inf");
} else {
Console.WriteLine(ans);
}
}
private Dictionary<int, Dictionary<int, long>> Road =
new Dictionary<int, Dictionary<int, long>>();
private Dictionary<int, Dictionary<int, long>> RoadRev =
new Dictionary<int, Dictionary<int, long>>();
private bool[] canReach;
private Dictionary<int, long> dic = new Dictionary<int, long>();
private long GetAns(int pos, bool[] flag) {
if (dic.ContainsKey(pos)) {
return dic[pos];
}
if (!Road.ContainsKey(pos)) {
if (pos == flag.Length - 1) {
dic.Add(pos, 0);
return 0;
} else {
dic.Add(pos, long.MinValue);
return long.MinValue;
}
}
long ans = long.MinValue;
if (pos == flag.Length - 1) {
ans = 0;
}
foreach (int nextPos in Road[pos].Keys) {
if (!canReach[nextPos]) {
continue;
}
if (flag[nextPos]) {
if (IsPositiveRoop(pos, nextPos)) {
ans = long.MaxValue;
break;
} else {
continue;
}
} else {
flag[nextPos] = true;
long rete = GetAns(nextPos, flag);
flag[nextPos] = false;
if (rete == long.MaxValue) {
ans = long.MaxValue;
break;
} else if (rete == long.MinValue) {
continue;
} else if (ans == long.MinValue) {
ans = rete + Road[pos][nextPos];
} else {
ans = Math.Max(ans, rete + Road[pos][nextPos]);
}
}
}
dic[pos] = ans;
return ans;
}
private bool IsPositiveRoop(int pos1, int pos2) {
Queue<int> que = new Queue<int>();
Nullable<long>[] score = new Nullable<long>[canReach.Length];
score[pos1] = 0;
que.Enqueue(pos1);
while (que.Count > 0) {
int current = que.Dequeue();
if (!Road.ContainsKey(current)) {
continue;
}
foreach (int next in Road[current].Keys) {
long nextVal = score[current].Value + Road[current][next];
if (score[next] == null || (score[next].Value < 0 && nextVal >= 0) ||
(score[next].Value == 0 && nextVal > 0)) {
score[next] = nextVal;
if (next != pos2) {
que.Enqueue(next);
}
}
}
}
long max1 = score[pos2].Value;
score = new Nullable<long>[canReach.Length];
score[pos2] = 0;
que.Enqueue(pos2);
while (que.Count > 0) {
int current = que.Dequeue();
if (!Road.ContainsKey(current)) {
continue;
}
foreach (int next in Road[current].Keys) {
long nextVal = score[current].Value + Road[current][next];
if (score[next] == null || (score[next].Value < 0 && nextVal >= 0) ||
(score[next].Value == 0 && nextVal > 0)) {
score[next] = nextVal;
if (next != pos1) {
que.Enqueue(next);
}
}
}
}
long max2 = score[pos1].Value;
return (max1 + max2 > 0);
}
public class Reader {
public static bool IsDebug = true;
private static String PlainInput = @"
6 5
1 2 -1000000000
2 3 -1000000000
3 4 -1000000000
4 5 -1000000000
5 6 -1000000000
";
private static System.IO.StringReader Sr = null;
public static string ReadLine() {
if (IsDebug) {
if (Sr == null) {
Sr = new System.IO.StringReader(PlainInput.Trim());
}
return Sr.ReadLine();
} else {
return Console.ReadLine();
}
}
}
static void Main() {
Program prg = new Program();
prg.Proc();
}
}
|
[["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 0, 16, 31, 16, 31, 214, 205, 204, 205, 22], ["+", 31, 16, 31, 214, 205, 204, 206, 207, 0, 70], ["+", 31, 214, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 31, 16, 31, 214, 205, 204, 206, 207, 0, 73], ["+", 12, 23, 0, 16, 31, 16, 31, 214, 0, 131], ["+", 12, 23, 0, 16, 31, 16, 31, 214, 141, 22], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 17, 60], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 98], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 31, 22], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 17, 47], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 25], ["+", 31, 16, 12, 23, 0, 16, 12, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 12, 23, 0, 25], ["-", 8, 196, 0, 37, 0, 23, 0, 16, 17, 20], ["+", 8, 196, 0, 37, 0, 23, 0, 16, 17, 47]]
| 8
| 1,255
| 32
|
using System;
namespace AtCoder {
internal static class Program {
private static void Main() {
int[] nbrs = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int res = 0;
if (nbrs[0] == nbrs[1] && nbrs[0] == nbrs[2])
if (nbrs[0] % 2 == 0)
res = -1;
else
res = 0;
else {
while (nbrs[0] % 2 == 0 || nbrs[1] % 2 == 0 || nbrs[2] % 2 == 0) {
int[] tmpNbrs = new int[3];
for (int i = 0; i < nbrs.Length; i++) {
tmpNbrs[i] = (nbrs[(i + 1) % 3] + nbrs[(i + 2) % 3]) / 2;
}
for (int i = 0; i < nbrs.Length; i++) {
nbrs[i] = tmpNbrs[i];
}
if (nbrs[0] == nbrs[1] && nbrs[1] == nbrs[2]) {
Console.WriteLine(-1);
return;
}
res++;
}
}
Console.WriteLine(res);
}
}
}
|
using System;
namespace AtCoder {
internal static class Program {
private static void Main() {
int[] nbrs = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int res = 0;
if (nbrs[0] == nbrs[1] && nbrs[0] == nbrs[2])
if (nbrs[0] % 2 == 0)
res = -1;
else
res = 0;
else {
while (nbrs[0] % 2 == 0 && nbrs[1] % 2 == 0 && nbrs[2] % 2 == 0) {
int[] tmpNbrs = new int[3];
for (int i = 0; i < nbrs.Length; i++) {
tmpNbrs[i] = (nbrs[(i + 1) % 3] + nbrs[(i + 2) % 3]) / 2;
}
for (int i = 0; i < nbrs.Length; i++) {
nbrs[i] = tmpNbrs[i];
}
res++;
}
}
Console.WriteLine(res);
}
}
}
|
[["-", 75, 196, 0, 52, 15, 16, 31, 16, 17, 106], ["+", 75, 196, 0, 52, 15, 16, 31, 16, 17, 98], ["-", 0, 57, 75, 196, 0, 52, 15, 16, 17, 106], ["+", 0, 57, 75, 196, 0, 52, 15, 16, 17, 98], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 52, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 75, 196, 0, 52, 8, 196, 0, 57, 0, 121], ["-", 75, 196, 0, 52, 8, 196, 0, 57, 0, 24], ["-", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["-", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 0, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["-", 15, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 15, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["-", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["-", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["-", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["-", 75, 196, 0, 52, 8, 196, 0, 57, 0, 25], ["-", 0, 52, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38]]
| 8
| 259
| 38
|
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 readonly long Mod = 1000000000 + 7;
static void Main(string[] args) {
// SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
var ABC = Sarray();
var A = ABC[0];
var B = ABC[1];
var C = ABC[2];
var ans = 0L;
var sft = 1L;
for (var i = 0; i < 32; ++i) {
if ((sft & A) == (sft & B) && (sft & B) == (sft & C)) {
} else {
break;
}
sft <<= 1;
++ans;
}
WriteLine(ans == 32 ? -1 : ans);
// 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 readonly long Mod = 1000000000 + 7;
static void Main(string[] args) {
// SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
var ABC = Sarray();
var A = ABC[0];
var B = ABC[1];
var C = ABC[2];
var ans = 0L;
var sft = 1L;
if (A % 2 != 0 || B % 2 != 0 || C % 2 != 0) {
WriteLine(0);
return;
}
for (var i = 0; i < 32; ++i) {
if ((sft & A) == (sft & B) && (sft & B) == (sft & C)) {
} else {
break;
}
sft <<= 1;
++ans;
}
WriteLine(ans == 32 ? -1 : ans);
// Out.Flush();
}
}
}
|
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 31, 22], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 17, 109], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 79], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 31, 22], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 17, 109], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 79], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
| 8
| 237
| 29
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static Libraries.Input;
namespace Libraries {
static class Input {
private static Func<string, T[]>
Cast<T>() => _ => _.Split(' ').Select(Convert<T>()).ToArray();
private static Func<string, T> Convert<T>() {
Type t = typeof(T);
if (t == typeof(string))
return _ => (T)(object)_;
if (t == typeof(int))
return _ => (T)(object) int.Parse(_);
if (t == typeof(long))
return _ => (T)(object) long.Parse(_);
if (t == typeof(double))
return _ => (T)(object) double.Parse(_);
if (t == typeof(string[]))
return _ => (T)(object)_.Split(' ');
if (t == typeof(int[]))
return _ => (T)(object)Cast<int>()(_);
if (t == typeof(long[]))
return _ => (T)(object)Cast<long>()(_);
if (t == typeof(double[]))
return _ => (T)(object)Cast<double>()(_);
throw new NotSupportedException(t + "is not supported.");
}
private static T Convert<T>(string s) => Convert<T>()(s);
private static string String() => Console.ReadLine();
private static string[] String(long rowNumber) =>
new bool [rowNumber].Select(_ => String()).ToArray();
public static void Cin<T>(out T a) => a = Convert<T>(String());
public static void Cin<T1, T2>(out T1 a1, out T2 a2) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
}
public static void Cin<T1, T2, T3>(out T1 a1, out T2 a2, out T3 a3) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
set(v[2], out a3);
}
public static void Cin<T1, T2, T3, T4>(out T1 a1, out T2 a2, out T3 a3,
out T4 a4) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
set(v[2], out a3);
set(v[3], out a4);
}
public static void Cin<T1, T2, T3, T4, T5>(out T1 a1, out T2 a2, out T3 a3,
out T4 a4, out T5 a5) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
set(v[2], out a3);
set(v[3], out a4);
set(v[4], out a5);
}
public static void Cin<T1, T2, T3, T4, T5, T6>(out T1 a1, out T2 a2,
out T3 a3, out T4 a4,
out T5 a5, out T6 a6) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
set(v[2], out a3);
set(v[3], out a4);
set(v[4], out a5);
set(v[5], out a6);
}
private static void set<T1>(string s, out T1 o1) => o1 = Convert<T1>(s);
public static void
Cin<T>(long n, out T[] l) => l = String(n).Select(Convert<T>()).ToArray();
public static void Cin<T1, T2>(long n, out T1[] l1, out T2[] l2) {
l1 = new T1[n];
l2 = new T2[n];
for (int i = 0; i < n; i++)
Cin(out l1[i], out l2[i]);
}
public static void Cin<T1, T2, T3>(long n, out T1[] l1, out T2[] l2,
out T3[] l3) {
l1 = new T1[n];
l2 = new T2[n];
l3 = new T3[n];
for (int i = 0; i < n; i++)
Cin(out l1[i], out l2[i], out l3[i]);
}
public static void Cin<T1, T2, T3, T4>(long n, out T1[] l1, out T2[] l2,
out T3[] l3, out T4[] l4) {
l1 = new T1[n];
l2 = new T2[n];
l3 = new T3[n];
l4 = new T4[n];
for (int i = 0; i < n; i++)
Cin(out l1[i], out l2[i], out l3[i], out l4[i]);
}
public static void Cin<T>(out T[] a) => a = Convert<T[]>(String());
public static void Cin<T>(long h, out T[][] map) => map =
String(h).Select(Convert<T[]>()).ToArray();
}
class Program {
public static void Main(string[] args) {
StreamWriter streamWriter =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(streamWriter);
new Solver().Solve();
Console.Out.Flush();
}
public static void Debug() { new Solver().Solve(); }
}
class Solver {
public void Solve() {
long a, b, c;
Cin(out a, out b, out c);
if (a == b && b == c) {
Console.WriteLine(-1);
return;
}
int count = 0;
while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
var newA = (b + c) / 2;
var newB = (c + a) / 2;
var newC = (a + b) / 2;
a = newA;
b = newB;
c = newC;
count++;
}
Console.WriteLine(count);
}
}
}
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static Libraries.Input;
namespace Libraries {
static class Input {
private static Func<string, T[]>
Cast<T>() => _ => _.Split(' ').Select(Convert<T>()).ToArray();
private static Func<string, T> Convert<T>() {
Type t = typeof(T);
if (t == typeof(string))
return _ => (T)(object)_;
if (t == typeof(int))
return _ => (T)(object) int.Parse(_);
if (t == typeof(long))
return _ => (T)(object) long.Parse(_);
if (t == typeof(double))
return _ => (T)(object) double.Parse(_);
if (t == typeof(string[]))
return _ => (T)(object)_.Split(' ');
if (t == typeof(int[]))
return _ => (T)(object)Cast<int>()(_);
if (t == typeof(long[]))
return _ => (T)(object)Cast<long>()(_);
if (t == typeof(double[]))
return _ => (T)(object)Cast<double>()(_);
throw new NotSupportedException(t + "is not supported.");
}
private static T Convert<T>(string s) => Convert<T>()(s);
private static string String() => Console.ReadLine();
private static string[] String(long rowNumber) =>
new bool [rowNumber].Select(_ => String()).ToArray();
public static void Cin<T>(out T a) => a = Convert<T>(String());
public static void Cin<T1, T2>(out T1 a1, out T2 a2) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
}
public static void Cin<T1, T2, T3>(out T1 a1, out T2 a2, out T3 a3) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
set(v[2], out a3);
}
public static void Cin<T1, T2, T3, T4>(out T1 a1, out T2 a2, out T3 a3,
out T4 a4) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
set(v[2], out a3);
set(v[3], out a4);
}
public static void Cin<T1, T2, T3, T4, T5>(out T1 a1, out T2 a2, out T3 a3,
out T4 a4, out T5 a5) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
set(v[2], out a3);
set(v[3], out a4);
set(v[4], out a5);
}
public static void Cin<T1, T2, T3, T4, T5, T6>(out T1 a1, out T2 a2,
out T3 a3, out T4 a4,
out T5 a5, out T6 a6) {
var v = String().Split(' ');
set(v[0], out a1);
set(v[1], out a2);
set(v[2], out a3);
set(v[3], out a4);
set(v[4], out a5);
set(v[5], out a6);
}
private static void set<T1>(string s, out T1 o1) => o1 = Convert<T1>(s);
public static void
Cin<T>(long n, out T[] l) => l = String(n).Select(Convert<T>()).ToArray();
public static void Cin<T1, T2>(long n, out T1[] l1, out T2[] l2) {
l1 = new T1[n];
l2 = new T2[n];
for (int i = 0; i < n; i++)
Cin(out l1[i], out l2[i]);
}
public static void Cin<T1, T2, T3>(long n, out T1[] l1, out T2[] l2,
out T3[] l3) {
l1 = new T1[n];
l2 = new T2[n];
l3 = new T3[n];
for (int i = 0; i < n; i++)
Cin(out l1[i], out l2[i], out l3[i]);
}
public static void Cin<T1, T2, T3, T4>(long n, out T1[] l1, out T2[] l2,
out T3[] l3, out T4[] l4) {
l1 = new T1[n];
l2 = new T2[n];
l3 = new T3[n];
l4 = new T4[n];
for (int i = 0; i < n; i++)
Cin(out l1[i], out l2[i], out l3[i], out l4[i]);
}
public static void Cin<T>(out T[] a) => a = Convert<T[]>(String());
public static void Cin<T>(long h, out T[][] map) => map =
String(h).Select(Convert<T[]>()).ToArray();
}
class Program {
public static void Main(string[] args) {
StreamWriter streamWriter =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(streamWriter);
new Solver().Solve();
Console.Out.Flush();
}
public static void Debug() { new Solver().Solve(); }
}
class Solver {
public void Solve() {
long a, b, c;
Cin(out a, out b, out c);
if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) {
Console.WriteLine(0);
return;
}
if (a == b && b == c) {
Console.WriteLine(-1);
return;
}
int count = 0;
while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
var newA = (b + c) / 2;
var newB = (c + a) / 2;
var newC = (a + b) / 2;
a = newA;
b = newB;
c = newC;
count++;
}
Console.WriteLine(count);
}
}
}
|
[["+", 15, 16, 31, 16, 31, 16, 31, 16, 17, 109], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 31, 22], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 17, 109], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60]]
| 8
| 1,494
| 31
|
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
public static class P {
public static void Main() {
int res = 0;
var a = Reader.NextLong;
var b = Reader.NextLong;
var c = Reader.NextLong;
if (a == b && b == c) {
Console.WriteLine(-1);
return;
}
while ((a & 1) + (b & 1) + (c & 1) == 0) {
var newa = (b >> 1) + (c >> 1);
var newb = (a >> 1) + (c >> 1);
var newc = (a >> 1) + (b >> 1);
a = newa;
b = newb;
c = newc;
res++;
}
Console.WriteLine(res);
}
}
static class Reader {
const int BUF_SIZE = 1 << 12;
static Stream Stream = Console.OpenStandardInput();
static byte[] Buffer = new byte[BUF_SIZE];
static int ptr = 0;
static void Move() {
if (++ptr >= Buffer.Length) {
Stream.Read(Buffer, 0, BUF_SIZE);
ptr = 0;
}
}
public static long NextLong {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get {
long res = 0;
while (Buffer[ptr] < 48)
Move();
do {
res = res * 10 + (Buffer[ptr] ^ 48);
Move();
} while (48 <= Buffer[ptr]);
return res;
}
}
}
|
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
public static class P {
public static void Main() {
int res = 0;
var a = Reader.NextLong;
var b = Reader.NextLong;
var c = Reader.NextLong;
if ((a & 1) + (b & 1) + (c & 1) == 0 && a == b && b == c) {
Console.WriteLine(-1);
return;
}
while ((a & 1) + (b & 1) + (c & 1) == 0) {
var newa = (b >> 1) + (c >> 1);
var newb = (a >> 1) + (c >> 1);
var newc = (a >> 1) + (b >> 1);
a = newa;
b = newb;
c = newc;
res++;
}
Console.WriteLine(res);
}
}
static class Reader {
const int BUF_SIZE = 1 << 12;
static Stream Stream = Console.OpenStandardInput();
static byte[] Buffer = new byte[BUF_SIZE];
static int ptr = 0;
static void Move() {
if (++ptr >= Buffer.Length) {
Stream.Read(Buffer, 0, BUF_SIZE);
ptr = 0;
}
}
public static long NextLong {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get {
long res = 0;
while (Buffer[ptr] < 48)
Move();
do {
res = res * 10 + (Buffer[ptr] ^ 48);
Move();
} while (48 <= Buffer[ptr]);
return res;
}
}
}
|
[["+", 31, 16, 31, 16, 31, 16, 31, 23, 0, 24], ["+", 31, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["+", 31, 16, 31, 16, 31, 23, 0, 16, 17, 67], ["+", 31, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 31, 16, 31, 16, 31, 16, 31, 23, 0, 25], ["+", 31, 16, 31, 16, 31, 16, 31, 16, 17, 72], ["+", 31, 16, 31, 16, 31, 16, 12, 23, 0, 24], ["+", 31, 16, 31, 16, 12, 23, 0, 16, 31, 22], ["+", 31, 16, 31, 16, 12, 23, 0, 16, 17, 67], ["+", 31, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["+", 31, 16, 31, 16, 31, 16, 12, 23, 0, 25], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 17, 72], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98]]
| 8
| 381
| 20
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace AtCoder {
class Practice {
static void Main() => CustomMain();
static void Solve() {
var a = ReadLongArray();
if (a[0] == a[1] && a[1] == a[2]) {
WriteAnswer(-1);
return;
}
var ans = 0;
var aa = new long[3];
while (IsEven(a[0]) && IsEven(a[1]) && IsEven(a[2])) {
aa[0] = a[0] / 2;
aa[1] = a[1] / 2;
aa[2] = a[2] / 2;
a[0] = aa[1] + aa[2];
a[1] = aa[0] + aa[2];
a[2] = aa[0] + aa[1];
ans++;
}
WriteAnswer(ans);
}
static void CustomMain() {
#if DEBUG
// ファイルからテストケースを読み込む
global::Common.ChangeStdIn();
// 時間計測
var stopwatch = new Stopwatch();
stopwatch.Start();
#endif
// 出力高速化
var streamWriter =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(streamWriter);
// 回答
Solve();
#if DEBUG
stopwatch.Stop();
Console.WriteLine(stopwatch.Elapsed);
#endif
Console.Out.Flush();
}
static string ReadString() => Console.ReadLine().Trim();
static int ReadInt() => int.Parse(ReadString());
static long ReadLong() => long.Parse(ReadString());
static float ReadFloat() => float.Parse(ReadString());
static double ReadDouble => double.Parse(ReadString());
static string[] ReadStringArray() => ReadString().Split(' ');
static int[] ReadIntArray() => Array.ConvertAll(ReadString().Split(' '),
int.Parse);
static long[] ReadLongArray() => Array.ConvertAll(ReadString().Split(' '),
long.Parse);
static float[] ReadFloatArray() => Array.ConvertAll(ReadString().Split(' '),
float.Parse);
static double[] ReadDoubleArray() => Array.ConvertAll(ReadString().Split(' '),
double.Parse);
static T TypeConversion<T>(string s) {
if (typeof(T) == typeof(int)) {
return (T)Convert.ChangeType(int.Parse(s), typeof(T));
} else if (typeof(T) == typeof(long)) {
return (T)Convert.ChangeType(long.Parse(s), typeof(T));
} else if (typeof(T) == typeof(double)) {
return (T)Convert.ChangeType(double.Parse(s), typeof(T));
} else {
return (T)Convert.ChangeType(s, typeof(T));
}
}
static void ReadMulti<T, U>(out T a, out U b) {
var str = ReadStringArray();
a = TypeConversion<T>(str[0]);
b = TypeConversion<U>(str[1]);
}
static void ReadMulti<T, U, V>(out T a, out U b, out V c) {
var str = ReadStringArray();
a = TypeConversion<T>(str[0]);
b = TypeConversion<U>(str[1]);
c = TypeConversion<V>(str[2]);
}
static void WriteAnswer(object ans) => Console.WriteLine(ans);
static bool IsOdd(long num) { return (num & 1) == 1; }
static bool IsEven(long num) { return (num & 1) == 0; }
static long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; }
}
}
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace AtCoder {
class Practice {
static void Main() => CustomMain();
static void Solve() {
var a = ReadLongArray();
if (a[0] == a[1] && a[1] == a[2]) {
if (IsOdd(a[0]) || IsOdd(a[1]) || IsOdd(a[2])) {
WriteAnswer(0);
} else {
WriteAnswer(-1);
}
return;
}
var ans = 0;
var aa = new long[3];
while (IsEven(a[0]) && IsEven(a[1]) && IsEven(a[2])) {
aa[0] = a[0] / 2;
aa[1] = a[1] / 2;
aa[2] = a[2] / 2;
a[0] = aa[1] + aa[2];
a[1] = aa[0] + aa[2];
a[2] = aa[0] + aa[1];
ans++;
}
WriteAnswer(ans);
}
static void CustomMain() {
#if DEBUG
// ファイルからテストケースを読み込む
global::Common.ChangeStdIn();
// 時間計測
var stopwatch = new Stopwatch();
stopwatch.Start();
#endif
// 出力高速化
var streamWriter =
new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(streamWriter);
// 回答
Solve();
#if DEBUG
stopwatch.Stop();
Console.WriteLine(stopwatch.Elapsed);
#endif
Console.Out.Flush();
}
static string ReadString() => Console.ReadLine().Trim();
static int ReadInt() => int.Parse(ReadString());
static long ReadLong() => long.Parse(ReadString());
static float ReadFloat() => float.Parse(ReadString());
static double ReadDouble => double.Parse(ReadString());
static string[] ReadStringArray() => ReadString().Split(' ');
static int[] ReadIntArray() => Array.ConvertAll(ReadString().Split(' '),
int.Parse);
static long[] ReadLongArray() => Array.ConvertAll(ReadString().Split(' '),
long.Parse);
static float[] ReadFloatArray() => Array.ConvertAll(ReadString().Split(' '),
float.Parse);
static double[] ReadDoubleArray() => Array.ConvertAll(ReadString().Split(' '),
double.Parse);
static T TypeConversion<T>(string s) {
if (typeof(T) == typeof(int)) {
return (T)Convert.ChangeType(int.Parse(s), typeof(T));
} else if (typeof(T) == typeof(long)) {
return (T)Convert.ChangeType(long.Parse(s), typeof(T));
} else if (typeof(T) == typeof(double)) {
return (T)Convert.ChangeType(double.Parse(s), typeof(T));
} else {
return (T)Convert.ChangeType(s, typeof(T));
}
}
static void ReadMulti<T, U>(out T a, out U b) {
var str = ReadStringArray();
a = TypeConversion<T>(str[0]);
b = TypeConversion<U>(str[1]);
}
static void ReadMulti<T, U, V>(out T a, out U b, out V c) {
var str = ReadStringArray();
a = TypeConversion<T>(str[0]);
b = TypeConversion<U>(str[1]);
c = TypeConversion<V>(str[2]);
}
static void WriteAnswer(object ans) => Console.WriteLine(ans);
static bool IsOdd(long num) { return (num & 1) == 1; }
static bool IsEven(long num) { return (num & 1) == 0; }
static long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; }
}
}
|
[["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 213, 63, 22], ["+", 15, 16, 31, 16, 31, 213, 3, 4, 0, 24], ["+", 31, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 15, 16, 31, 16, 31, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["+", 0, 57, 15, 16, 31, 16, 12, 213, 63, 22], ["+", 15, 16, 31, 16, 12, 213, 3, 4, 0, 24], ["+", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 15, 16, 31, 16, 12, 213, 3, 4, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 106], ["+", 64, 196, 0, 57, 15, 16, 12, 213, 63, 22], ["+", 0, 57, 15, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 57, 15, 16, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 213, 63, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46]]
| 8
| 860
| 36
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
class Program {
static void Main(string[] args) {
var abc = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
if (abc[0] == abc[1] && abc[0] == abc[2]) {
WriteLine(-1);
return;
}
var result = 0;
while (abc[0] % 2 == 0 && abc[1] % 2 == 0 && abc[2] % 2 == 0) {
var a = abc[0];
var b = abc[1];
var c = abc[2];
abc[0] = b / 2 + c / 2;
abc[1] = a / 2 + c / 2;
abc[2] = a / 2 + b / 2;
result++;
}
WriteLine(result);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
class Program {
static void Main(string[] args) {
var abc = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
if (abc[0] % 2 == 1 || abc[1] % 2 == 1 || abc[2] % 2 == 1) {
WriteLine(0);
return;
}
if (abc[0] == abc[1] && abc[0] == abc[2]) {
WriteLine(-1);
return;
}
var result = 0L;
while (abc[0] % 2 == 0 && abc[1] % 2 == 0 && abc[2] % 2 == 0) {
var a = abc[0];
var b = abc[1];
var c = abc[2];
abc[0] = b / 2 + c / 2;
abc[1] = a / 2 + c / 2;
abc[2] = a / 2 + b / 2;
result++;
}
WriteLine(result);
}
}
|
[["+", 15, 16, 31, 16, 31, 16, 31, 16, 17, 109], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["+", 31, 16, 12, 16, 31, 16, 31, 204, 205, 22], ["+", 12, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 17, 109], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 15, 16, 12, 16, 31, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
| 8
| 210
| 40
|
using System;
using System.Collections.Generic;
using System.Linq;
class Scanner //標準入力
{
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int Int() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Int() + add;
}
return Array;
}
public long Long() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = Long() + add;
}
return Array;
}
}
class Program {
static Scanner cin = new Scanner();
static void Main(string[] args) {
long A = cin.Long();
long B = cin.Long();
long C = cin.Long();
int cnt = 0;
if (A == C && B == C)
Console.WriteLine(-1);
else {
while (true) {
long tmpa = A, tmpb = B, tmpc = C;
if (tmpa % 2 != 0 || tmpb % 2 != 0 || tmpc % 2 != 0)
break;
A = tmpb / 2 + tmpc / 2;
B = tmpc / 2 + tmpa / 2;
C = tmpa / 2 + tmpb / 2;
cnt++;
}
Console.WriteLine(cnt);
}
Console.ReadLine();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
class Scanner //標準入力
{
string[] s;
int i;
char[] cs = new char[] { ' ' };
public Scanner() {
s = new string[0];
i = 0;
}
public string next() {
if (i < s.Length)
return s[i++];
string st = Console.ReadLine();
while (st == "")
st = Console.ReadLine();
s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
if (s.Length == 0)
return next();
i = 0;
return s[i++];
}
public int Int() { return int.Parse(next()); }
public int[] ArrayInt(int N, int add = 0) {
int[] Array = new int[N];
for (int i = 0; i < N; i++) {
Array[i] = Int() + add;
}
return Array;
}
public long Long() { return long.Parse(next()); }
public long[] ArrayLong(int N, long add = 0) {
long[] Array = new long[N];
for (int i = 0; i < N; i++) {
Array[i] = Long() + add;
}
return Array;
}
}
class Program {
static Scanner cin = new Scanner();
static void Main(string[] args) {
long A = cin.Long();
long B = cin.Long();
long C = cin.Long();
int cnt = 0;
if (A % 2 == 0 && B % 2 == 0 && C % 2 == 0 && A == C && B == C)
Console.WriteLine(-1);
else {
while (true) {
long tmpa = A, tmpb = B, tmpc = C;
if (tmpa % 2 != 0 || tmpb % 2 != 0 || tmpc % 2 != 0)
break;
A = tmpb / 2 + tmpc / 2;
B = tmpc / 2 + tmpa / 2;
C = tmpa / 2 + tmpb / 2;
cnt++;
}
Console.WriteLine(cnt);
}
Console.ReadLine();
}
}
|
[["+", 31, 16, 31, 16, 31, 16, 31, 16, 17, 109], ["+", 31, 16, 31, 16, 31, 16, 31, 16, 12, 203], ["+", 31, 16, 31, 16, 31, 16, 31, 16, 17, 60], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 17, 98], ["+", 31, 16, 31, 16, 12, 16, 31, 16, 31, 22], ["+", 31, 16, 31, 16, 12, 16, 31, 16, 17, 109], ["+", 31, 16, 31, 16, 12, 16, 31, 16, 12, 203], ["+", 31, 16, 31, 16, 31, 16, 12, 16, 17, 60], ["+", 31, 16, 31, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 98], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 17, 60], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22]]
| 8
| 456
| 18
|
using System;
using System.Collections.Generic;
using System.Text;
namespace AtTest.AGC_Challenge {
class _014_A {
static void Main(string[] args) {
Method(args);
Console.ReadLine();
}
static void Method(string[] args) {
int[] abc = ReadInts();
if (abc[0] == abc[1] && abc[1] == abc[2]) {
Console.WriteLine(-1);
return;
}
int cnt = 0;
while (abc[0] % 2 == 0 && abc[1] % 2 == 0 && abc[2] % 2 == 0) {
int[] next = new int[3];
next[0] = (abc[1] + abc[2]) / 2;
next[1] = (abc[2] + abc[0]) / 2;
next[2] = (abc[0] + abc[1]) / 2;
abc = next;
cnt++;
}
Console.WriteLine(cnt);
}
private static string Read() { return Console.ReadLine(); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
using System;
using System.Collections.Generic;
using System.Text;
namespace AtTest.AGC_Challenge {
class _014_A {
static void Main(string[] args) {
Method(args);
Console.ReadLine();
}
static void Method(string[] args) {
int[] abc = ReadInts();
if (abc[0] % 2 == 0 && abc[0] == abc[1] && abc[1] == abc[2]) {
Console.WriteLine(-1);
return;
}
int cnt = 0;
while (abc[0] % 2 == 0 && abc[1] % 2 == 0 && abc[2] % 2 == 0) {
int[] next = new int[3];
next[0] = (abc[1] + abc[2]) / 2;
next[1] = (abc[2] + abc[0]) / 2;
next[2] = (abc[0] + abc[1]) / 2;
abc = next;
cnt++;
}
Console.WriteLine(cnt);
}
private static string Read() { return Console.ReadLine(); }
private static int ReadInt() { return int.Parse(Read()); }
private static long ReadLong() { return long.Parse(Read()); }
private static double ReadDouble() { return double.Parse(Read()); }
private static int[] ReadInts() {
return Array.ConvertAll(Read().Split(), int.Parse);
}
private static long[] ReadLongs() {
return Array.ConvertAll(Read().Split(), long.Parse);
}
private static double[] ReadDoubles() {
return Array.ConvertAll(Read().Split(), double.Parse);
}
}
}
|
[["+", 15, 16, 31, 16, 31, 16, 31, 16, 17, 109], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["+", 15, 16, 31, 16, 12, 16, 31, 204, 205, 22], ["+", 31, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 60]]
| 8
| 372
| 9
|
using System;
namespace AGC014A {
class Program {
static bool Check(long a, long b, long c) {
return a % 2 == 0 && b % 2 == 0 && c % 2 == 0;
}
static void Main() {
string[] s = Console.ReadLine().Split(' ');
long a, b, c;
a = long.Parse(s[0]);
b = long.Parse(s[1]);
c = long.Parse(s[2]);
if (a == b && b == c) {
Console.WriteLine(-1);
Environment.Exit(0);
}
for (long i = 0;; i++) {
if (!Check(a, b, c)) {
Console.WriteLine(i);
Environment.Exit(0);
}
long at = a, bt = b, ct = c;
a = (bt + ct) / 2;
b = (at + ct) / 2;
c = (at + bt) / 2;
}
}
}
}
|
using System;
namespace AGC014A {
class Program {
static bool Check(long a, long b, long c) {
return a % 2 == 0 && b % 2 == 0 && c % 2 == 0;
}
static void Main() {
string[] s = Console.ReadLine().Split(' ');
long a, b, c;
a = long.Parse(s[0]);
b = long.Parse(s[1]);
c = long.Parse(s[2]);
if (a == b && b == c && Check(a, b, c)) {
Console.WriteLine(-1);
Environment.Exit(0);
}
for (long i = 0;; i++) {
if (!Check(a, b, c)) {
Console.WriteLine(i);
Environment.Exit(0);
}
long at = a, bt = b, ct = c;
a = (bt + ct) / 2;
b = (at + ct) / 2;
c = (at + bt) / 2;
}
}
}
}
|
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 213, 63, 22], ["+", 0, 57, 15, 16, 12, 213, 3, 4, 0, 24], ["+", 15, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 12, 213, 3, 4, 0, 21], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25]]
| 8
| 224
| 9
|
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
var N = sc.ReadInt();
var count = new int[N + 1];
for (int i = 0; i < N; i++) {
var a = sc.ReadInt();
var b = sc.ReadInt();
count[a]++;
count[b]++;
}
var ok = count.All(c => c % 2 == 0);
Console.WriteLine(ok ? "YES" : "NO");
}
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.Linq;
class Program {
static void Main(string[] args) {
var N = sc.ReadInt();
var M = sc.ReadInt();
var count = new int[N];
for (int i = 0; i < M; i++) {
var a = sc.ReadInt() - 1;
var b = sc.ReadInt() - 1;
count[a]++;
count[b]++;
}
var ok = count.All(c => c % 2 == 0);
Console.WriteLine(ok ? "YES" : "NO");
}
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, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["-", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
| 8
| 1,098
| 17
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST {
static void Main() {
Sol mySol = new Sol();
mySol.Solve();
}
}
class Sol {
public void Solve() {
long Inf = (long)1e18;
long[][] min = new long [H][];
bool[][] used = new bool [H][];
for (int i = 0; i < H; i++) {
min[i] = new long[W];
used[i] = new bool[W];
for (int j = 0; j < W; j++)
min[i][j] = Inf;
}
int[][] m = new int [H][];
for (int i = 0; i < H; i++) {
m[i] = new int[W];
for (int j = 0; j < W; j++)
m[i][j] = S[i][j] == '#' ? 1 : 0;
}
Init(m);
int r0 = 0, c0 = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (S[i][j] == 'S') {
r0 = i;
c0 = j;
}
}
}
var Q = new Queue<int>();
min[r0][c0] = 0;
Q.Enqueue(enc(r0, c0));
while (Q.Count > 0) {
var rc = Q.Dequeue();
int r = decR(rc);
int c = decC(rc);
for (int t = 0; t < 4; t++) {
int nr = r + dy[t];
int nc = c + dx[t];
if (!InRange(nr, 0, H) || !InRange(nc, 0, W))
continue;
if (S[nr][nc] == '#')
continue;
if (min[nr][nc] != Inf)
continue;
min[nr][nc] = min[r][c] + 1;
Q.Enqueue(enc(nr, nc));
}
}
long ans = Inf;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (min[i][j] > K)
continue;
if (i == 0 || i == H - 1 || j == 0 || j == W - 1 && min[i][j] < K) {
Console.WriteLine(1);
return;
}
long turn = 0;
turn = (i + 1 - 1) / K + 1 + 1;
ans = Math.Min(ans, turn);
turn = (H - i - 1) / K + 1 + 1;
ans = Math.Min(ans, turn);
turn = (j + 1 - 1) / K + 1 + 1;
ans = Math.Min(ans, turn);
turn = (W - j - 1) / K + 1 + 1;
ans = Math.Min(ans, turn);
}
}
Console.WriteLine(ans);
}
int[] dy = new int[] { 0, 1, 0, -1 };
int[] dx = new int[] { 1, 0, -1, 0 };
bool InRange(int t, int l, int r) { return l <= t && t < r; }
void Init(int[][] M) {
acc = new int [H + 1][];
for (int i = 0; i <= H; i++) {
acc[i] = new int[W + 1];
if (i == 0)
continue;
for (int j = 1; j <= W; j++) {
acc[i][j] = M[i - 1][j - 1];
}
}
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= W; j++) {
acc[i][j] += acc[i][j - 1];
}
}
for (int j = 1; j <= W; j++) {
for (int i = 1; i <= H; i++) {
acc[i][j] += acc[i - 1][j];
}
}
}
static int[][] acc;
static int cal(int x1, int y1, int x2, int y2) {
// return num of land [x1,x2)*[y1,y2); left-inclusive / right-noninclusive;
if (x2 < x1 || y2 < y1)
return 0;
return acc[y2][x2] - acc[y2][x1] - acc[y1][x2] + acc[y1][x1];
}
int enc(int r, int c) { return (r * 1024) | c; }
int decR(int rc) { return rc / 1024; }
int decC(int rc) { return rc % 1024; }
int H, W;
long K;
String[] S;
public Sol() {
var d = ria();
H = d[0];
W = d[1];
K = d[2];
S = new String[H];
for (int i = 0; i < H; i++)
S[i] = rs();
}
static String rs() { return Console.ReadLine(); }
static int ri() { return int.Parse(Console.ReadLine()); }
static long rl() { return long.Parse(Console.ReadLine()); }
static double rd() { return double.Parse(Console.ReadLine()); }
static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
static int[] ria(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e));
}
static long[] rla(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e));
}
static double[] rda(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep),
e => double.Parse(e));
}
}
|
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST {
static void Main() {
Sol mySol = new Sol();
mySol.Solve();
}
}
class Sol {
public void Solve() {
long Inf = (long)1e18;
long[][] min = new long [H][];
bool[][] used = new bool [H][];
for (int i = 0; i < H; i++) {
min[i] = new long[W];
used[i] = new bool[W];
for (int j = 0; j < W; j++)
min[i][j] = Inf;
}
int[][] m = new int [H][];
for (int i = 0; i < H; i++) {
m[i] = new int[W];
for (int j = 0; j < W; j++)
m[i][j] = S[i][j] == '#' ? 1 : 0;
}
Init(m);
int r0 = 0, c0 = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (S[i][j] == 'S') {
r0 = i;
c0 = j;
}
}
}
var Q = new Queue<int>();
min[r0][c0] = 0;
Q.Enqueue(enc(r0, c0));
while (Q.Count > 0) {
var rc = Q.Dequeue();
int r = decR(rc);
int c = decC(rc);
for (int t = 0; t < 4; t++) {
int nr = r + dy[t];
int nc = c + dx[t];
if (!InRange(nr, 0, H) || !InRange(nc, 0, W))
continue;
if (S[nr][nc] == '#')
continue;
if (min[nr][nc] != Inf)
continue;
min[nr][nc] = min[r][c] + 1;
Q.Enqueue(enc(nr, nc));
}
}
long ans = Inf;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (min[i][j] > K)
continue;
if (i == 0 || i == H - 1 || j == 0 || j == W - 1 && min[i][j] < K) {
Console.WriteLine(1);
return;
}
long turn = 0;
turn = (i - 1) / K + 1 + 1;
ans = Math.Min(ans, turn);
turn = (H - i - 1 - 1) / K + 1 + 1;
ans = Math.Min(ans, turn);
turn = (j - 1) / K + 1 + 1;
ans = Math.Min(ans, turn);
turn = (W - j - 1 - 1) / K + 1 + 1;
ans = Math.Min(ans, turn);
}
}
Console.WriteLine(ans);
}
int[] dy = new int[] { 0, 1, 0, -1 };
int[] dx = new int[] { 1, 0, -1, 0 };
bool InRange(int t, int l, int r) { return l <= t && t < r; }
void Init(int[][] M) {
acc = new int [H + 1][];
for (int i = 0; i <= H; i++) {
acc[i] = new int[W + 1];
if (i == 0)
continue;
for (int j = 1; j <= W; j++) {
acc[i][j] = M[i - 1][j - 1];
}
}
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= W; j++) {
acc[i][j] += acc[i][j - 1];
}
}
for (int j = 1; j <= W; j++) {
for (int i = 1; i <= H; i++) {
acc[i][j] += acc[i - 1][j];
}
}
}
static int[][] acc;
static int cal(int x1, int y1, int x2, int y2) {
// return num of land [x1,x2)*[y1,y2); left-inclusive / right-noninclusive;
if (x2 < x1 || y2 < y1)
return 0;
return acc[y2][x2] - acc[y2][x1] - acc[y1][x2] + acc[y1][x1];
}
int enc(int r, int c) { return (r * 1024) | c; }
int decR(int rc) { return rc / 1024; }
int decC(int rc) { return rc % 1024; }
int H, W;
long K;
String[] S;
public Sol() {
var d = ria();
H = d[0];
W = d[1];
K = d[2];
S = new String[H];
for (int i = 0; i < H; i++)
S[i] = rs();
}
static String rs() { return Console.ReadLine(); }
static int ri() { return int.Parse(Console.ReadLine()); }
static long rl() { return long.Parse(Console.ReadLine()); }
static double rd() { return double.Parse(Console.ReadLine()); }
static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); }
static int[] ria(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e));
}
static long[] rla(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e));
}
static double[] rda(char sep = ' ') {
return Array.ConvertAll(Console.ReadLine().Split(sep),
e => double.Parse(e));
}
}
|
[["-", 31, 16, 31, 23, 0, 16, 31, 16, 17, 72], ["-", 31, 16, 31, 23, 0, 16, 31, 16, 12, 203], ["+", 31, 16, 31, 23, 0, 16, 31, 16, 17, 33], ["+", 31, 16, 31, 23, 0, 16, 31, 16, 12, 203]]
| 8
| 1,391
| 8
|
using System;
namespace ConsoleApp24 {
class Program {
static void Main(string[] args) {
bool isShiritori = false;
string[] cin = Console.ReadLine().Split(' ');
if (cin[0][cin[0].Length] == cin[1][0] &&
cin[1][cin[1].Length] == cin[2][0]) {
isShiritori = true;
}
if (isShiritori) {
Console.WriteLine("YES");
}
Console.WriteLine("NO");
}
}
}
|
using System;
namespace ConsoleApp24 {
class Program {
static void Main(string[] args) {
bool isShiritori = false;
string[] cin = Console.ReadLine().Split(' ');
if (cin[0][cin[0].Length - 1] == cin[1][0] &&
cin[1][cin[1].Length - 1] == cin[2][0]) {
isShiritori = true;
}
if (isShiritori) {
Console.WriteLine("YES");
} else {
Console.WriteLine("NO");
}
}
}
}
|
[["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 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
| 119
| 7
|
using System;
class A {
static void Main(string[] args) {
string[] Shiri = { Console.ReadLine(), Console.ReadLine(),
Console.ReadLine() };
Console.WriteLine(Shiri[0][Shiri[0].Length - 1] == Shiri[1][0] &&
Shiri[1][Shiri[1].Length - 1] == Shiri[2][0]
? "YES"
: "NO");
}
}
|
using System;
class A {
static void Main(string[] args) {
string[] Shiri = Console.ReadLine().Split(' ');
Console.WriteLine(Shiri[0][Shiri[0].Length - 1] == Shiri[1][0] &&
Shiri[1][Shiri[1].Length - 1] == Shiri[2][0]
? "YES"
: "NO");
}
}
|
[["-", 0, 198, 0, 200, 0, 212, 0, 229, 0, 45], ["-", 0, 198, 0, 200, 0, 212, 0, 229, 0, 21], ["-", 0, 212, 0, 229, 0, 213, 63, 214, 205, 22], ["-", 0, 212, 0, 229, 0, 213, 63, 214, 141, 22], ["-", 0, 212, 0, 229, 0, 213, 3, 4, 0, 24], ["-", 0, 212, 0, 229, 0, 213, 3, 4, 0, 25], ["-", 0, 212, 0, 229, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 104], ["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["-", 0, 198, 0, 200, 0, 212, 0, 229, 0, 46]]
| 8
| 102
| 15
|
using System;
using System.Linq;
class Program {
static void Main() {
string[] input = Console.ReadLine().Split();
// int input=int.Parse(Console.ReadLine());
// string a = Console.ReadLine();
Console.WriteLine(input[0][input[0].Length - 1] == input[1][0] &&
input[1][input[1].Length - 1] == input[2][0]);
Console.ReadLine();
}
}
|
using System;
using System.Linq;
class Program {
static void Main() {
string[] input = Console.ReadLine().Split();
// int input=int.Parse(Console.ReadLine());
// string a = Console.ReadLine();
Console.WriteLine(input[0][input[0].Length - 1] == input[1][0] &&
input[1][input[1].Length - 1] == input[2][0]
? "YES"
: "NO");
Console.ReadLine();
}
}
|
[["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
| 8
| 93
| 8
|
using System;
namespace abc60 {
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split(' ');
string A = str[0];
string B = str[1];
string C = str[2];
if (A[A.Length - 1] == B[B.Length - 1] &&
B[B.Length - 1] == C[C.Length - 1]) {
Console.WriteLine("YES");
} else {
Console.WriteLine("NO");
}
}
}
}
|
using System;
namespace abc60 {
class Program {
static void Main(string[] args) {
string[] str = Console.ReadLine().Split(' ');
string A = str[0];
string B = str[1];
string C = str[2];
if (A[A.Length - 1] == B[0] && B[B.Length - 1] == C[0]) {
Console.WriteLine("YES");
} else {
Console.WriteLine("NO");
}
}
}
}
|
[["-", 206, 207, 0, 28, 0, 16, 31, 214, 205, 22], ["-", 206, 207, 0, 28, 0, 16, 31, 214, 0, 131], ["-", 206, 207, 0, 28, 0, 16, 31, 214, 141, 22], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
| 8
| 125
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
public static string ans;
public static int n;
public static string[] a;
static void Main(string[] args) {
a = Console.ReadLine().Split();
if (a[0][a[0].Length] == a[1][0] && (a[1][a[1].Length] == a[2][0])) {
ans = "YES";
} else {
ans = "NO";
}
Console.WriteLine(ans);
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program {
public static string ans;
public static string[] a;
static void Main(string[] args) {
a = Console.ReadLine().Split();
if (a[0][a[0].Length - 1] == a[1][0] &&
(a[1][a[1].Length - 1] == a[2][0])) {
ans = "YES";
} else {
ans = "NO";
}
Console.WriteLine(ans);
}
}
|
[["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 8, 201, 0, 124, 0, 198, 0, 200, 141, 22], ["-", 0, 208, 0, 235, 8, 201, 0, 124, 0, 35], ["-", 0, 235, 8, 201, 0, 124, 0, 251, 0, 259], ["-", 0, 235, 8, 201, 0, 124, 0, 251, 0, 115], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
| 8
| 141
| 9
|
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 abc = IO.ReadSplitInt;
bool f = false;
for (int i = 1; i <= abc[1]; i++) {
var mod = (abc[0] * i) % abc[1];
if (mod == abc[2]) {
f = true;
break;
}
}
IO.WriteLineYes_or_No(f);
}
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 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 abc = IO.ReadSplitInt;
bool f = false;
for (int i = 1; i <= abc[1]; i++) {
var mod = (abc[0] * i) % abc[1];
if (mod == abc[2]) {
f = true;
break;
}
}
// IO.WriteLineYes_or_No(f);
WriteLine(f ? "YES" : "NO");
}
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 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
}
}
}
|
[["-", 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], ["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
| 8
| 617
| 12
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
int a = sc.NextInt();
int b = sc.NextInt();
int c = sc.NextInt();
List<int> exist = new List<int>();
while (true) {
int mod = a % b;
while (mod < 0) {
mod += b;
}
if (mod == c) {
Console.WriteLine("YES");
}
if (exist.Contains(mod)) {
break;
}
exist.Add(mod);
a += a;
}
Console.WriteLine("NO");
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class AtCoderA {
static void Main() {
var sc = new Scanner();
int a = sc.NextInt();
int b = sc.NextInt();
int c = sc.NextInt();
List<int> exist = new List<int>();
int now = a;
while (true) {
int mod = now % b;
if (mod == c) {
Console.WriteLine("YES");
return;
}
if (exist.Contains(mod)) {
break;
}
exist.Add(mod);
now += a;
}
Console.WriteLine("NO");
}
class Scanner {
private string[] _line;
private int _index;
private const char Separator = ' ';
public Scanner() {
_line = new string[0];
_index = 0;
}
public string Next() {
while (_index >= _line.Length) {
_line = Console.ReadLine().Split(Separator);
_index = 0;
}
return _line[_index++];
}
public int NextInt() => int.Parse(Next());
public long NextLong() => long.Parse(Next());
public double NextDouble() => double.Parse(Next());
public decimal NextDecimal() => decimal.Parse(Next());
public char NextChar() => Next()[0];
public char[] NextCharArray() => Next().ToCharArray();
public string[] Array() {
_line = Console.ReadLine().Split(Separator);
_index = _line.Length;
return _line;
}
public int[] IntArray() => Array().Select(int.Parse).ToArray();
public long[] LongArray() => Array().Select(long.Parse).ToArray();
public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
}
}
|
[["-", 8, 201, 0, 195, 8, 196, 0, 52, 0, 89], ["-", 8, 201, 0, 195, 8, 196, 0, 52, 0, 24], ["-", 0, 195, 8, 196, 0, 52, 15, 211, 0, 146], ["-", 8, 201, 0, 195, 8, 196, 0, 52, 0, 25], ["-", 0, 195, 8, 196, 0, 52, 8, 196, 0, 45], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["-", 0, 52, 8, 196, 0, 52, 15, 16, 31, 22], ["-", 0, 52, 8, 196, 0, 52, 15, 16, 17, 18], ["-", 0, 52, 8, 196, 0, 52, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 52, 15, 211, 0, 146], ["+", 0, 52, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["-", 0, 52, 8, 196, 0, 52, 8, 196, 0, 46], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22]]
| 8
| 450
| 23
|
using System;
class Program {
static void Main() {
string[] input = Console.ReadLine().Split(
' '); // Splitで区切り文字を指定して複数個受け取る。
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int c = int.Parse(input[2]);
int ok = 0;
for (int i = 0; i < 105; i++) {
a += a;
if (a % b == c)
ok++;
}
//出力
Console.WriteLine((ok >= 1) ? "YES" : "NO");
}
}
|
using System;
class Program {
static void Main() {
string[] input = Console.ReadLine().Split(
' '); // Splitで区切り文字を指定して複数個受け取る。
int a = int.Parse(input[0]);
int b = int.Parse(input[1]);
int c = int.Parse(input[2]);
int ok = 0;
int aa = 0;
for (int i = 0; i < 105; i++) {
aa += a;
if (aa % b == c)
ok++;
}
//出力
Console.WriteLine((ok >= 1) ? "YES" : "NO");
}
}
|
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22]]
| 8
| 128
| 9
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.