static void Main(string[] args) { Scanner cin = new Scanner(); int N = cin.Int(); int x = cin.Int(); int[] a = cin.ArrayInt(N); Array.Sort(a); int ans = 0, index = 0; while (x >= a[index]) { if (index != a.Length - 1) { x -= a[index++]; ans++; } else { if (a[index] == x) { ans++; } break; } } Console.WriteLine(ans); Console.ReadLine(); }
public object E_matrix() { var N = cin.NextInt(); var M = cin.NextInt(); var Q = cin.NextInt(); var graph = Enumerable.Range(0, N).Select(_ => new bool[N]).ToArray(); for (int i = 0; i < M; i++) { var u = cin.NextInt(); var v = cin.NextInt(); u -= 1; v -= 1; graph[u][v] = true; graph[v][u] = true; } var C = cin.ArrayInt(N); for (int i = 0; i < Q; i++) { var s1 = cin.NextInt(); var x = 0; var y = 0; if (s1 == 1) { x = cin.NextInt(); x -= 1; Console.WriteLine(C[x]); for (int j = 0; j < graph[x].Count(); j++) { if (graph[x][j]) { C[j] = C[x]; } } } else { x = cin.NextInt(); y = cin.NextInt(); x -= 1; Console.WriteLine(C[x]); C[x] = y; } } return(null); }
static void Main(string[] args) { Scanner cin = new Scanner(); int N = cin.Int(); int K = cin.Int(); int[] A = cin.ArrayInt(N); int gcd = A[0]; //A_sub?????????? for (int i = 0; i < N; i++) { gcd = GCD(gcd, A[i]); } Console.WriteLine(K <= A.Max() && K % gcd == 0 ? "POSSIBLE" : "IMPOSSIBLE"); Console.ReadLine(); }
static void Main(string[] args) { Scanner cin = new Scanner(); int N = cin.Int(); int[] a = cin.ArrayInt(N); int ans = 0; for (int i = 0; i <= a.Length - 2; i++) { if (a[i] == a[i + 1]) { a[i + 1] = 10000; ans++; } } Console.WriteLine(ans); Console.ReadLine(); }
static void Main(string[] args) { Scanner cin = new Scanner(); int N = cin.Int(); int P = cin.Int(); int[] A = cin.ArrayInt(N); bool flag = true; //???? for (int i = 0; i < N; i++) { if (A[i] % 2 != 0) { flag = false; } } Console.WriteLine(flag ? P == 0 ? (long)Math.Pow(2, N) : 0 : Math.Pow(2, N - 1)); Console.ReadLine(); }