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>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define f(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
ll delivery(int n, int k, int l, int ar[]) {
ll ans = 1e18;
vector<int>arr;
f(i,0,n){
if(ar[i] != 0){
arr.pb(ar[i]);
}
}
n = arr.size();
f(p,0,n+1){
int pos = p-1;
ll res = 0;
while(pos >= 0){
res += min(l,2 * arr[pos]);
pos -= k;
}
int p2 = n - p;
pos = p2 - 1;
while(pos >= 0){
res += min(l,2 * (l - arr[n-1-pos]));
pos -= k;
}
ans = min(ans,res);
}
return ans;
}
Compilation message (stderr)
boxes.cpp: In function 'll delivery(int, int, int, int*)':
boxes.cpp:31:17: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
31 | n = arr.size();
| ~~~~~~~~^~
# | 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... |