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 "boxes.h"
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define inside sl<=l&&r<=sr
#define outside r<sl||sr<l
#define orta ((l+r)>>1)
#define INF 1000000009
#define mod 1000000007
#define ppair(x); cerr << "(" << x.first << ", " << x.second << ")\n";
#define bas(x) #x << ": " << x << " "
#define prarr(x, n); cerr << #x << ": "; for(int qsd = 0; qsd < n; qsd++) cerr << x[qsd] << " "; cerr << "\n";
#define prarrv(x); cerr << #x << ": "; for(int qsd = 0; qsd < (int)x.size(); qsd++) cerr << x[qsd] << " "; cerr << "\n";
using namespace std;
typedef long long ll;
ll n, k, s;
vector<int> arr;
ll tekcoz(vector<int>& ar){
if (ar[0] > ar.back()) reverse(ar.begin(), ar.end());
int i = ar.size()-1;
ll ans = 0;
while (i >= 0){
ans += ar[i] + ar[i];
i -= k;
}
return ans;
}
ll solve(){
vector<int> sol, sag;
for (int i = 0; i < n; i++) if (arr[i] < s - arr[i]) sol.pb(arr[i]); else sag.pb(s - arr[i]);
return tekcoz(sol) + tekcoz(sag);
}
ll solve2(){
int l = 0;
int r = k-1;
while (r < n && arr[l] < s-arr[r]) l++, r++;
if (r >= n) return s*s;
vector<int> sol, sag;
for (int i = 0; i < l; i++) sol.pb(arr[i]);
for (int i = n-1; i > r; i--) sag.pb(s-arr[i]);
ll ans1 = tekcoz(sol) + tekcoz(sag) + s;
sol.clear();
sag.clear();
l++; r++;
if (r >= n) return ans1;
for (int i = 0; i < l; i++) sol.pb(arr[i]);
for (int i = n-1; i > r; i--) sag.pb(s-arr[i]);
ll ans2 = tekcoz(sol) + tekcoz(sag) + s;
return min(ans1, ans2);
}
ll delivery(int N, int K, int L, int p[]) {
n = N;
k = K;
s = L;
for (int i = 0; i < n; i++) arr.pb(p[i]);
//sort(arr.begin(), arr.end());
ll ans = 0;
int artik = n%k;
int l = 0;
int r = n-1;
ll bas, son;
if (artik){
bas = arr[l+artik-1];
son = s - arr[r-artik+1];
if (bas < son){
ans = bas*2;
l += artik;
} else {
ans = son*2;
r -= artik;
}
}
while (l <= r){
bas = arr[l+k-1];
son = s-arr[r-k+1];
//cout << bas(bas) << bas(son) << endl;
if (2*bas > s && 2*son > s){
ans += s;
l += k;
continue;
}
if (bas < son) ans += bas*2, l += k;
else ans += son*2, r -= k;
}
//cout << solve() << endl;
return min(ans, min(solve(), solve2()));
}
Compilation message (stderr)
boxes.cpp: In function 'll tekcoz(std::vector<int>&)':
boxes.cpp:23:19: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
int i = ar.size()-1;
~~~~~~~~~^~
boxes.cpp:27:5: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
i -= k;
~~^~~~
boxes.cpp: In function 'll solve()':
boxes.cpp:34:85: warning: conversion to 'std::vector<int>::value_type {aka int}' from 'll {aka long long int}' may alter its value [-Wconversion]
for (int i = 0; i < n; i++) if (arr[i] < s - arr[i]) sol.pb(arr[i]); else sag.pb(s - arr[i]);
boxes.cpp: In function 'll solve2()':
boxes.cpp:40:11: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
int r = k-1;
~^~
boxes.cpp:45:16: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
for (int i = n-1; i > r; i--) sag.pb(s-arr[i]);
~^~
boxes.cpp:45:40: warning: conversion to 'std::vector<int>::value_type {aka int}' from 'll {aka long long int}' may alter its value [-Wconversion]
for (int i = n-1; i > r; i--) sag.pb(s-arr[i]);
boxes.cpp:52:16: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
for (int i = n-1; i > r; i--) sag.pb(s-arr[i]);
~^~
boxes.cpp:52:40: warning: conversion to 'std::vector<int>::value_type {aka int}' from 'll {aka long long int}' may alter its value [-Wconversion]
for (int i = n-1; i > r; i--) sag.pb(s-arr[i]);
boxes.cpp: In function 'll delivery(int, int, int, int*)':
boxes.cpp:66:15: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
int artik = n%k;
~^~
boxes.cpp:68:11: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
int r = n-1;
~^~
boxes.cpp:88:6: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
l += k;
~~^~~~
boxes.cpp:91:34: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
if (bas < son) ans += bas*2, l += k;
~~^~~~
boxes.cpp:92:24: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
else ans += son*2, r -= 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... |