Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int, int>
- #define pb(x) push_back(x)
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvl(vector <ll> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvv(vector <vector <int> > &v) {
- for (auto x : v) cv(x);
- cout << "\n";
- }
- void cvb(vector <bool> v) {
- for (bool x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvs(vector <string> v) {
- for (auto a : v) {
- cout << a << "\n";
- }
- }
- void cvp(vector <pii> a) {
- for (auto p : a) {
- cout << p.first << ' ' << p.second << "\n";
- }
- cout << "\n";
- }
- ll a, b, c, d;
- bool sh = 1;
- ll S(ll a1, ll d, ll n) {
- return (2 * a1 + d * (n - 1)) * n / 2;
- }
- ll f(ll t) {
- return 1 + (t - 1) / d;
- }
- ll g(ll t) {
- ll k = (t - 1 - c) / d;
- ll a1 = 1 + k * d + c - t;
- ll N = f(t) - (k - 1);
- ll del = S(a1, d * b, N);
- ll res = f(t) * b * c - del;
- return res;
- }
- ll hp(ll t) {
- return g(t) - f(t) * a ;
- }
- void slv() {
- cin >> a >> b >> c >> d;
- if (a > b * c) {
- cout << -1 << "\n";
- return;
- }
- //tehnarnik po t
- ll ls = 0, rs = 1e5, s1, s2, mn;
- if (sh) {
- rs = 30;
- }
- while (ls + 3 < rs) {
- s1 = ls + (rs - ls) / 3;
- s2 = ls + 2 * (rs - ls) / 3;
- if (sh) {
- cout << "ls s1 s2 rs = " << ls << ' ' << s1 << ' ' << s2 << ' ' << rs << "\n";
- cout << "hp(s1) = " << hp(s1) << "\n";
- cout << "hp(s2) = " << hp(s2) << "\n";
- }
- if (hp(s1) < hp(s2)) {
- mn = s1;
- rs = s2;
- } else {
- mn = s2;
- ls = s1;
- }
- }
- if (sh) {
- cout << "mn hp(mn) = " << mn << ' ' << hp(mn) << "\n";
- }
- cout << -hp(mn) << "\n";
- }
- int main() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- int t = 1;
- if (!sh) cin >> t;
- for (int go = 0; go < t; ++go) {
- slv();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement