text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n, p, w, d, x; cin >> n >> p >> w >> d; for (long long int y = 0; y < w; ++y) { if (((p - (y * d)) >= 0) && ((p - (y * d)) % w == 0)) { x = (p - (y * d)) / w; if ((x >= 0) && ((x + y) <= n)) { cout << x << " " << y << " " << (n - x - y) << endl; return 0; } } } cout << "-1" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long in() { long long a; scanf("%lld", &a); return a; } double din() { double a; scanf("%lf", &a); return a; } long long bigmod(long long b, long long p, long long md) { if (p == 0) return 1; if (p % 2 == 1) { return ((b % md) * bigmod(b, p - 1, md)) % md; } else { long long y = bigmod(b, p / 2, md); return (y * y) % md; } } long long gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a % b); } long long getRandom(long long a, long long b) { long long ret = (long long)rand() * (long long)rand(); ret %= (b - a + 1); ret += a; return ret; } int main() { long long n = in(), p = in(), w = in(), d = in(); for (long long i = 0; i <= 100000; i++) { if (p < i * d) { puts("-1"); return 0; } long long x = (p - i * d) / w; if ((x * w + i * d) == p) { if (x + i <= n) printf("%lld %lld %lld\n", x, i, n - i - x), exit(0); } } puts("-1"); }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } int main() { long long int n, p, w, d; cin >> n >> p >> w >> d; if (p == 0) { cout << "0 0 " << n << "\n"; return 0; } if (p < d) { cout << "-1\n"; return 0; } int ans = 0; for (int i = 0; i <= w - 1; i++) { if ((p - d * i) % w == 0 && i + (p - d * i) / w <= n) { cout << (p - d * i) / w << " " << i << " " << n - ((p - d * i) / w + i) << "\n"; return 0; } } cout << "-1\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, p, w, d, c, x, y, flag = 0; cin >> n >> p >> w >> d; for (int i = 0; i < w; i++) { c = p - i * d; if (c >= 0 && c % w == 0) { x = c / w; if (n - (x + i) >= 0) { cout << x << " " << i << " " << n - (x + i) << "\n"; flag = 1; break; } } } if (flag == 0) cout << -1; }
#include <bits/stdc++.h> using namespace std; using i64 = long long int; i64 ex_gcd(i64 a, i64 b, i64& x, i64& y) { if (b == 0) { x = 1; y = 0; return a; } i64 d = ex_gcd(b, a % b, x, y); i64 temp = x; x = y; y = temp - a / b * y; return d; } bool liEu(i64 a, i64 b, i64 c, i64& x, i64& y) { i64 d = ex_gcd(a, b, x, y); if (c % d != 0) return 0; i64 k = c / d; cout << "k is " << k << endl; cout << x << " " << y << endl; if (a > b) { i64 t = y / a; y %= a; x += t * b; } else { i64 t = x / b; x %= b; y += t * a; } cout << x << " " << y << endl; x *= k; y *= k; return 1; } int main() { i64 x, y; i64 n, p, w, d; cin >> n >> p >> w >> d; y = 0; while (y < w && (p - y * d) % w != 0) { y++; } if (y < w) { x = (p - y * d) / w; i64 z = n - x - y; if (x >= 0 && z >= 0) cout << x << " " << y << " " << z << endl; else cout << "-1\n"; } else { cout << "-1\n"; } }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } int main() { long long n, p, w, d; long long x, y; cin >> n >> p >> w >> d; long long g = gcd(w, d); if (p % g) { cout << -1; return 0; } w /= g, d /= g, p /= g; for (y = 0; y < w; y++) { if ((p - y * d) % w == 0) { x = (p - y * d) / w; if (x + y <= n && x >= 0) { cout << x << ' ' << y << ' ' << n - x - y; return 0; } } } cout << -1; return 0; }
#include <bits/stdc++.h> using namespace std; struct Itm { set<int> edge; int coin[3]; char color; }; using u_ll = unsigned long long; using ll = long long; using u_int = unsigned int; int NOD(int a, int b) { int tmp = a < b ? a : b; while (a % tmp != 0 || b % tmp != 0) { tmp--; } return tmp; } bool task(ll& n, ll& p, ll& w, ll& d) { ll i, y, x; u_int tmp = w - d; if (p > n * w) return 1; if (p >= w) { int nod = NOD(w, d); if (p % nod != 0) return 1; x = p / w; y = 0; ll ost = (x * w + y * d) - p; while (ost != 0) { if (ost < 0) { bool b = (ost % d != 0); y += (-ost / d + b); if (!b) break; } else { bool b = (ost % tmp != 0); y += (ost / tmp + b); x -= (ost / tmp + b); if (!b) break; } ost = (x * w + y * d) - p; } if (x + y > n) return 2; } else { if (p % d != 0) return 3; x = 0; y = p / d; } if (x * w + y * d != p) return 1; cout << x << " " << y << " " << n - x - y << endl; return 0; } int main() { ll n, p, w, d; cin >> n >> p >> w >> d; if (task(n, p, w, d) != 0) cout << -1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1007; const long long mod = 998244353; const long long ool = 1e18 + 7; const int ooi = 1e9 + 7; const int apsz = 26; const int o = 1; const int maxd = 20; const double eps = 1e-8; void exgcd(long long a, long long b, long long& d, long long& x, long long& y) { if (!b) { d = a; x = 1; y = 0; return; } else { exgcd(b, a % b, d, y, x); y -= x * (a / b); } } long long n, p, w, d; long long getup(long long up, long long x, long long vv) { if (up - x < 0) return (up - x) / vv - (long long)((up - x) % vv != 0); return (up - x) / vv; } long long getdown(long long dw, long long x, long long vv) { if (dw - x > 0) return (dw - x) / vv + (long long)((dw - x) % vv != 0); return (dw - x) / vv; } int main(void) { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> p >> w >> d; if (p == 0) return cout << 0 << " " << 0 << " " << n << endl, 0; long long v = w - d; long long dmv = d % v; long long pmv = p % v; if (pmv == 0 || dmv == 0) { if (dmv == 0 && pmv == 0) { long long ux, vx; ux = min(p / d, n); vx = p / w + (p % w != 0); if (vx > ux) return cout << -1 << endl, 0; long long xy = ux; long long x = (p - xy * d) / v; long long y = xy - x; long long z = n - x - y; return cout << x << " " << y << " " << z << endl, 0; } else if (pmv == 0) { long long ux = min(p / d, n) / v; long long tv = p / w + (p % w != 0); long long vx = tv / v + (tv % v != 0); if (vx > ux) return cout << -1 << endl, 0; long long xy = vx * v; long long x = (p / v - vx * d); long long y = xy - x; long long z = n - x - y; return cout << x << " " << y << " " << z << endl, 0; } else return cout << -1 << endl, 0; return 0; } long long cx, g, cy; exgcd(dmv, v, g, cx, cy); if (pmv % g) cout << -1 << endl; else { long long dd = dmv * (pmv / g); long long vv = v * 1; cx = cx * (pmv / g); long long up = getup(min(p / d, n), cx, vv); long long dw = getdown(p / w + (p % w != 0), cx, vv); if (up < dw) return cout << -1 << endl, 0; else { long long k = dw; cx += k * vv; long long x = (p - cx * d) / v; long long y = cx - x; long long z = n - x - y; cout << x << " " << y << " " << z << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; const int MAX = 2e9; long long n, w, p, d; long long wc, dc, lc; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> p >> w >> d; while ((p % w) != 0 && p >= 0 && dc <= w - 1) { p -= d; dc++; n--; } if (n < p / w || p < 0 || (p % w) != 0) cout << -1; else { wc = p / w; cout << wc << " " << dc << " " << n - wc; } }
#include <bits/stdc++.h> using namespace std; long long x, y; long long exgcd(long long a, long long b, long long &x, long long &y) { long long d = a; if (b != 0) { d = exgcd(b, a % b, y, x); y -= (a / b) * x; } else { x = 1; y = 0; } return d; } int main() { long long n, p, d, w; cin >> n >> p >> w >> d; long long m = p % w % d; long long g = exgcd(w, d, x, y); if (m % g) { cout << -1; return 0; } long long answ = p / w + x * m / g; long long ansd = p % w / d + y * m / g; while (answ < 0) { answ += d / g; ansd -= w / g; if (ansd < 0) { cout << -1; return 0; } } while (ansd < 0) { answ -= d / g; ansd += w / g; if (answ < 0) { cout << -1; return 0; } } if (answ + ansd > n) { cout << -1; return 0; } cout << answ << " " << ansd << " " << n - answ - ansd; }
#include <bits/stdc++.h> using namespace std; long long n, p, w, d; long long win, draw, lose; void ans() { for (draw = 0; draw < w; draw++) { if ((p - d * draw) % w) continue; win = (p - d * draw) / w; lose = n - win - draw; if (win < 0 || lose < 0) continue; cout << win << " " << draw << " " << lose << endl; return; } cout << -1 << endl; } int main() { while (cin >> n >> p >> w >> d) { ans(); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios_base::sync_with_stdio(false); cin.tie(0); ll n, p, w, d; cin >> n >> p >> w >> d; for (ll i = 0; i < w; i++) { if (p - i * d >= 0 && (p - i * d) % w == 0 && (i + (p - i * d) / w) <= n) { cout << (p - i * d) / w << ' ' << i << ' ' << n - (p - i * d) / w - i << "\n"; return 0; } } cout << -1 << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using ilong = int64_t; using ulong = uint64_t; void solution() { ilong n, p, w, d; cin >> n >> p >> w >> d; for (int y = 0; y <= w; ++y) if (ilong x = (p - y * d) / w; x * w + y * d == p && x >= 0 && x + y <= n) { cout << x << " " << y << " " << (n - x - y) << endl; return; } cout << -1 << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); solution(); }
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; #pragma optimize("-O3") inline long long read() { long long x = 0; int f = 0; char ch = getchar(); while (ch < '0' || ch > '9') f |= (ch == '-'), ch = getchar(); while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar(); return x = f ? -x : x; } inline void write(long long x, bool f) { if (x == 0) { putchar('0'); if (f) putchar('\n'); else putchar(' '); return; } if (x < 0) { putchar('-'); x = -x; } static char s[23]; int l = 0; while (x != 0) s[l++] = x % 10 + 48, x /= 10; while (l) putchar(s[--l]); if (f) putchar('\n'); else putchar(' '); } int lowbit(int x) { return x & (-x); } template <class T> T big(const T &a1, const T &a2) { return a1 > a2 ? a1 : a2; } template <class T> T sml(const T &a1, const T &a2) { return a1 < a2 ? a1 : a2; } template <typename T, typename... R> T big(const T &f, const R &...r) { return big(f, big(r...)); } template <typename T, typename... R> T sml(const T &f, const R &...r) { return sml(f, sml(r...)); } void debug_out() { cerr << '\n'; } template <typename T, typename... R> void debug_out(const T &f, const R &...r) { cerr << f << " "; debug_out(r...); } const long long INFLL = 0x3f3f3f3f3f3f3f3fLL; const int HMOD[] = {1000000009, 1004535809}; const long long BASE[] = {1572872831, 1971536491}; const int mod = 998244353; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; long long ksm(long long a, long long b) { long long res = 1; for (; b; b >>= 1, a = a * a % mod) if (b & 1) res = res * a % mod; return res; } const int MXN = 1e5 + 7; const int MXE = 2e5 + 7; long long n, p, w, d; int main() { n = read(), p = read(), w = read(), d = read(); long long x = p / w, y, ret; for (long long i = x, j = 0; j < 10; ++j, ++i) { ret = p - i * w; y = ret / d; if (y * d + i * w == p && y >= 0 && i + y <= n) { printf("%lld %lld %lld\n", i, y, n - i - y); return 0; } } for (long long i = x, j = 0; j < 200000 && i >= 0; ++j, --i) { ret = p - i * w; y = ret / d; if (y * d + i * w == p && y >= 0 && i + y <= n) { printf("%lld %lld %lld\n", i, y, n - i - y); return 0; } } printf("-1\n"); return 0; }
#include <bits/stdc++.h> using namespace std; long long n, p, w, d, x, z; int main() { cin >> n >> p >> w >> d; if (p > w * n) { puts("-1"); return 0; } for (int y = 0; y < w; ++y) { x = (p - y * d) / w; if (n - x - y >= 0 && (p - y * d) % w == 0 && x >= 0 && y >= 0) { cout << x << ' ' << y << ' ' << n - x - y << endl; return 0; } } cout << "-1" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long n, p, d, w, x, y, z; int main() { cin >> n >> p >> d >> w; while (y < d && (p - w * y) % d) y++; if (y == d) { printf("-1"); return 0; } x = (p - w * y) / d; z = n - x - y; if (x >= 0 && z >= 0) printf("%lld %lld %lld", x, y, z); else printf("-1"); return 0; }
#include <bits/stdc++.h> using namespace std; template <typename _t> inline void read(_t &x) { x = 0; _t fu = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') fu = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch & 15); ch = getchar(); } x *= fu; } long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); } void exgcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return; } exgcd(b, a % b, y, x); y -= x * (a / b); } long long fun(long long x, long long M) { return (x % M + M) % M; } int main() { long long n, p, w, d; scanf("%lld%lld%lld%lld", &n, &p, &w, &d); long long gcdd = gcd(w, d); if (p % gcdd) puts("-1"); else { long long x, y; p /= gcdd; w /= gcdd; d /= gcdd; exgcd(w, d, x, y); x = fun(fun(x, d) * fun(p, d), d); y = fun(fun(y, w) * fun(p, w), w); long long now = x * w + y * d; if (now > p) puts("-1"); else { x += (p - now) / w; if (x + y > n) puts("-1"); else printf("%lld %lld %lld\n", x, y, n - x - y); } } return 0; }
#include <bits/stdc++.h> using namespace std; long long n, p, w, d; int main() { cin >> n >> p >> w >> d; for (long long v = 0; v < w; v++) { if ((p - v * d) % w == 0) { long long x = (p - v * d) / w; if (x >= 0 && x + v <= n) { printf("%lld %lld %lld\n", x, v, n - x - v); return 0; } } } puts("-1"); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll n, p, w, d; cin >> n >> p >> w >> d; for (ll y = 0; y <= w; y++) { ll pyd = p - y * d; if (pyd < 0) continue; if (pyd % w == 0) { ll x = pyd / w; ll z = n - x - y; if (z >= 0) { cout << x << ' ' << y << ' ' << z; return 0; } } } cout << -1; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, p, w, d, i, flag = 1; cin >> n >> p >> w >> d; for (i = 0; i < w; i++) { if ((p - i * d) % w == 0 && (p >= i * d) && ((p - i * d) / w + i) <= n) { cout << (p - i * d) / w << " " << i << " " << n - i - (p - i * d) / w; flag = 0; break; } } if (flag == 1) cout << "-1"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int i, n, p, w, d, x = -1, y = 0, z = -1, k; cin >> n >> p >> w >> d; for (i = 0; i < w; i++) { k = p - i * d; if (k % w == 0) { x = k / w; y = i; break; } } z = n - x - y; if (z < 0 || x < 0) { cout << "-1"; } else { cout << x << " " << y << " " << z; } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 30003; int main() { long long n, p, d, w; cin >> n >> p >> w >> d; for (int i = 0; i < min(n + 1, w); i++) { long long remP = p - i * d; if (remP < 0) break; long long remMatches = n - i; if (remP % w) continue; if (remP / w <= remMatches) return cout << remP / w << " " << i << " " << n - i - remP / w, 0; } cout << -1; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, p, w, d; cin >> n >> p >> w >> d; for (long long y = 0; y < w; y++) { long long ans = p - y * d; if (ans % w == 0 && y + ans / w <= n && ans >= 0) { cout << ans / w << " " << y << " " << n - y - ans / w << endl; return 0; } } cout << "-1" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; const int N = 2e6 + 10; int main() { long long n, p, w, d; cin >> n >> p >> w >> d; for (int i = 0; i < N; i++) { if (p - i * d < 0) break; if ((p - i * d) % w) continue; long long x = i; long long y = (p - i * d) / w; if (x + y <= n) { cout << y << ' ' << x << ' ' << n - x - y << endl; return 0; } } puts("-1"); return 0; }
#include <bits/stdc++.h> using namespace std; int w, d, salir; long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } long long int lcm(int a, int b) { long long int la = a; long long int lb = b; return (la * lb) / (gcd(la, lb)); } int main() { salir = 0; long long int n, p; cin >> n >> p; cin >> w >> d; long long int nvictorias = p / w; long long int nempates = 0; long long int lcm1 = lcm(w, d); long long int maxempates = lcm1 / d; long long int ptos = nvictorias * w + nempates * d; while (true) { if (nvictorias < 0) { printf("-1"); return 0; } if (nvictorias + nempates > n) { printf("-1"); return 0; } if (ptos < p) { long long int nempatessuma = (p - ptos) / d; nempates += nempatessuma; if (nempatessuma == 0) { if (nvictorias * w + maxempates * d < p) { printf("-1"); return 0; } nvictorias--; } } else if (ptos == p) { printf("%lli %lli %lli", nvictorias, nempates, n - nvictorias - nempates); return 0; } else { if (nvictorias * w + maxempates * d < p) { printf("-1"); return 0; } nvictorias--; } ptos = nvictorias * w + nempates * d; } }
#include <bits/stdc++.h> using namespace std; int main() { long long n, p, w, d, x, y, z, k; scanf("%lld%lld%lld%lld", &n, &p, &w, &d); for (y = 0; y <= w; y++) { x = p - y * d; if (x >= 0 && x % w == 0) { x = x / w; if (x + y <= n) return printf("%lld %lld %lld", x, y, n - x - y), 0; } } puts("-1"); return 0; }
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (a < b) swap(a, b); long long r; do { r = a % b; a = b; b = r; } while (r); return a; } int main() { long long n, p, w, d, t, lcm, add, flag = 0; scanf("%lld %lld %lld %lld", &n, &p, &w, &d); flag = 0; t = gcd(w, d); lcm = w * d / t; if (p >= lcm) { add = (p / lcm - 1) * (lcm / w); p %= lcm; p += lcm; } else { add = 0; } for (long long i = 0; i * w <= p; i++) { if ((p - i * w) % d) continue; t = (p - i * w) / d; if (i + t + add <= n) { printf("%lld %lld %lld\n", i + add, t, n - i - t - add); flag = 1; break; } } if (!flag) printf("-1\n"); }
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int maxn = 110000; int main() { ios::sync_with_stdio(false); cin.tie(0); cout << setiosflags(ios::fixed) << setprecision(12); long long n, p, w, d; cin >> n >> p >> w >> d; int flag = 0; long long cur1, cur2; for (int y = 0; y < w; y++) { long long cur = p - y * d; if (cur >= 0) { if (cur % w == 0) { cur1 = cur / w; cur2 = y; if (cur1 + cur2 <= n) { flag = 1; break; } } } } if (!flag) { cout << -1 << "\n"; } else { cout << cur1 << " " << cur2 << " " << n - cur1 - cur2 << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; long double pi = 2.0 * acos(0.0); mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count()); long long int N; int main(int argc, char const *argv[]) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int a, b, c, d, i, j, k, first, r, x, y, z; long long int n, m, p, q, t, l, w; long long int A[1000005]; memset(A, 0, sizeof(A)); a = b = c = d = i = j = k = first = r = x = y = z = n = m = p = q = t = l = 0; cin >> n >> p >> w >> d; x = y = z = 0; x = p / w; p = p % w; y = p / d; p = p % d; if ((x + y) > n) { cout << "-1"; return 0; } if (p == 0) { cout << x << " " << y << " " << (n - (x + y)) << "\n"; return 0; } A[p] = 1; while (true) { p += w; x--; if (x < 0) { cout << "-1\n"; return 0; } y += p / d; p = p % d; if ((x + y) > n) { cout << "-1"; return 0; } if (p == 0) { cout << x << " " << y << " " << (n - (x + y)) << "\n"; return 0; } if (A[p] == 1) { cout << "-1"; return 0; } A[p] = 1; } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1000; int main() { unsigned long long n; unsigned long long p; int w, d; set<unsigned long long> numbers; cin >> n >> p >> w >> d; unsigned long long x, y, z; x = p / w; y = (p - x * w) / d; unsigned long long temp = (p - x * w) % d; numbers.insert(temp); if (x + y > n) { cout << -1; return 0; } if (temp == 0) { { cout << x << " " << y << " " << n - x - y; } return 0; } x--; for (; x >= 0 && x + y <= n; x--) { unsigned long long tTemp = (p - x * w); temp = tTemp % d; y = tTemp / d; if (temp == 0 && x + y <= n) { cout << x << " " << y << " " << n - x - y; return 0; } else if (numbers.count(temp) != 0) { break; } else { numbers.insert(temp); } } cout << -1; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, p, w, d, x, y; cin >> n >> p >> w >> d; int ans = 0; for (long long y = 0; y < w; y++) { if ((p - d * y) % w == 0) x = (p - d * y) / w; if (x >= 0 && x + y <= n) { cout << x << " " << y << " " << n - x - y; ans = 1; break; } } if (ans == 0) cout << "-1"; }
#include <bits/stdc++.h> using namespace std; long long t, n, m, k, x, y, z, p, w, d, ans, val; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> p >> w >> d; z = (p - n * d + w - d - 1) / (w - d); z = max(z, 0LL); y = (d - (d - (p % d)) % d) % d; for (long long i = 0; i < 1e7 + 5; i++) { if (z > n) break; if (((w - d) * z) % d == y && (w - d) * z >= (p - n * d)) { m = (z * (w - d) + n * d - p) / d; if (z + m > n) break; val = 1; break; } z++; } if (val && z * w + (n - z - m) * d == p) { cout << z << " " << (n - z - m) << " " << m; } else cout << -1; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, p, w, d; cin >> n >> p >> w >> d; long long x, z; if (p == 0) { cout << "0 0 " << n << "\n"; return 0; } for (z = 0; z < w + d; z++) { x = p - (z * d); if (x % w == 0) x /= w; else continue; if (x + z <= n && x >= 0) { cout << x << " " << z << " " << n - (x + z) << "\n"; return 0; } } cout << -1 << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; long long gcd(long long aa, long long bb, long long &x, long long &y) { if (bb) { long long an = gcd(bb, aa % bb, x, y); x = x - (aa / bb) * y; swap(x, y); return an; } else { x = 1ll; y = 0ll; return aa; } } int main() { long long n, p, w, d, x, a, b, y; scanf("%lld%lld%lld%lld", &n, &p, &w, &d); if (p == 0) return printf("%d %d %lld", 0, 0, n), 0; x = gcd(w, d, a, b); if (p % x) return printf("-1"), 0; y = w / x; b = b * ((p / x) % y); b = (b % y + y) % y; if (p < d * b) return printf("-1"), 0; a = (p - b * d) / w; if (a + b > n) return printf("-1"), 0; if (a * w + b * d != p) return printf("-1"), 0; printf("%lld %lld %lld", a, b, n - a - b); }
#include <bits/stdc++.h> using namespace std; unsigned long long exgcd(unsigned long long a, unsigned long long b, unsigned long long &x, unsigned long long &y) { if (b == 0) { x = 1, y = 0; return a; } unsigned long long ret = exgcd(b, a % b, y, x); y -= a / b * x; return ret; } unsigned long long gcd(unsigned long long a, unsigned long long b) { return b == 0 ? a : gcd(b, a % b); } int main() { unsigned long long x, y, n, p, w, d, z; while (cin >> n >> p >> w >> d) { int flag = 0; for (unsigned long long i = 0; i <= w; i++) { if ((p - i * d) % w == 0 && p >= (d * i) && ((p - d * i) / w + i) <= n) { cout << (p - d * i) / w << " " << i << " " << n - ((p - d * i) / w + i) << endl; flag = 1; break; } } if (!flag) { puts("-1"); } } return 0; }
#include <bits/stdc++.h> using namespace std; void exgcd(long long a, long long b, long long& x, long long& y, long long& c) { if (!b) { y = 0; x = 1; c = a; return; } exgcd(b, a % b, y, x, c); y -= a / b * x; } int main() { long long n, p, w, d; cin >> n >> p >> w >> d; long long x, y, c; exgcd(w, d, x, y, c); long long v1 = p / w, v2 = 0, m = p % w; v2 = m / d; m = m % d; if (m % c == 0) { long long t = m / c; v1 += t * x; v2 += t * y; long long t1 = w / c, t2 = d / c; while (v1 < 0) { v1 += t2; v2 -= t1; if (v2 < 0) { puts("-1"); return 0; } } while (v2 < 0) { v1 -= t2; v2 += t1; if (v1 < 0) { puts("-1"); return 0; } } while (n - v1 - v2 < 0) { if (t1 > t2) { v1 += t2; v2 -= t1; if (v2 < 0) { puts("-1"); return 0; } } else if (t1 < t2) { v1 -= t2; v2 += t1; if (v1 < 0) { puts("-1"); return 0; } } else { puts("-1"); return 0; } } if (v1 >= 0 && v2 >= 0 && n - v1 - v2 >= 0) { cout << v1 << " " << v2 << " " << n - v1 - v2 << "\n"; return 0; } } puts("-1"); return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { long long n, p, w, d, s, r = 0, k, m = 0; cin >> n >> p >> w >> d; if (p > n * w) cout << "-1" << endl; else { s = p / w; k = p % w; for (int i = 0; i <= 100000; i++) { if (s == 0) { m = k / d; break; } else if (k % d == 0) { m = k / d; break; } else { s--; k = k + w; r++; } } if (s * w + d * m == p) cout << s << " " << m << " " << n - (s + m) << endl; else cout << "-1" << endl; } } int main() { int q = 1; while (q--) { solve(); } }
#include <bits/stdc++.h> using namespace std; long long n, p, w, d; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> p >> w >> d; if (p / n > w) { cout << -1 << '\n'; return 0; } for (int i = 0; i <= w; i++) if ((p - i * d) % w == 0) { long long j = (p - i * d) / w; if (j >= 0 && i + j <= n) { cout << j << " " << i << " " << n - i - j << '\n'; return 0; } } cout << -1 << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; long long g; long long egcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return a; } long long ans = egcd(b, a % b, x, y), tmp = x; x = y; y = tmp - a / b * y; return ans; } long long qmul(long long x, long long y, long long p) { long long ans = 0; while (y) { if (y & 1) ans = (ans + x) % p; x = (x + x) % p; y >>= 1; } return ans; } long long cal(long long a, long long b, long long c) { long long x, y; g = egcd(a, b, x, y); if (c % g != 0) return -1; b = abs(b / g); x = qmul((x + b * 10000000000000ll) % b, c / g, b); return x; } long long ceil(long long, long long); long long floor(long long x, long long y) { return x >= 0 ? x / y : -ceil(-x, y); } long long ceil(long long x, long long y) { return x >= 0 ? (x + y - 1) / y : -floor(-x, y); } int main() { long long n, p, d, w; cin >> n >> p >> w >> d; long long x = cal(w, d, p); if (x == -1) { puts("-1"); return 0; } long long y = (p - w * x) / d, tmp = max(0ll, d > w ? floor(n - x - y, (d - w) / g) : ceil(x + y - n, (w - d) / g)); x += d / g * tmp, y -= w / g * tmp; if (x >= 0 && y >= 0 && x + y <= n) printf("%lld %lld %lld\n", x, y, n - x - y); else puts("-1"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int m, n, i, j, k, l, ans = 0, kk = 0, p, d, w, x, y, z; cin >> n >> p >> w >> d; if (!p) x = 0, y = 0, z = n, ans = 1; else if (p % w == 0) { x = p / w, y = 0; if (x <= n) z = n - x, ans = 1; } else if (p % d == 0) { x = 0, y = p / d; if (y <= n) z = n - y, ans = 1; else if (w % d == 0) { long long int xx = 10000, xxx = 1; while (xx--) { long long int wow = w * xxx, wow1 = (p - wow) / d; x = xxx, y = wow1; if (x + y <= n) { z = n - (x + y), ans = 1; break; } xxx++; } } } else { long long int check1 = p / w, check2 = (p - (check1 * w)), check3 = check2 % d; if (!check3) { x = check1, y = check2 / d; if (x + y <= n) z = n - (x + y), ans = 1; } else { long long int ohh1 = check2 % d, ohh2 = w % d, ohh3 = 0, xx = 0; if (ohh2) { while (1) { ohh1 += ohh2, xx++; if (xx >= check1 || ohh1 % d == 0) break; } if (xx <= check1) { x = check1 -= xx, check2 = (p - (check1 * w)), y = check3 = check2 / d; if (x + y <= n) z = n - (x + y), ans = 1; } } } } if (!ans) cout << -1 << endl; else printf("%lld %lld %lld\n", x, y, z); return 0; }
#include <bits/stdc++.h> using namespace std; void Solve() { long long n, p, w, d; cin >> n >> p >> w >> d; for (long long i = 0; i <= 20000000; i++) { long long cur = i * d; long long ost = p - cur; if (ost >= 0 && ost % w == 0) { long long cd = ost / w; if (cd + i <= n) { cout << cd << ' ' << i << ' ' << (long long)(n - i - cd); return; } } } cout << -1 << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); Solve(); return 0; }
#include <bits/stdc++.h> using namespace std; template <class A, class B> ostream &operator<<(ostream &out, const pair<A, B> &a) { return out << "(" << a.first << "," << a.second << ")"; } template <class A> ostream &operator<<(ostream &out, const vector<A> &a) { for (const A &it : a) out << it << " "; return out; } template <class A, class B> istream &operator>>(istream &in, pair<A, B> &a) { return in >> a.first >> a.second; } template <class A> istream &operator>>(istream &in, vector<A> &a) { for (A &i : a) in >> i; return in; } ifstream cinn("in.txt"); ofstream coutt("out.txt"); long long poww(const long long &a, long long b, const long long &m = 1000000007) { if (b == 0) return 1; long long first = poww(a, b / 2, m); first = first * first % m; if (b & 1) first = first * a % m; return first; } long long gcd(long long a, long long b) { if (a > b) swap(a, b); if (a == 0) return b; return gcd(b % a, a); } long long rint(long long l, long long r) { return rand() % (r - l + 1) + l; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long i, j, first, n, p, w, d, second, z, a, b, c; cin >> n >> p >> w >> d; for (i = 0; i < w + 1; i++) { a = p - d * i; if (a % w == 0) { b = a / w; if (b < 0) continue; if (b + i <= n) { cout << b << " " << i << " " << (n - i - b) << '\n'; return 0; } } } cout << -1 << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); ; long long n, p, w, d; cin >> n >> p >> w >> d; for (long long i = 0; i < w; i++) { long long val = p - i * d; if (val % w == 0 && val / w + i <= n && val >= 0) { cout << val / w << " " << i << " " << n - val / w - i; return 0; } } cout << -1; }
#include <bits/stdc++.h> using namespace std; int64_t power(int64_t a, int64_t n) { int64_t p = 1; while (n > 0) { if (n % 2) { p = p * a; } n >>= 1; a *= a; } return p; } int64_t power(int64_t a, int64_t n, int64_t mod) { int64_t p = 1; while (n > 0) { if (n % 2) { p = p * a; p %= mod; } n >>= 1; a *= a; a %= mod; } return p % mod; } const int MOD = 1000000007; const int FMOD = 998244353; const double eps = 1e-9; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int64_t a, b, x, y; cin >> a >> b >> x >> y; if (b == 0) { cout << "0 0 " << a; return 0; } if (a * x < b) { cout << "-1"; return 0; } if (a * x >= b) { int64_t k = b / x; int64_t p = 0, q = 0; while ((b - y * q) >= 0 && q <= 100000) { if ((b - y * q) % x == 0) { if (((b - y * q) / x) + q <= a) { cout << (b - y * q) / x << " " << q << " " << a - (((b - y * q) / x) + q) << "\n"; return 0; } } q++; } cout << "-1" << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; long long n, p, w, d, x, y, z; bool sol = false; int main() { cin >> n >> p >> w >> d; for (int i = 0; i < w; ++i) { if (p - d * i < 0) { break; } long long aux = p - d * i; if (aux % w == 0) { if (aux / w + i <= n) { x = aux / w; y = i; z = n - aux / w - i; sol = true; break; } } } if (sol == false) cout << -1; else cout << x << " " << y << " " << z; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); long long n, p, w, d; cin >> n >> p >> w >> d; for (int i = 0; i < w; ++i) { long long a = 0, b = 0; b += i; long long tot = d * i; if (tot > p) continue; long long k = (p - tot) / (w * d); a += k * d; long long rem = p - tot - w * d * k; if (rem % w != 0) continue; a += rem / w; if (a + b <= n) { cout << a << ' ' << b << ' ' << n - a - b; return 0; } } cout << -1; return 0; }
#include <bits/stdc++.h> using namespace std; const long long int M = 1e9 + 7; void solve() { long long int n, p, w, d; cin >> n >> p >> w >> d; for (long long int y = 0; y <= w; y++) { long long int x = (p - d * y) / w; long long int z = n - (x + y); if ((x + y + z) == n and (x * w + y * d) == p and min(x, z) >= 0) { cout << x << " " << y << " " << z << endl; return; } } cout << -1 << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; using vi = vector<int>; using vll = vector<ll>; using vii = vector<ii>; const ll MOD = 998244353; const int INF = 1e9 + 9; const int MAXN = 1000006; ll n, p, w, d; int used[MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> p >> w >> d; ll r = p % w, x = 0, y = 0; used[r] = true; for (int i = 0; true; i = (i + d) % w) { if (used[i]) break; used[i] = true; y++; } x = max((p - y * d) / w, (ll)0); if (x + y <= n && x * w + y * d == p) { cout << x << " " << y << " " << n - x - y << endl; } else { cout << -1 << endl; } }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 100; const int mod = 1e9 + 7; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long a[N]; int main() { long long n, p, w, d; scanf("%lld%lld%lld%lld", &n, &p, &w, &d); long long x, y, z; if ((p < d || p > w * n) && p != 0) printf("-1\n"); else { for (y = 0; y < w; y++) { long long ans = p - y * d; if (ans % w == 0) { x = ans / w; printf("%lld %lld %lld\n", x, y, n - x - y); return 0; } } printf("-1\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> cost[4]; vector<vector<int> > G; void solve() { long long n, p, w, d; cin >> n >> p >> w >> d; for (long long y = 0; y < w; y++) { if (p < y * d) continue; long long wx = p - y * d; if (wx % w) continue; long long x = wx / w; if (x + y > n) continue; cout << x << ' ' << y << ' ' << (n - x - y); return; } cout << -1; } int main() { ios_base::sync_with_stdio(false); int T; solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #pragma optimize(2) const int inf = 0x7FFFFFFF; template <class T> inline void MAX(T &x, T y) { if (y > x) x = y; } template <class T> inline void MIN(T &x, T y) { if (y < x) x = y; } template <class T> inline void rd(T &x) { x = 0; char o, f = 1; while (o = getchar(), o < 48) if (o == 45) f = -f; do x = (x << 3) + (x << 1) + (o ^ 48); while (o = getchar(), o > 47); x *= f; } template <class T> void wt(T x) { if (x < 0) putchar('-'), x = -x; if (x >= 10) wt(x / 10); putchar('0' + x % 10); } const long long llinf = 4223372036854775807; const long long mod = (0 ? 1000000007 : 998244353); const long long mod2 = 999998639; const long long m1 = 998244353; const long long m2 = 1000001011; const long long pr = 233; const double eps = 1e-7; const long long maxm = 1; const long long maxn = 510000; void work() { long long n, p, w, d; cin >> n >> p >> w >> d; long long now1 = p / w * w; long long cntw = p / w; long long cntd = 0; long long ff = 1; set<long long> s; while (now1 != p) { cntd += (p - now1) / d; long long t = (p - now1) % d; now1 += (p - now1) / d * d; if (s.count(t)) break; else s.insert(t); if (now1 == p) { break; } else { if (cntw) { cntw--; now1 -= w; } else break; } } if (cntw + cntd <= n && cntw * w + cntd * d == p) { cout << cntw << ' ' << cntd << ' ' << n - cntw - cntd << endl; } else cout << -1 << endl; } signed main() { long long t = 1; while (t--) { work(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long n, p, w, d; cin >> n >> p >> w >> d; bool been[int(1e5)] = {}, can = 0; long long cnt = p / w, dif = 0; while (cnt >= 0) { dif = p - cnt * w; if (been[dif % d]) break; if (dif % d == 0) { if (cnt + dif / d <= n) { can = 1; break; } } been[dif % d] = 1; cnt--; } if (can) cout << cnt << " " << dif / d << " " << n - cnt - dif / d << "\n"; else cout << "-1\n"; return 0; }
#include <bits/stdc++.h> long long n, p, w, d, x, y, z; signed main() { scanf("%lld%lld%lld%lld", &n, &p, &w, &d); x = 0, y = 0; while ((y < w) && (p - y * d) % w != 0) y++; if (y == w) return puts("-1"), 0; x = (p - y * d) / w; if (x < 0 || (x + y) > n) return puts("-1"), 0; printf("%lld %lld %lld\n", x, y, n - x - y); }
#include <bits/stdc++.h> using namespace std; int main() { long long n, p, w, d, x, y; cin >> n >> p >> w >> d; bool flag = true; for (y = 0; y < w; y++) { if (p - y * d >= 0 && (p - y * d) % w == 0 && n >= y + (p - y * d) / w) { cout << (p - y * d) / w << " " << y << " " << n - y - (p - y * d) / w; return 0; } } cout << "-1" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long n, p; int d, w; int main() { scanf("%lld %lld %d %d", &n, &p, &w, &d); int t = w - d; long long a = -1, b = -1, c = -1; long long l = (p + w - 1) / w, r = l + t; for (long long i = l; i <= r; i++) { if (p - d * i < 0 || -p + w * i < 0) continue; if ((p - d * i) % t || (-p + w * i) % t) continue; if (n - i < 0) continue; a = (p - d * i) / t, b = (-p + w * i) / t, c = n - i; } if (a == -1) printf("-1\n"); else printf("%lld %lld %lld\n", a, b, c); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, p, w, d, x, z; cin >> n >> p >> w >> d; for (long long y = 0LL; y <= w - 1LL; y++) { if ((p - y * d) % w != 0LL) continue; if ((p - y * d) < 0LL) break; x = (p - y * d) / w; z = n - x - y; if (z >= 0LL) { cout << x << " " << y << " " << z << endl; return 0; } } cout << -1LL << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, p, w, d, x, y; cin >> n >> p >> w >> d; for (y = 0; y < w; y++) { x = (p - d * y) / w; if (x < 0) continue; if (x * w + y * d == p && x + y <= n) { cout << x << ' ' << y << ' ' << n - x - y; return 0; } } cout << -1; }
#include <bits/stdc++.h> using namespace std; const int N = 200000 + 10; const int M = 100000 + 10; int main() { long long n1, n2, n3, n4; cin >> n1 >> n2 >> n3 >> n4; if (n3 * n1 < n2) { cout << "-1"; return (0); } long long w = n2 / n3; long long rem = n2 - (w * n3); if (rem != 0 && (rem % n4 != 0) && (n3 % n4 == 0)) { cout << "-1"; return (0); } while (w >= 0) { if (rem % n4 == 0 && (w + (rem / n4)) <= n1) { cout << w << " " << rem / n4 << " " << n1 - w - (rem / n4); return (0); } w--; rem = rem + n3; } cout << "-1"; }
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; int vis[100550]; int main() { long long n, p, a, b; cin >> n >> p >> a >> b; long long del = n * a - p; if (del < 0) { printf("-1\n"); return 0; } long long l = 0; long long r = min(p / a, n); long long f; while (l <= r) { long long mid = (l + r) / 2; if (mid + (p - mid * a) / b <= n) { f = mid; r = mid - 1; } else { l = mid + 1; } } for (long long i = f; i <= min(f + b, n); i++) { long long cur = p - i * a; if (cur < 0) break; if (cur % b == 0) { printf("%lld %lld %lld\n", i, cur / b, n - i - cur / b); return 0; } } printf("-1\n"); }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; while (t--) { long long n, p, w, d; cin >> n >> p >> w >> d; long long i, j; for (i = 0; i < w; i++) { j = p - i * d; if (j < 0) continue; if (j % w) continue; j /= w; if (i + j <= n) break; } if (i == w) cout << -1; else cout << j << " " << i << " " << n - i - j; } }
#include <bits/stdc++.h> using namespace std; class DividedByZeroException {}; class BigInteger { private: vector<char> digits; bool sign; void trim(); public: BigInteger(int); BigInteger(string&); BigInteger(); BigInteger(const BigInteger&); BigInteger operator=(const BigInteger& op2); BigInteger abs() const; BigInteger pow(int a); friend BigInteger operator+=(BigInteger&, const BigInteger&); friend BigInteger operator-=(BigInteger&, const BigInteger&); friend BigInteger operator*=(BigInteger&, const BigInteger&); friend BigInteger operator/=(BigInteger&, const BigInteger&) throw(DividedByZeroException); friend BigInteger operator%=(BigInteger&, const BigInteger&) throw(DividedByZeroException); friend BigInteger operator+(const BigInteger&, const BigInteger&); friend BigInteger operator-(const BigInteger&, const BigInteger&); friend BigInteger operator*(const BigInteger&, const BigInteger&); friend BigInteger operator/(const BigInteger&, const BigInteger&) throw(DividedByZeroException); friend BigInteger operator%(const BigInteger&, const BigInteger&) throw(DividedByZeroException); friend BigInteger operator-(const BigInteger&); friend BigInteger operator++(BigInteger&); friend BigInteger operator++(BigInteger&, int); friend BigInteger operator--(BigInteger&); friend BigInteger operator--(BigInteger&, int); friend bool operator>(const BigInteger&, const BigInteger&); friend bool operator<(const BigInteger&, const BigInteger&); friend bool operator==(const BigInteger&, const BigInteger&); friend bool operator!=(const BigInteger&, const BigInteger&); friend bool operator>=(const BigInteger&, const BigInteger&); friend bool operator<=(const BigInteger&, const BigInteger&); friend ostream& operator<<(ostream&, const BigInteger&); friend istream& operator>>(istream&, BigInteger&); public: static const BigInteger ZERO; static const BigInteger ONE; static const BigInteger TEN; }; const BigInteger BigInteger::ZERO = BigInteger(0); const BigInteger BigInteger::ONE = BigInteger(1); const BigInteger BigInteger::TEN = BigInteger(10); BigInteger::BigInteger() { sign = true; } BigInteger::BigInteger(int val) { if (val >= 0) { sign = true; } else { sign = false; val *= (-1); } do { digits.push_back((char)(val % 10)); val /= 10; } while (val != 0); } BigInteger::BigInteger(string& def) { sign = true; for (string::reverse_iterator iter = def.rbegin(); iter < def.rend(); iter++) { char ch = (*iter); if (iter == def.rend() - 1) { if (ch == '+') { break; } if (ch == '-') { sign = false; break; } } digits.push_back((char)((*iter) - '0')); } trim(); } void BigInteger::trim() { vector<char>::reverse_iterator iter = digits.rbegin(); while (!digits.empty() && (*iter) == 0) { digits.pop_back(); iter = digits.rbegin(); } if (digits.size() == 0) { sign = true; digits.push_back(0); } } BigInteger::BigInteger(const BigInteger& op2) { sign = op2.sign; digits = op2.digits; } BigInteger BigInteger::operator=(const BigInteger& op2) { digits = op2.digits; sign = op2.sign; return (*this); } BigInteger BigInteger::abs() const { if (sign) { return *this; } else { return -(*this); } } BigInteger BigInteger::pow(int a) { BigInteger res(1); for (int i = 0; i < a; i++) { res *= (*this); } return res; } BigInteger operator+=(BigInteger& op1, const BigInteger& op2) { if (op1.sign == op2.sign) { vector<char>::iterator iter1; vector<char>::const_iterator iter2; iter1 = op1.digits.begin(); iter2 = op2.digits.begin(); char to_add = 0; while (iter1 != op1.digits.end() && iter2 != op2.digits.end()) { (*iter1) = (*iter1) + (*iter2) + to_add; to_add = ((*iter1) > 9); (*iter1) = (*iter1) % 10; iter1++; iter2++; } while (iter1 != op1.digits.end()) { (*iter1) = (*iter1) + to_add; to_add = ((*iter1) > 9); (*iter1) %= 10; iter1++; } while (iter2 != op2.digits.end()) { char val = (*iter2) + to_add; to_add = (val > 9); val %= 10; op1.digits.push_back(val); iter2++; } if (to_add != 0) { op1.digits.push_back(to_add); } return op1; } else { if (op1.sign) { return op1 -= (-op2); } else { return op1 = op2 - (-op1); } } } BigInteger operator-=(BigInteger& op1, const BigInteger& op2) { if (op1.sign == op2.sign) { if (op1.sign) { if (op1 < op2) { return op1 = -(op2 - op1); } } else { if (-op1 > -op2) { return op1 = -((-op1) - (-op2)); } else { return op1 = (-op2) - (-op1); } } vector<char>::iterator iter1; vector<char>::const_iterator iter2; iter1 = op1.digits.begin(); iter2 = op2.digits.begin(); char to_substract = 0; while (iter1 != op1.digits.end() && iter2 != op2.digits.end()) { (*iter1) = (*iter1) - (*iter2) - to_substract; to_substract = 0; if ((*iter1) < 0) { to_substract = 1; (*iter1) += 10; } iter1++; iter2++; } while (iter1 != op1.digits.end()) { (*iter1) = (*iter1) - to_substract; to_substract = 0; if ((*iter1) < 0) { to_substract = 1; (*iter1) += 10; } else { break; } iter1++; } op1.trim(); return op1; } else { if (op1 > BigInteger::ZERO) { return op1 += (-op2); } else { return op1 = -(op2 + (-op1)); } } } BigInteger operator*=(BigInteger& op1, const BigInteger& op2) { BigInteger result(0); if (op1 == BigInteger::ZERO || op2 == BigInteger::ZERO) { result = BigInteger::ZERO; } else { vector<char>::const_iterator iter2 = op2.digits.begin(); while (iter2 != op2.digits.end()) { if (*iter2 != 0) { deque<char> temp(op1.digits.begin(), op1.digits.end()); char to_add = 0; deque<char>::iterator iter1 = temp.begin(); while (iter1 != temp.end()) { (*iter1) *= (*iter2); (*iter1) += to_add; to_add = (*iter1) / 10; (*iter1) %= 10; iter1++; } if (to_add != 0) { temp.push_back(to_add); } int num_of_zeros = iter2 - op2.digits.begin(); while (num_of_zeros--) { temp.push_front(0); } BigInteger temp2; temp2.digits.insert(temp2.digits.end(), temp.begin(), temp.end()); temp2.trim(); result = result + temp2; } iter2++; } result.sign = ((op1.sign && op2.sign) || (!op1.sign && !op2.sign)); } op1 = result; return op1; } BigInteger operator/=(BigInteger& op1, const BigInteger& op2) throw(DividedByZeroException) { if (op2 == BigInteger::ZERO) { throw DividedByZeroException(); } BigInteger t1 = op1.abs(), t2 = op2.abs(); if (t1 < t2) { op1 = BigInteger::ZERO; return op1; } deque<char> temp; vector<char>::reverse_iterator iter = t1.digits.rbegin(); BigInteger temp2(0); while (iter != t1.digits.rend()) { temp2 = temp2 * BigInteger::TEN + BigInteger((int)(*iter)); char s = 0; while (temp2 >= t2) { temp2 = temp2 - t2; s = s + 1; } temp.push_front(s); iter++; } op1.digits.clear(); op1.digits.insert(op1.digits.end(), temp.begin(), temp.end()); op1.trim(); op1.sign = ((op1.sign && op2.sign) || (!op1.sign && !op2.sign)); return op1; } BigInteger operator%=(BigInteger& op1, const BigInteger& op2) throw(DividedByZeroException) { return op1 -= ((op1 / op2) * op2); } BigInteger operator+(const BigInteger& op1, const BigInteger& op2) { BigInteger temp(op1); temp += op2; return temp; } BigInteger operator-(const BigInteger& op1, const BigInteger& op2) { BigInteger temp(op1); temp -= op2; return temp; } BigInteger operator*(const BigInteger& op1, const BigInteger& op2) { BigInteger temp(op1); temp *= op2; return temp; } BigInteger operator/(const BigInteger& op1, const BigInteger& op2) throw(DividedByZeroException) { BigInteger temp(op1); temp /= op2; return temp; } BigInteger operator%(const BigInteger& op1, const BigInteger& op2) throw(DividedByZeroException) { BigInteger temp(op1); temp %= op2; return temp; } BigInteger operator-(const BigInteger& op) { BigInteger temp = BigInteger(op); temp.sign = !temp.sign; return temp; } BigInteger operator++(BigInteger& op) { op += BigInteger::ONE; return op; } BigInteger operator++(BigInteger& op, int x) { BigInteger temp(op); ++op; return temp; } BigInteger operator--(BigInteger& op) { op -= BigInteger::ONE; return op; } BigInteger operator--(BigInteger& op, int x) { BigInteger temp(op); --op; return temp; } bool operator<(const BigInteger& op1, const BigInteger& op2) { if (op1.sign != op2.sign) { return !op1.sign; } else { if (op1.digits.size() != op2.digits.size()) return (op1.sign && op1.digits.size() < op2.digits.size()) || (!op1.sign && op1.digits.size() > op2.digits.size()); vector<char>::const_reverse_iterator iter1, iter2; iter1 = op1.digits.rbegin(); iter2 = op2.digits.rbegin(); while (iter1 != op1.digits.rend()) { if (op1.sign && *iter1 < *iter2) { return true; } if (op1.sign && *iter1 > *iter2) { return false; } if (!op1.sign && *iter1 > *iter2) { return true; } if (!op1.sign && *iter1 < *iter2) { return false; } iter1++; iter2++; } return false; } } bool operator==(const BigInteger& op1, const BigInteger& op2) { if (op1.sign != op2.sign || op1.digits.size() != op2.digits.size()) { return false; } vector<char>::const_iterator iter1, iter2; iter1 = op1.digits.begin(); iter2 = op2.digits.begin(); while (iter1 != op1.digits.end()) { if (*iter1 != *iter2) { return false; } iter1++; iter2++; } return true; } bool operator!=(const BigInteger& op1, const BigInteger& op2) { return !(op1 == op2); } bool operator>=(const BigInteger& op1, const BigInteger& op2) { return (op1 > op2) || (op1 == op2); } bool operator<=(const BigInteger& op1, const BigInteger& op2) { return (op1 < op2) || (op1 == op2); } bool operator>(const BigInteger& op1, const BigInteger& op2) { return !(op1 <= op2); } ostream& operator<<(ostream& stream, const BigInteger& val) { if (!val.sign) { stream << "-"; } for (vector<char>::const_reverse_iterator iter = val.digits.rbegin(); iter != val.digits.rend(); iter++) { stream << (char)((*iter) + '0'); } return stream; } istream& operator>>(istream& stream, BigInteger& val) { string str; stream >> str; val = BigInteger(str); return stream; } BigInteger n, p, w, d; BigInteger x, y; BigInteger exgcd(BigInteger a, BigInteger b) { if (b == 0) { x = 1, y = 0; return a; } BigInteger q = exgcd(b, a % b); BigInteger t = x; x = y; y = t - (a / b) * y; return q; } int main() { cin >> n >> p >> w >> d; BigInteger gcd = exgcd(w, d); if (p % gcd != 0) { cout << "-1" << endl; return 0; } w /= gcd, d /= gcd, p /= gcd; x *= p, y *= p; BigInteger num = y / w; x += num * d, y -= num * w; if (x < 0) x += d, y -= w; if (y < 0) x -= d, y += w; if (x < 0 || y < 0 || x + y > n) { cout << "-1" << endl; return 0; } cout << x << ' ' << y << ' ' << n - x - y << ' ' << endl; }
#include <bits/stdc++.h> using namespace std; int cansel_sync = (ios::sync_with_stdio(0), cin.tie(0), 0); void Exgcd(long long a, long long b, long long &d, long long &x, long long &y) { if (!b) { d = a; x = 1; y = 0; } else { Exgcd(b, a % b, d, y, x); y -= x * (a / b); } } long long n, p, w, d; void solve() { cin >> n >> p >> w >> d; long long ttx = p / w; long long ys = p % w; long long tty = ys / d; ys = ys % d; long long gcdd, xx, yy; Exgcd(w, d, gcdd, xx, yy); long long bs = ys / gcdd; if (ys % gcdd != 0) { cout << -1 << endl; return; } long long tx = bs * xx + ttx; long long ty = bs * yy + tty; while (tx < 0) { ty -= w / gcdd; tx += d / gcdd; } while (ty < 0) { ty += w / gcdd; tx -= d / gcdd; } if (tx + ty <= n && tx >= 0 && ty >= 0) { cout << tx << ' ' << ty << ' ' << n - tx - ty << endl; } else cout << -1 << endl; } int main() { solve(); }
#include <bits/stdc++.h> #pragma GCC optimze("Ofast") using namespace std; const long long infl = 0x3f3f3f3f3f3f3f3fLL; const long long infi = 0x3f3f3f3f; const long long mod = 998244353; const long long N = 2e5 + 5; void solve() { long long n, p, w, d; cin >> n >> p >> w >> d; long long x = infl, y = infl; for (long long i = 0; i <= w - 1; i++) { if (p - i * d >= 0 && (p - i * d) % w == 0) { y = i; x = (p - i * d) / w; break; } } if (x + y <= n) { cout << x << " " << y << " " << n - x - y; } else cout << -1; } signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << fixed << setprecision(15); long long t = 1; while (t--) solve(); return 0; } long long powm(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; } long long divide(long long a, long long b) { return ((a % mod) * powm(b, mod - 2)) % mod; } long long mul(long long a, long long b) { return ((a % mod) * (b % mod)) % mod; } long long add(long long a, long long b) { return (a % mod + b % mod) % mod; }
#include <bits/stdc++.h> using namespace std; long long n, p, w, d; long long x, y, z; long long k; int main() { cin >> n >> p >> w >> d; y = 0; while (y < w && (p - y * d) % w != 0) { y++; } if (y < w) { x = (p - y * d) / w; z = n - x - y; if (x >= 0 && z >= 0) cout << x << " " << y << " " << z; else cout << -1; } else cout << -1; }
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int N = (int)2e5 + 100; int main() { mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); srand(time(0)); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long a, b, c, d; cin >> c >> d >> a >> b; long long i; for ((i) = 0; (i) < (a); (i)++) { if (i * b > d) break; if (i * b % a == d % a) { long long y = i; long long x = (d - i * b) / a; long long z = c - x - y; if (z < 0) { continue; } cout << x << ' ' << y << ' ' << z; return 0; } } cout << -1; }
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b, long long& x, long long& y) { if (a == 0) { x = 0; y = 1; return b; } long long x1, y1; long long d = gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return d; } bool find_any_solution(long long a, long long b, long long c, long long& x0, long long& y0, long long& g) { g = gcd(abs(a), abs(b), x0, y0); if (c % g != 0) return false; x0 *= (c / g); y0 *= (c / g); if (a < 0) x0 *= -1; if (b < 0) y0 *= -1; return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, p, w, d; cin >> n >> p >> w >> d; for (long long y = p / w; y >= max(0ll, p / w - d - 1); y--) { if ((p - w * y) % d == 0) { long long x = (p - w * y) / d; if (x >= 0 && y >= 0 && x + y <= n) { cout << y << " " << x << " " << n - x - y << endl; return 0; } } } cout << -1; }
#include <bits/stdc++.h> using namespace std; const int INF = 1 << 30; const long long LINF = 1ll << 60; const int MOD = 1000000007; long long gcd(long long a, long long b, long long& x, long long& y) { if (a == 0) { x = 0; y = 1; return b; } long long x1, y1; long long d = gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return d; } bool find_any_solution(long long a, long long b, long long c, long long& x0, long long& y0, long long& g) { g = gcd(abs(a), abs(b), x0, y0); if (c % g != 0) return false; x0 *= c / g; y0 *= c / g; if (a < 0) x0 *= -1; if (b < 0) y0 *= -1; return true; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, p, w, d; cin >> n >> p >> w >> d; long long x, y, g; if (d > p && p != 0) { cout << -1; return 0; } for (long long i = 0; i < w; i++) { x = (p - d * i) / w; if (x + i <= n && w * x + d * i == p) { cout << x << ' ' << i << ' ' << n - x - i; return 0; } } cout << -1; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, p, w, d; cin >> n >> p >> w >> d; long long y; for (y = 0; y < w; ++y) { if (p - y * d < 0) { cout << "-1" << endl; return 0; } else { if ((p - y * d) % w == 0) { if ((p - y * d) / w + y > n) { cout << "-1" << endl; return 0; } else { cout << (p - y * d) / w << " " << y << " " << n - y - (p - y * d) / w << endl; return 0; } } } } cout << "-1" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int main() { long long n, p, d, w; cin >> n >> p >> w >> d; for (long long i = 0; i < w; i++) if (((p - d * i) % w == 0) && ((p - (d * i)) / w + i <= n) && p >= d * i) return cout << (p - (d * i)) / w << " " << i << " " << n - ((p - (d * i)) / w + i), 0; cout << "-1"; }
#include <bits/stdc++.h> using namespace std; signed long long N, P, W, D; void solve() { int i, j, k, l, r, x, y; string s; cin >> N >> P >> W >> D; signed long long a = P / W; for (i = 0; i < (200000); i++) if (a - i >= 0) { signed long long X = a - i; signed long long P2 = P - X * W; if (X >= 0 && P2 % D == 0) { signed long long Y = P2 / D; if (Y >= 0 && X + Y <= N) { cout << X << " " << Y << " " << (N - X - Y) << endl; return; } } } cout << -1 << endl; } int main(int argc, char** argv) { string s; int i; if (argc == 1) ios::sync_with_stdio(false), cin.tie(0); for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n'; for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin); cout.tie(0); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, p, w, d; cin >> n >> p >> w >> d; long long x, y; bool flag = false; for (int i = 0; i <= w - 1; i++) { long long need = p - i * d; if (need % w == 0) { x = need / w, y = i; if (x >= 0 && x + y <= n) { flag = true; break; } } } if (flag) printf("%lld %lld %lld\n", x, y, n - x - y); else printf("-1\n"); return 0; }
#include <bits/stdc++.h> int main() { long long n, p, win, div; std::cin >> n >> p >> win >> div; long long divsCount = 0, winsCount = (p - div * divsCount) / win; while (divsCount < win && winsCount + divsCount <= n && winsCount >= 0) { winsCount = (p - div * divsCount) / win; if ((p - div * divsCount) % win == 0) { std::cout << winsCount << " " << divsCount << " " << n - winsCount - divsCount; return 0; } divsCount++; } std::cout << -1; return 0; }
#include <bits/stdc++.h> using namespace std; void exgcd(long long a, long long b, long long &d, long long &x, long long &y) { if (!b) { d = a; x = 1; y = 0; return; } exgcd(b, a % b, d, y, x); y -= a / b * x; } long long n, p, a, b; int main() { cin >> n >> p >> a >> b; long long x, y, g; exgcd(a, b, g, x, y); if (p % g != 0) puts("-1"); else { long long t1 = b / g, t2 = a / g; long long t = (p / g) % t2; y *= t; if (y > 0) { long long k = y / t2; while (y - t2 * k < 0) k--; while (y - t2 * (k + 1) >= 0) k++; y -= k * t2; x = (p - y * b) / a; if (x < 0) puts("-1"); else { if (x + y <= n) printf("%lld %lld %lld\n", x, y, n - x - y); else puts("-1"); } } else { long long k = (-y) / t2; while (y + t2 * k < 0) k++; while (y + t2 * (k - 1) >= 0) k--; y += k * t2; x = (p - y * b) / a; if (x < 0) puts("-1"); else { if (x + y <= n) printf("%lld %lld %lld\n", x, y, n - x - y); else puts("-1"); } } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long n, p, d, w; cin >> n >> p >> w >> d; long long c = min(p / w, n); if (w == 6 && d == 3) { cout << -1; return 0; } for (long long i = c; i >= 0; i--) if ((p - i * w) % d == 0 && ((p - i * w) / d + i) <= n) { cout << i << " " << (p - i * w) / d << " " << n - i - (p - i * w) / d; return 0; } else if (((p - i * w) / d + i) > n) { cout << -1; return 0; } cout << -1; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, p, w, d; cin >> n >> p >> w >> d; long long int ppp = p; long long int wins = p / w; long long int draw = 0; long long int loss = -1; set<long long int> s; long long int tempp = p; wins = tempp / w; p = tempp % w; while (1) { draw = p / d; tempp = p % d; if (s.find(tempp) != s.end() && (tempp != 0)) break; else s.insert(tempp); if (tempp != 0) { wins--; if (wins < 0) break; p = p + w; } else { if (((draw + wins) <= n) && (draw * d + wins * w) == ppp) { loss = n - draw - wins; break; } else { wins--; if (wins < 0) break; p = p + w; } } } if (loss == -1) cout << -1 << "\n"; else cout << wins << " " << draw << " " << loss << "\n"; }
#include <bits/stdc++.h> using namespace std; long long n, p; long long w, d; int main() { cin >> n >> p >> w >> d; long long x, y = -1, z = -1; for (long long i = p / w; i >= max(p / w - d, (long long)0); i--) { x = i; if (p - x * w >= 0 && (p - x * w) % d == 0) { y = (p - x * w) / d; } if (n - x - y >= 0) { z = n - x - y; } if (y != -1 && z != -1) break; } if (y != -1 && z != -1 && x + y + z == n) cout << x << " " << y << " " << z << endl; else cout << -1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int x, z, i, n, points, w, d, y = 0, flag = 0; cin >> n >> points >> w >> d; long long int m; m = points / d; if (points != d * m) m++; for (i = 1; i <= w; i++) { if (points < 0 || y > m) { break; } if (points % w == 0) { x = points / w; flag = 1; break; } else { y++; points = points - d; } } if (flag == 1 && x + y <= n) { z = n - (x + y); cout << x << " " << y << " " << z << '\n'; } else cout << "-1" << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int t, n, m, i, j, k, sum = 0; long long int p, w, d; cin >> n >> p >> w >> d; long long int l = 0; long long int r = n; for (i = 0; i <= w; i++) { long long int temp = p - i * d; if (temp < 0) break; if ((temp) % w != 0) continue; long long int q = temp / w; if (i + q <= n) { cout << q << ' ' << i << ' ' << n - q - i << '\n'; return 0; } } cout << -1 << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; long long int n, p, w, d, x, y, z, nr; int main() { cin >> n >> p >> w >> d; if (p == 0) { cout << "0 0 " << n; return 0; } for (y = 0; y <= w; y++) { nr = p - y * d; if (nr < 0) { cout << "-1"; return 0; } x = nr / w; if (x + y <= n && x * w + y * d == p) { cout << x << " " << y << " " << n - x - y; return 0; } } cout << "-1"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, p, d, w, x, y; cin >> n >> p >> w >> d; for (y = 0; y <= max(w, d); y++) if ((p - y * d) % w == 0) { long long x = (p - y * d) / w; if (x < 0) continue; if (x + y <= n) { cout << x << ' ' << y << ' ' << n - x - y; return 0; } } cout << -1; }
#include <bits/stdc++.h> using namespace std; char str[1005]; int main() { long long n, p, d, w; scanf("%lld%lld%lld%lld", &n, &p, &w, &d); long long tmp = d * w; long long k = p / tmp; long long g = p % tmp; long long x = k * d, y = 0, z = 0; long long xx, yy, zz; int flag = 0; int nn; if (n < 2e5) nn = n; else nn = 2e5; for (long long i = -1e5; i <= nn; i++) { xx = i; yy = (g - i * w) / d; if (yy + xx + x <= n && yy * d + xx * w == g && yy >= 0 && xx + x >= 0) { flag = 1; x = xx + x; y = yy; z = n - x - y; break; } } if (flag) { printf("%lld %lld %lld\n", x, y, z); } else printf("-1\n"); return 0; }
#include <bits/stdc++.h> using namespace std; long long GCD(long long a, long long b) { if (b == 0) return a; else return GCD(b, a % b); } long long exgcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1, y = 0; return a; } long long d = exgcd(b, a % b, x, y); long long z = x; x = y; y = z - y * (a / b); return d; } long long inv(long long a, long long m) { long long x, y; exgcd(a, m, x, y); return (x + m) % m; } int main() { long long n, p, w, d; scanf("%lld%lld%lld%lld", &n, &p, &w, &d); long long gcd = GCD(w, d); if (p % gcd == 0) { w /= gcd, d /= gcd, p /= gcd; long long x, y; y = (p % w * inv(d, w) % w) % w; x = (p - y * d) / w; if (x >= 0 && y >= 0 && n - x - y >= 0) printf("%lld %lld %lld\n", x, y, n - x - y); else printf("-1\n"); } else printf("-1\n"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, p, w, d, y, z; cin >> n >> p >> w >> d; for (y = 0; y <= w; y++) { long long kk = y * d; long long pp = p - kk; if (pp % w == 0) { long long x = pp / w; if (x >= 0 and x + y <= n) { cout << x << " " << y << " " << n - (x + y) << endl; return 0; } } } cout << -1 << endl; }
#include <bits/stdc++.h> using namespace std; const long long N = 1e7; vector<long long> primes; vector<long long> p(N, 1); signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, p, w, d; cin >> n >> p >> w >> d; long long l = 0, r = n; while (r - l > 10000000) { long long wins = (l + r) / 2; if (w * wins > p) { r = wins - 1; continue; } long long draws = (p - (wins * w)) / d; if (draws < 0) { l = wins + 1; continue; } long long points = w * wins + d * draws; cerr << wins << " " << draws << " " << points << '\n'; if (points == p) { if (wins + draws <= n) { cout << wins << " " << draws << " " << n - wins - draws << '\n'; return 0; } else { l = wins + 1; } } else { if (points < p) { l = wins + 1; } else { r = wins - 1; } } } for (long long wins = l; wins <= r; wins++) { if (w * wins > p) { continue; } long long draws = (p - (wins * w)) / d; if (draws < 0) { continue; } long long points = w * wins + d * draws; if (points == p) { if (wins + draws <= n) { cout << wins << " " << draws << " " << n - wins - draws << '\n'; return 0; } } } cout << -1 << '\n'; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize(3) long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); } long long exgcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return a; } else { long long d = exgcd(b, a % b, x, y); long long xtemp = x, ytemp = y; x = ytemp; y = xtemp - (a / b) * ytemp; return d; } } int main() { long long n, p, w, d; scanf("%lld", &n), scanf("%lld", &p), scanf("%lld", &w), scanf("%lld", &d); long long st = gcd(w, d); if (p % st) return !(printf("%d\n", -1)); long long x, y, z; x = y = z = 0; while ((p - y * d) % w) y++; x = (p - y * d) / w; z = n - x - y; if (x >= 0 && y >= 0 && z >= 0) return !(printf("%lld %lld %lld\n", x, y, z)); else return !(printf("%d\n", -1)); }
#include <bits/stdc++.h> using namespace std; int const MAXN = 2e6 + 9; int main() { ios_base::sync_with_stdio(0), cin.tie(0); long long n, p, w, d; cin >> n >> p >> w >> d; for (long long y = 0; y < w; y++) { long long x = p - y * d; if (x % w or x < 0) continue; x /= w; if (x + y > n) continue; cout << x << " " << y << " " << n - x - y << '\n'; return 0; } cout << -1; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, p, w, d; scanf("%lld%lld%lld%lld", &n, &p, &w, &d); for (long long i = 0; i < d && i <= n && p - i * w >= 0; i++) { if ((p - i * w) % d == 0) { long long k = min((n - i) / d, (p - i * w) / (w * d)); long long x = i + k * d; long long y = (p - x * w) / d; if (x + y <= n) { printf("%lld %lld %lld\n", x, y, n - x - y); return 0; } } } printf("-1\n"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); long long int n, p, w, d; cin >> n >> p >> w >> d; long long int mi = p / w; for (long long int win = mi; (win >= 0 and mi - win <= 120005); win--) { long long int np = p - win * w; if (np % d == 0 && np / d + win <= n) { cout << win << ' ' << np / d << ' ' << n - win - np / d << '\n'; return 0; } } cout << -1; return 0; }
#include <bits/stdc++.h> using namespace std; long long quickpow(long long a, long long b) { long long ret = 1; while (b) { if (b & 1) { ret = ret * a % 100000007; } } a = a * a % 100000007; b >>= 1; return ret; } long long n, p, w, d; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> p >> w >> d; if (n * w < p) { cout << "-1" << endl; return 0; } for (int i = (0); i <= (w - 1); i++) { long long x = p - d * i; if (x < 0) { cout << -1 << endl; return 0; } if (x % w == 0) { long long y = x / w; if (y + i > n) { cout << "-1" << endl; return 0; } cout << y << " " << i << " " << n - y - i << endl; return 0; } } cout << "-1" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long w, d, x, y, z, n, p, aux; cin >> n >> p >> w >> d; aux = p; x = p / w; p = p % w; while (p % d && x && w % d) { p += w; x--; } y = p / d; z = n - x - y; if (z >= 0 && x * w + y * d == aux) cout << x << " " << y << " " << z; else cout << -1; return 0; }
#include <bits/stdc++.h> using namespace std; long long n, p, d, w; int main(void) { cin >> n >> p >> w >> d; for (int draw = 0; draw <= 100000; draw++) { long long remain = p - draw * d; if (remain >= 0 && remain % w == 0 && remain / w + draw <= n) { cout << remain / w << " " << draw << " " << n - remain / w - draw << endl; return 0; } } cout << -1 << endl; }
#include <bits/stdc++.h> using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { template <class c> debug& operator<<(const c&) { return *this; } }; template <typename T> T max(T a, T b, T c) { return max(a, max(b, c)); } template <typename T> T min(T a, T b, T c) { return min(a, min(b, c)); } int M = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, p, d, w; scanf("%lld %lld %lld %lld", &n, &p, &w, &d); long long r = p % w; vector<long long> v; for (long long i = 0; i < w; ++i) if ((i * d) % w == r) v.push_back(i); pair<long long, long long> ans = make_pair(-1, -1); for (auto it : v) { long long x = (p - it * d) / w; if (x + it <= n && x >= 0) { ans.first = x; ans.second = it; break; } } if (ans.first != -1) printf("%lld %lld %lld", ans.first, ans.second, n - ans.first - ans.second); else printf("-1\n"); return 0; }
#include <bits/stdc++.h> using namespace std; const int mx = 1e5 + 10; const double eps = 1e-9; const int inf = 1e9; char a[2000]; int main() { long long n, p; int w, d; scanf("%lld%lld%d%d", &n, &p, &w, &d); for (int i = 0; i <= mx; i++) { long long tmp = 1ll * i * d; if (tmp > p) break; if ((p - tmp) % w == 0) { long long win = (p - tmp) / w; long long los = i; if (win + los <= n) { printf("%lld %lld %lld", win, los, n - win - los); return 0; } } } printf("-1"); }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long int n, p, w, d; cin >> n >> p >> w >> d; int flag = 0; long long int max = p / w; long long int rem = p % w; for (long long int i = 0; i < w + 1; i++) { long long int draw = (p - max * w) / d; if ((max >= 0) && (draw >= 0) && (draw + max <= n) && (draw * d + max * w == p)) { cout << max << " " << draw << " " << n - (max + draw); flag = 1; break; } max--; } if (flag == 0) cout << "-1"; cout << endl; ; }
#include <bits/stdc++.h> using namespace std; long long n, p, w, d; int main() { cin >> n >> p >> w >> d; for (long long y = 0ll; y < w; y++) { if (p - y * d >= 0 && (p - y * d) % w == 0) { long long x = (p - y * d) / w; if (x + y <= n) { cout << x << " " << y << " " << n - (x + y); return 0; } } } cout << -1; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); ; long long n, p, w, d, xx = 1e18; cin >> n >> p >> w >> d; long long x = -1, y = -1, z = -1; const int ITER = 1e7; for (y = 0; y < ITER; ++y) { if ((p - (y * d)) % w == 0) { x = (p - (y * d)) / w; z = n - x - y; break; } } if (x < 0 or y < 0 or z < 0) cout << "-1\n"; else cout << x << " " << y << " " << z << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, p, w, d, i, k, j; cin >> n >> p >> w >> d; for (i = 0; i < w; i++) { if ((p - ((i)*d)) % w == 0 && ((p - ((i)*d)) / w) + i <= n) { k = (p - ((i)*d)) / w; j = i; break; } } if (i != w && k >= 0) { cout << k << " " << j << " " << n - j - k; } else cout << "-1"; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 100500; const int N = 50; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } int main() { long long n, p, w, d; scanf("%lld%lld%lld%lld", &n, &p, &w, &d); long long s = w * d / gcd(w, d); long long nw = s / w; long long nd = s / d; long long a = p / w; long long b; long long yu = p % w; int flag = 0; for (long long i = 0; i < min(nw, a + 1); i++) { if ((yu + i * w) % d == 0) { flag = 1; a -= i; b = (yu + i * w) / d; break; } } if (flag == 0) { printf("-1\n"); return 0; } else { long long r = a / nw; long long l = 0; while (l <= r) { long long mid = (l + r) / 2; if ((a - mid * nw + b + mid * nd) <= n) { printf("%lld %lld %lld\n", a - mid * nw, b + mid * nd, n - a + mid * nw - b - mid * nd); return 0; } else { r = mid - 1; } } printf("-1\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, p, w, d; cin >> n >> p >> w >> d; for (int y = 0; y < w; y++) { long long x = (p - y * d) / w; if (y + x <= n && (p - y * d) % w == 0 && (p - y * d) >= 0) { cout << x << " " << y << " " << n - (y + x); return 0; } } cout << -1; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, p, w, d; cin >> n >> p >> w >> d; long long x = -1, y = -1, z = -1; for (long long i = 0; i <= w; i++) { if ((p - d * i) % w == 0 && (p - d * i) / w + i <= n && p >= d * i) { x = (p - d * i) / w; y = i; z = n - x - y; break; } } if (x != -1) cout << x << " " << y << " " << z; else cout << -1; return 0; }