This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "boxes.h"
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 1e7 + 10;
long long f[N], g[N];
int p[N];
long long delivery(int n, int k, int l, int P[]) {
for (int i = 0; i < n; ++i) p[i + 1] = P[i];
for (int i = 1; i <= n; ++i) f[i] = f[max(0, i - k)] + 2 * p[i];
for (int i = n; i >= 1; --i) g[i] = g[min(n + 1, i + k)] + 2 * (l - p[i]);
long long ans = 1e18;
k = min(k, n);
for (int i = 1; i <= n; ++i)
ans = min(ans, f[i] + g[i + 1]);
for (int i = 1; i <= n; ++i) {
for (int j = i; j <= n; ++j) {
int t = ceil(1.0L * (j - i + 1) / k);
ans = min(ans, f[i - 1] + g[j + 1] + 1LL * t * l);
}
}
return ans;
}
//
//int main() {
// freopen("test.inp", "r", stdin);
// ios :: sync_with_stdio(0); cin.tie(0);
// int n, k, l;
// cin >> n >> k >> l;
// int p[n];
// for (int i = 0; i < n; ++i) cin >> p[i];
// cout << delivery(n, k, l, p);
//}
Compilation message (stderr)
boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:29:25: warning: conversion from 'long double' to 'int' may change value [-Wfloat-conversion]
29 | int t = ceil(1.0L * (j - i + 1) / k);
| ~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |