Submission #677428

# Submission time Handle Problem Language Result Execution time Memory
677428 2023-01-03T09:45:24 Z stanislavpolyn Measures (CEOI22_measures) C++17
0 / 100
1500 ms 648 KB
#include <bits/stdc++.h>

#define fr(i, a, b) for (int i = (a); i <= (b); ++i)
#define rf(i, a, b) for (int i = (a); i >= (b); --i)
#define fe(x, y) for (auto& x : y)

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define all(x) (x).begin(), (x).end()
#define pw(x) (1LL << (x))
#define sz(x) (int)(x).size()

using namespace std;

mt19937_64 rng(228);

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order
#define ook order_of_key

template <typename T>
bool umn(T& a, T b) {
    return a > b ? (a = b, 1) : 0;
}
template <typename T>
bool umx(T& a, T b) {
    return a < b ? (a = b, 1) : 0;
}

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
using ve = vector<T>;

const int N = 3e5 + 5;

int n, m;
ll d;
ll a[N];
ll b[N];

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios::sync_with_stdio(0);
    cin.tie(0);
#endif

    cin >> n >> m >> d;

    d *= 2;

    fr (i, 1, n) {
        cin >> a[i];
        a[i] *= 2;
    }

    fr (i, 1, m) {
        ll x;
        cin >> x;
        x *= 2;
        a[++n] = x;
        sort(a + 1, a + 1 + n);

        auto possible = [&](ll t) {
            fr (i, 1, n) b[i] = a[i];

            fr (i, 1, n) {
                ll have = t;
                if (i > 1) {
                    ll x = b[i] - b[i - 1];
                    if (x < d) {
                        if (d - x > t) {
                            return 0;
                        }
                        have -= max(0LL, d - x);
                        b[i] = b[i - 1] + d;
                    }
                }
                if (i == 1 || b[i] - b[i - 1] > d) {
                    if (i == 1) b[i] -= t;
                    else b[i] -= min(b[i] - b[i - 1] - d, have);
                }
            }
            return 1;
        };

        ll l = 0;
        ll r = 4e9;
        while (l < r) {
            ll mid = l + ((r - l) >> 1);
            if (possible(mid)) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }
        assert(possible(l));

        cout << l / 2;
        if (l % 2) cout << ".5";
        cout << "\n";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Correct 4 ms 340 KB Output is correct
4 Correct 4 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Runtime error 2 ms 596 KB Execution killed with signal 6
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Correct 4 ms 340 KB Output is correct
4 Correct 4 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Runtime error 2 ms 596 KB Execution killed with signal 6
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1578 ms 648 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1578 ms 648 KB Time limit exceeded
2 Halted 0 ms 0 KB -