Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
429_E. Points and Segments
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct segments [li, ri] ...
2
11
#include <bits/stdc++.h> using namespace std; const long long mx = 2e5 + 10; set<pair<long long, long long> > ad[mx]; vector<long long> ver; long long ans[mx], l[mx], r[mx]; void dfst(long long v) { while ((long long)ad[v].size()) { long long u = ad[v].begin()->first, yal = ad[v].begin()->second; ad[v].erase(...
CPP
429_E. Points and Segments
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct segments [li, ri] ...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; inline long long rd() { long long x = 0, w = 1; char ch = 0; while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); } ...
CPP
429_E. Points and Segments
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct segments [li, ri] ...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; inline int gi() { char c = getchar(); while (c < '0' || c > '9') c = getchar(); int sum = 0; while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar(); return sum; } int n, l[maxn], r[maxn], ans[maxn], *q[maxn], num, cnt; struct ...
CPP
429_E. Points and Segments
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct segments [li, ri] ...
2
11
#include <bits/stdc++.h> using namespace std; const int _ = 1e5 + 5; inline int read() { char ch = '!'; int z = 1, num = 0; while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar(); if (ch == '-') z = -1, ch = getchar(); while (ch <= '9' && ch >= '0') num = (num << 3) + (num << 1) + ch - '0', ch = getch...
CPP
429_E. Points and Segments
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct segments [li, ri] ...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; int n; int l[maxn]; int r[maxn]; int clr[maxn]; bool mark[maxn]; vector<int> cmp; map<int, int> compress; stack<pair<int, int>> adj[maxn]; void in(); void solve(); void dfs(int u); void out(); int main() { ios::sync_with_stdio(false); cout.tie...
CPP
429_E. Points and Segments
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct segments [li, ri] ...
2
11
#include <bits/stdc++.h> using namespace std; inline int read() { int ans = 0, fh = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') fh = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') ans = ans * 10 + ch - '0', ch = getchar(); return ans * fh; } const int maxn = 4e5; int ...
CPP
429_E. Points and Segments
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct segments [li, ri] ...
2
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 10; int n, l[MAXN], r[MAXN], sec[MAXN], sz; int ptr[MAXN]; vector<int> adj[MAXN]; short used[MAXN], cur = 1; void dfs(int v, int p = -1) { for (; ptr[v] < adj[v].size();) { int e = adj[v][ptr[v]++]; if (!used[e]) { used[e] = 1; d...
CPP
429_E. Points and Segments
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct segments [li, ri] ...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 222222; int n, p[N], c[N], a, b, i; pair<int, int> s[N]; int dp(int x, int t) { if (c[x]) return c[x]; c[x] = t; dp(p[x << 1] >> 1, p[x << 1] & 1 ^ t ^ 1); dp(p[x << 1 | 1] >> 1, p[x << 1 | 1] & 1 ^ t); return t; } int main() { scanf("%d", &n); f...
CPP
429_E. Points and Segments
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct segments [li, ri] ...
2
11
import java.io.*; import java.util.*; /** * Created by Katushka on 14.02.2021. */ public class Main { static void sortArray(long[] a, boolean rev) { Random random = new Random(); for (int i = 0; i < a.length; i++) { int randomPos = random.nextInt(a.length); long t = a[i...
JAVA
429_E. Points and Segments
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct segments [li, ri] ...
2
11
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; int n, fir[MAXN], nxt[MAXN << 1], to[MAXN << 1], ans[MAXN << 1], vis[MAXN << 1], tot = 1, d[MAXN << 1]; int d1[MAXN << 1], d2[MAXN << 1]; int l[MAXN], r[MAXN], t[MAXN << 1], cnt; void add(int u, int v) { to[++tot] = v; nxt[tot] = fir[u]; ...
CPP
429_E. Points and Segments
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct segments [li, ri] ...
2
11
#include <bits/stdc++.h> const int maxn = 1e6 + 9; int Read() { int x(0), f(1); char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 3ll) + (x << 1ll) + c - '0'; c = getchar(); } return x * f; } struct node { int...
CPP
429_E. Points and Segments
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct segments [li, ri] ...
2
11
#include <bits/stdc++.h> using namespace std; const int maxN = 101000 * 2; const int maxM = maxN * 4; int n, m; int num, Num[maxN], L[maxN], R[maxN], Dg[maxN]; int edgecnt = -1, Hd[maxN], Nt[maxM], V[maxM], vis[maxM]; void Add_Edge(int u, int v); void dfs(int u); int main() { memset(Hd, -1, sizeof(Hd)); scanf("%d",...
CPP
429_E. Points and Segments
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct segments [li, ri] ...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 100030; pair<int, int> l[N], r[N], tot[N * 2]; int n, cnt; vector<int> mp[N << 1]; int vis[N << 1]; int read() { char c = getchar(); int k = 0; for (; c < 48 || c > 57; c = getchar()) ; for (; c > 47 && c < 58; c = getchar()) k = (k << 3) + (k << 1...
CPP
429_E. Points and Segments
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct segments [li, ri] ...
2
11
#include <bits/stdc++.h> const int N = 400050; int l[N], r[N], num[N], nk; int n, tot; int id(int v) { int L = 1, R = nk, mid; while (L <= R) { mid = (L + R) / 2; if (num[mid] == v) return mid; if (num[mid] < v) L = mid + 1; else R = mid - 1; } } int first[2 * N], to[4 * N], next[4 * N...
CPP
429_E. Points and Segments
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct segments [li, ri] ...
2
11
#include <bits/stdc++.h> using namespace std; struct sweep { pair<int, int> P; int idx; }; int N, L; sweep B[2 * 100005]; vector<int> G[2 * 100005]; int color[2 * 100005]; bool qx(sweep a, sweep b) { return a.P < b.P; } void doIt(int node) { for (auto it : G[node]) if (!color[it]) color[it] = -1 * color[node]...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; int main() { long long q, t, n, k, d1, d2, x, y; cin >> t; while (t--) { cin >> n >> k >> d1 >> d2; q = k; k = n - k; if (k - (d1 + d2) >= 0) { x = (d1 + d2 + q) / 3; y = (q - d1 - d2) / 3; if ((k - (d1 + d2)) % 3 == 0 && (d1 + d2 + q...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; long long n, k, d1, d2, ave, x; int main() { int T; cin >> T; while (T--) { cin >> n >> k >> d1 >> d2; if (n % 3) { puts("no"); continue; } ave = n / 3; bool flag = false; if ((k - d1 - 2 * d2) % 3 == 0 && (k - d1 - 2 * d2) >= 0) { ...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import java.util.Scanner; public class Main { public static void main(String args[]) { Scanner s=new Scanner(System.in); int t=s.nextInt(); for(int i=0;i<t;i++) { long n=s.nextLong(); long k=s.nextLong(); long d1=s.nextLong(); long ...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.util.StringTokenizer; /** * Built using CHelper plug-in * Actual solution is at the top * @author Rubanenko */ public class M...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintStream; import java.io.PrintWriter; import java.io.StreamTokenizer; public class Solution { public static void main(String[] args) throws Exception { solve(Sy...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
from sys import * t=int(stdin.readline()) for i in range(t): n,k,d1,d2=(int(z) for z in stdin.readline().split()) vars=((2*d1+d2,2*d2+d1),(2*max(d1,d2)-min(d1,d2),d1+d2)) y=False for i in vars: if i[0]<=k and i[0]%3==k%3 and n-k-i[1]>=0 and (n-i[1]-k)%3==0: print("yes") ...
PYTHON3
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import java.util.Scanner; public class Sample { public static void main(String[] args) { long i,j,n,k,d1,d2,t; long n1, n2, n3; Scanner sc = new Scanner(System.in); t = sc.nextInt(); while (t-- != 0) { n = sc.nextLong(); k = sc.nextLong(); ...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> int inf = 1e9 + 7; using namespace std; long long n, k, d1, d2; long long a[4]; int judge() { long long r = n - k, sum = 0; sort(a, a + 3); if (a[0] < 0) { long long ad = -a[0]; for (int i = 0; i < (3); i++) a[i] += ad; } for (int i = 0; i < (3); i++) sum += a[i]; if (sum > ...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; import static java.lang.Math.*; import static java.util.Arrays.*; public class Main { public static void main(Stri...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import java.io.IOException; import java.io.OutputStreamWriter; import java.io.BufferedWriter; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author Mahmoud Aladdin <aladdin3> */ public ...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
t = int(input()) for l in range(t): n, k, d1, d2 = map(int, input().split()) if n % 3 != 0: print("no") continue n = n // 3 ok = False for i in [-1, 1]: for j in [-1, 1]: tmp = k; tmp -= d1 * i tmp -= d1 * i tmp -= d2 * j ...
PYTHON3
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import java.util.*; import java.io.*; public class C { static void solve() { int T = in.nextInt(); outer : for (int i = 0; i < T; i++) { long n, k, d1, d2; n = in.nextLong(); k = in.nextLong(); d1 = in.nextLong(); d2 = in.nextLong(); ...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
def get(k, d1, d2): x = (k + (2 * d1) + d2) if x < 0 or x % 3 != 0: return -1, -1, -1 x /= 3 y = (k + d1 + d2) - (2 * x) if y < 0: return -1, -1, -1 z = (x - d1 - d2) if z < 0: return -1, -1, -1 return x, y, z def solve(n, k, d1, d2): signs = [ (1, 1...
PYTHON
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.Collection; import java.util.Locale; import java.util.PriorityQueue; import java.util.StringTokenizer; public class Main { public static void main(String[]...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; int check(long long int n, long long int k, long long int d1, long long int d2) { long long int A[4] = {1, -1, -1, 1}, B[4] = {1, -1, 1, -1}, x, a, b, c, D1, D2; x = n / 3; if (n % 3 != 0) return 0; for (int i = (0); i < (4); ++i) { D1 ...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> int t; long long n, k, x, y, z; int chk(long long d1, long long d2) { y = (k + d2 - d1); if (y % 3 != 0) { return 0; } y /= 3; x = y + d1; z = y - d2; if (x < 0 || y < 0 || z < 0) { return 0; } if (x > n || y > n || z > n) { return 0; } return 1; } int main() {...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import java.io.IOException; import java.io.OutputStreamWriter; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.OutputStream; import java.io.PrintWriter; import java.util.NoSuchElementException; import java.io.Writer; import java.math.BigInteger; import java.io.InputStream; /** *...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; bool solve(int64_t n, int64_t k, int64_t d1, int64_t d2) { if (n % 3 != 0) return false; for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if (i == 0 || j == 0) continue; int64_t D1 = d1 * i; int64_t D2 = d2 * j; int64_t x2 = (k...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import java.io.*; import java.util.*; public final class predict_outcome { static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); static FastScanner sc=new FastScanner(br); static PrintWriter out=new PrintWriter(System.out); static boolean check(long curr1,long curr2,long curr3,long ...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import java.util.Scanner; public class PredictOutcomeOfTheGame { static boolean solve(long n, long k, long d1, long d2) { if (n % 3 == 0) { long d3 = 0; long min = Math.min(Math.min(d1, d2), 0); if (min < 0) { d1 += -min; d2 += -min; d3 += -min; } long end = d1 + d2 + d3; if (k - end ...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d", &t); while (t--) { long long n, k, d1, d2; scanf("%lld%lld%lld%lld", &n, &k, &d1, &d2); if (n % 3 != 0) { cout << "no\n"; continue; } long long gamesRem = n - k; bool poss = false; for (int sign1 ...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; long long num; long long n, k, d1, d2; bool solve() { if (n % 3) return false; long long aim = n / 3; bool res = false; if ((k + d1 + d2) % 3 == 0) { long long x2 = (k + d1 + d2) / 3; long long x1 = x2 - d1; long long x3 = x2 - d2; if (x1 <= aim && x...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; long long G(long long a, long long b) { if (b == 0) return a; return G(b, a % b); } int main() { int t; cin >> t; while (t--) { long long n, k, d1, d2, a, b, c, t, kk; cin >> n >> k >> d1 >> d2; kk = k - d1 - d1 - d2; if (kk >= 0 && kk % 3 == 0) { ...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
t=int(input()) while(t>0): n,k,d1,d2=map(int,raw_input().split()) w1=k+2*d1+d2 f=0 p=0 if(n%3!=0): print "no" t-=1 continue if(w1%3==0 and w1>=0): w1=w1/3 w2=w1-d1 w3=w2-d2 diff=n-k ch=max(w1,w2,w3) diff-=ch-w1 diff-=ch-w2 diff-=ch-w3 # p=w1-w2 # diff-=p # p=w1-w3 # diff-=p # if(diff>=0...
PYTHON
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class PredictOutcomeOfTheGame { static long[] arr = new long[3]; public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStre...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.util.StringTokenizer; public class PredictOutcomeOfTheGame { public static void main(String[] args) { MyScanner sc = new MyScanner(); int T = sc.nextInt(); StringBuilde...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; long long d1, d2; bool res(long long n, long long k, long long a, long long b, long long c) { long long maxi = max(max(a, b), c), still = (n - k) + (a + b + c); if (((a + b + c) > k) || (a < 0) || (b < 0) || (c < 0) || (n % 3 != 0) || ((k - a - b - c) % 3 != 0)) {...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; long long n, k, d1, d2; bool f(long long a, long long b) { long long c = k - a - b * 2; if (c < 0 || c % 3) return 0; return n / 3 >= a + b + c / 3; } int main() { int t; cin >> t; for (int i = 1; i <= t; i++) { cin >> n >> k >> d1 >> d2; if (n % 3) { ...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import sys stdin = sys.stdin t = int(stdin.readline()) for icase in range(t): n, k, d1, d2 = map(int, stdin.readline().split()) found = False for dir1, dir2 in [[1, 1], [-1, -1], [-1, 1], [1, -1]]: delta1 = d1*dir1 delta2 = d2*dir2 scores = [0, delta1, delta1+delta2] offs...
PYTHON
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
for i in range(int(input())): n, u, a, b = map(int, input().split()) if n % 3: print('no') else: if a > b: a, b = b, a p, q = a + b, 2 * b - a s, r, v = p + a, p + b, n - u t = [(p, q), (q, p), (s, r), (r, s)] print('no' if all(x > u or (x - u) % 3 or y > v or...
PYTHON3
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; long long t, n, k, d1, d2; bool solve(long long t1, long long t2, long long t3) { long long sum = t1 + t2 + t3; if (k < sum || (k - sum) % 3) return false; long long t = n - k - (3 * max(max(t1, t2), t3) - sum); if (t < 0 || t % 3) return false; return true; } int...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; inline void Boost() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } long long n, k, d1, d2, T; bool solve(long long &n, long long &k, long long &d1, long long &d2) { if (n % 3 != 0) return 0; short sign, sign2; long long x1, x2, x3, dd1, dd2, v[3...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import sys from functools import lru_cache, cmp_to_key from heapq import merge, heapify, heappop, heappush from math import * from collections import defaultdict as dd, deque, Counter as C from itertools import combinations as comb, permutations as perm from bisect import bisect_left as bl, bisect_right as br, bisect f...
PYTHON3
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; long long t, n, k, d1, d2, a, b, c; bool make(long long n, long long k, long long d1, long long d2) { long long a, b, c; a = (k + d1 + d1 + d2) / 3; b = a - d1; c = a - d1 - d2; if (a >= b && b >= c && a >= 0 && b >= 0 && c >= 0 && a <= n / 3 && a + b + c ==...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; int main() { long long int t, n, k, d1, d2; cin >> t; while (t--) { cin >> n >> k >> d1 >> d2; if (n % 3 != 0) { cout << "no\n"; continue; } long long int x, y, z; y = k + d1 - d2; if (y % 3 == 0 && y >= 0 && y - d1 >= 0) { y ...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; long long n, k, d1, d2; int solve(long long d1, long long d2) { long long x, y, z; y = (k - d1 + d2) / 3; if ((k - d1 + d2) % 3 != 0) return 0; x = y + d1; z = y - d2; if (x >= 0 && x <= n / 3 && y >= 0 && y <= n / 3 && z >= 0 && z <= n /...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
from sys import * t=int(stdin.readline()) mm=0 for i in range(t): n,k,d1,d2=(int(z) for z in stdin.readline().split()) mm=2*max(d1,d2)-min(d1,d2) if (k-2*d1-d2>=0 and (k-2*d1-d2)%3==0 and n-2*d2-d1-k>=0 and (n-2*d2-d1-k)%3==0) or (k-2*d2-d1>=0 and (k-2*d2-d1)%3==0 and n-2*d1-d2-k>=0 and (n-2*d1-d2-k)%3==0)...
PYTHON3
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; int calc(long long n, long long k, long long a1, long long a2, long long a3) { long long sum; if (a2 < a3) { swap(a2, a3); } if (a1 < a2) { swap(a1, a2); } if (a2 < a3) { swap(a2, a3); } if (a1 < 0 || a2 < 0 || a3 < 0) { return 0; } sum =...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; int main() { long long int t; scanf("%lld", &t); while (t--) { long long int n, k, d1, d2, x, y, z; scanf("%lld", &n); scanf("%lld", &k); scanf("%lld", &d1); scanf("%lld", &d2); x = (k + 2 * d1 + d2) / 3; y = x - d1; z = y - d2; if ...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import java.io.*; import java.math.*; import java.util.*; public class Main{ FastScanner in; PrintWriter out; public void solve() { int t = in.nextInt(); while (t --> 0) { long n = in.nextLong(); long k = in.nextLong(); long d1 = in.nextLong(); ...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
def f1(d1, d2, n, k): a1 = 2 * d1 + d2 + k a2 = -d1 + d2 + k a3 = -d1 - (2 * d2) + k if (a1 < 0 or a2 < 0 or a3 < 0 or a1 % 3 or a2 % 3 or a2 % 3): return False else: a1 //= 3 a2 //= 3 a3 //= 3 a1, a2, a3 = tuple(sorted([a1, a2, a3])[::-1]) if (a2 - a...
PYTHON3
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class CR258_predict_outcome_of_the_game { public static void main(String... args) throws IOException { MyScanner sc = new MyScanner(); int t = sc.nextInt(); ...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; int main() { long long T, n, k, d1, d2, x, y, z; scanf("%lld", &T); while (T--) { scanf("%lld%lld%lld%lld", &n, &k, &d1, &d2); int flag = 0; if ((k - d1 - d2) % 3 == 0 && k - d1 - d2 >= 0) { y = (k - d1 - d2) / 3; x = y + d1; z = y + d2; ...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
for i in range(int(input())): n, k, d1, d2 = map(int, input().split()) flag = True if flag: c = (k - d1 - 2*d2)//3 b = c + d2 a = b + d1 if a >= 0 and b >= 0 and c >= 0 and k == a + b + c: v = [a, b, c] v.sort(reverse=True) if n-k >= v[0...
PYTHON3
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class C { static StringTokenizer st; static BufferedRead...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; int t; long long n, k, d1, d2; long long A, W; long long add1, add2, add3; bool moze; bool try1() { A = k - d1 - d2 - d2; if (A % 3 != 0 || A < 0) return false; A /= 3; if (A + d1 + d2 > W) return false; if (A + d2 > W) return false; if (A > W) return false; a...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; long long a[10], b[10]; int main() { long long t, n, k, d1, d2; scanf("%I64d", &t); for (int i = 1; i <= t; i++) { scanf("%I64d%I64d%I64d%I64d", &n, &k, &d1, &d2); if (d1 > d2) { swap(d1, d2); } a[1] = d1 * 2 + d2; a[2] = d1 + d2 * 2; a[3...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
from sys import stdin rints = lambda: [int(x) for x in stdin.readline().split()] out = [] for _ in range(int(input())): n, k, d1, d2 = rints() cases, ans = [[d1, 0, d2], [0, d1, d1 + d2], [d2 + d1, d2, 0]], 'no' if d1 >= d2: cases.append([0, d1, d1 - d2]) if d2 >= d1: cases.append([d2 ...
PYTHON
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> bool solve(long long k, long long y, long long z, long long &x1, long long &x2, long long &x3) { if ((k - y - 2 * z) % 3 != 0) return (false); x3 = (k - y - 2 * z) / 3; x2 = x3 + z; x1 = x2 + y; return (x1 >= 0 && x2 >= 0 && x3 >= 0); } bool canwin(long long n, long long x1...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; const int INF = (1 << 30) - 1; const int mod = 1000000007; const int maxn = 1000005; int flag; long long n, k, d1, d2; void f(long long a, long long b, long long c) { if (n % 3 || a % 3 || b % 3 || c % 3) { flag = 0; return; } long long ans = n / 3; a = a / ...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import java.io.*; import java.util.*; import java.math.*; //import java.util.logging.Level; //import java.util.logging.Logger; public class Main { BufferedReader read; BufferedWriter write; public static void main(String args[]) throws Exception { new Main().init("1"); } void ...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; bool checking(long long x, long long y, long long z, long long n, long long k) { if (x < 0 || y < 0 || z < 0) return false; if ((x + y + z + n - k) % 3) return false; else { long long q = (x + y + z + n - k) / 3; if (q >= x && q >= y && q >= z) retur...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import java.util.*; import java.io.*; public class Task3 { private FastScanner in; private PrintWriter out; public Task3(InputStream in, OutputStream out) { this.in = new FastScanner(in); this.out = new PrintWriter(out); } public boolean canBe(long n, long k, long d1,...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; bool check(long long n, long long k, long long d1, long long d2) { long long b = k; long long a = b - d1; long long c = b + d2; long long sum = a + b + c; if (sum % 3 != k % 3) { return false; } a -= (sum - k) / 3; b -= (sum - k) / 3; c -= (sum - k) / ...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
t = int(input()) for _ in range(t): n, k, d1, d2 = map(int, input().split()) if n % 3 != 0: print("no") continue n = n // 3 ok = False for i in [-1, 1]: for j in [-1, 1]: tmp = k; tmp -= d1 * i tmp -= d1 * i tmp -= d2 * j ...
PYTHON3
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import static java.util.Arrays.deepToString; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Scanner; im...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import java.util.InputMismatchException; import java.math.BigInteger; import java.io.*; /** * Generated by Contest helper plug-in * Actual solution is at the bottom */ public class Main { public static void main(String[] args) { InputReader in = new StreamInputReader(System.in); PrintWriter out = new PrintWri...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import java.util.*; public class GameOutcome { private static class Case { long n, k, d1, d2; public Case(long n, long k, long d1, long d2) { this.n = n; this.k = k; this.d1 = d1; this.d2 = d2; } } public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextI...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; long long n, k, d1, d2; long long valid(long long w1, long long w2, long long w3) { if (w1 < 0 || w2 < 0 || w3 < 0) { return 0; } if (w1 + w2 + w3 != k) { return 0; } if (n % 3 != 0) { return 0; } long long d = n / 3; if (w1 > d || w2 > d || w3 >...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; void FastIO() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); } int64_t modpow(int64_t a, int64_t p, int64_t mod) { int64_t ret = 1; while (p) { if (p & 1) ret = (ret * a) % mod; a = (a * a) % mod; p /= 2; } return ret; } int64_t pow...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Writer; import java.util.InputMismatchException; /** * * @author jigsaw */ public class Main { /** * @param arg...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import java.io.*; import java.math.*; import java.util.*; public class A { final static int MOD = 1000000007; public static void main(String[] args) throws Exception { FastReader in = new FastReader(System.in); int t = in.nextInt(); while (t-- > 0) { long n = in.nextLong(); long k = in.nextLong(); long d1 ...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author cunbidun */ public class M...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
rIn = lambda: raw_input().strip() def verdict(k, d1, d2, n): a = k+2*d1+d2 if a % 3: return False a /= 3 b = a-d1 c = b-d2 if a < 0 or b < 0 or c < 0: return False avg = n/3 return True if a <= avg and b <= avg and c <= avg else False T = int(rIn()) for t in xrange(T): n, k, d1, d2 = map(int, rIn()...
PYTHON
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import itertools import sys ''' w1 - w2 = d1 w2 - w3 = d2 w1 + w2 + w3 = k w1 = w2 + d1 w3 = w2 - d2 w2 + d1 + w2 + w2 - d2 = k w2 = (k - d1 + d2) / 3 w1 = w2 + d1 w3 = w2 - d2 ''' for _ in range(int(input())): n, k, d1, d2 = map(int, str.split(sys.stdin.readline())) for s1, s2 in itertools.product((1, -1)...
PYTHON3
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; struct comp { bool operator()(const pair<int, int> &a, const pair<int, int> &b) { return a.second > b.second; } }; struct myclass { bool operator()(const pair<int, int> &a, const pair<int, int> &b) { return a.first > b.first; } } myobject; inline void in(int...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import java.io.*; import java.util.*; public class A implements Runnable { private static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null; private BufferedReader in; private PrintWriter out; private StringTokenizer tok = new StringTokenizer(""); private void init() throws...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import java.io.BufferedInputStream; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.Deque; import java.util.HashSet; import java.util.InputMismatchException; import java.util.Set; pub...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, d1, d2; int t; scanf("%d", &t); while (t--) { cin >> n >> k >> d1 >> d2; long long left = n - k; long long d = d1 + 2 * d2; long long twins = d1 + d1 + d2; if (d <= left && twins <= k && (k - twins) % 3 == 0) { ...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; int main() { long long T, n, k, a, b; cin >> T; while (T--) { cin >> n >> k >> a >> b; n -= k; bool flag = 0; if (a < b) swap(a, b); if ((2 * a + b) <= n && (n - 2 * a - b) % 3 == 0 && (2 * b + a) <= k && (k - 2 * b - a) % 3 == 0) fla...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-11; const int INFINITE = 0x3f3f3f3f; template <class T> inline void checkmin(T &a, T b) { if (b < a) a = b; } template <class T> inline void checkmax(T &a, T b) { if (b > a) a = b; } template <class T> inline T sqr(T x...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
def checksituation(x1, x2, n, k, d1, d2): q = (k + x1*d1 + x2*d2) if q % 3 != 0: return False t2 = q / 3 t1 = t2 - x1*d1 t3 = t2 - x2*d2 if t1 >= 0 and t2 >= 0 and t3 >= 0 and t1 <= k and t2 <= k and t3 <= k and (t1 + t2 + t3 == k): needed = n / 3 if t1 <= needed and t2 <...
PYTHON
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
t = int(raw_input()) def check(a, b, c, n, k): # print a, b, c val = min(a, b, c) if val < 0: a += -val b += -val c += -val # print a, b, c s = a + b + c if k < s: return False if (k-s) % 3 != 0: return False games = n - k if (games+s) % 3 == 0:...
PYTHON
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; bool cond(long long num, long long lim) { if (num <= lim && num >= 0 && num % 3 == 0) return true; return false; } int main() { int t; scanf("%d", &t); while (t--) { long long n, x, y, z, a, b, c; bool ans = false; cin >> n >> x >> y >> z; if (n % ...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
from sys import stdin rints = lambda: [int(x) for x in stdin.readline().split()] out, n = [], int(input()) inputs = [rints() for _ in range(n)] for n, k, d1, d2 in inputs: cases, ans = [[d1, 0, d2], [0, d1, d1 + d2], [d2 + d1, d2, 0]], 'no' if d1 >= d2: cases.append([0, d1, d1 - d2]) if d2 >= d1:...
PYTHON
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; int check(long long n, long long k, long long d1, long long d2) { return (k - d1 - d2 - d2) >= 0 && (k - d1 - d2 - d2) % 3 == 0 && (n - k - d1 - d1 - d2) >= 0 && (n - k - d1 - d1 - d2) % 3 == 0; } int main() { int ca; long long n, k, d1, d2; while (~scanf("...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
from sys import stdin def getint(): return int(stdin.readline()) def getints(): return tuple([int(z) for z in stdin.readline().split()]) def f((n,k,d1,d2)): p = [[0,z,z+t] for z in [d1,-d1] for t in [d2,-d2]] p = [[i-min(v) for i in v] for v in p] p = [v for v in p if sum(v) <= k and ((k % 3) == ...
PYTHON
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; const int LIM = 100005; int main(int argc, char* argv[]) { long long T, n, k, d1, d2, t1, t2, t3; long long m; int r; bool flag; cin >> T; while (T-- > 0LL) { cin >> n >> k >> d1 >> d2; if (n % 3 != 0) { printf("no\n"); continue; } m ...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d", &t); for (int i = 0; i < t; i++) { long long n, k, d1, d2; long long x1, x2, x3, av; bool tag = false; cin >> n >> k >> d1 >> d2; if (n % 3) { printf("no\n"); continue; } av = n / 3; if ((2 * ...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:100000000000000") using namespace std; const long long int INF = 2e9 + 1; int main() { int T; cin >> T; for (int(Q) = 0; (Q) < (T); (Q)++) { long long int n, k, d1, d2; cin >> n >> k >> d1 >> d2; bool can = false; for (int(i) = 0; (i) < (2);...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import java.io.*; import java.math.*; import java.util.*; public class Main { static long mod=((long)1e9)+7;//toString public static int gcd(int a,int b){if(b==0)return a;else return gcd(b,a%b);} public static long pow_mod(long x,long y){long res=1;x=x%mod;while(y > 0){if((y & 1)==1)res=(res * x)%mod;y=y>>1...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; long long n, k, d1, d2; bool isok(long long d1, long long d2) { long long x, y, z; if (k - 2 * d2 - d1 < 0) return false; if ((k - 2 * d2 - d1) % 3) return false; z = (k - 2 * d2 - d1) / 3; y = d2 + z; x = d1 + y; if (x < 0 || y < 0) return false; long long ...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; bool check(long long n, long long k, long long d1, long long d2) { if (n % 3) return 0; long long win = n / 3; for (long long sgn1 = -1; sgn1 <= 1; sgn1++) { for (long long sgn2 = -1; sgn2 <= 1; sgn2++) { if (sgn1 == 0 || sgn2 == 0) continue; long long...
CPP
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
import java.util.Scanner; public class T451C { private boolean getres(long n, long k, long d1, long d2) { if (n % 3 != 0) return false; long div = n / 3; long x1, x2, x3; if ((2 * d1 + k + d2) % 3 != 0) return false; x1 = (2 * d1 + k + d2) / 3; x2 = x1 - d1; x3 = x2 - d2; if (x1 < 0...
JAVA
451_C. Predict Outcome of the Game
There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each...
2
9
#include <bits/stdc++.h> using namespace std; long long n, k, d1, d2; bool Possibility(long long n, long long k, long long d1, long long d2) { if (n % 3) return false; if (d1 + d2 > k) return false; if (n - k - 3 * max(d1, d2) + d1 + d2 < 0) return false; if ((n - k - 3 * max(d1, d2) + d1 + d2) % 3 > 0) return ...
CPP