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>
#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#include "boxes.h"
#define maxn 10000005
using namespace std;
typedef long long ll;
int n,k;
int niz[maxn];
int d;
set<int>s;
ll dist(int l, int r){
if(l > r)swap(l, r);
ll res = min(r - l, l + d - r);
return res;
}
long long delivery(int N, int K, int L, int p[]) {
n = N, k = K, d = L;
ff(i,1,n)niz[i] = p[i - 1];
ff(i,1,n){
s.insert(niz[i]);
}
int poz = 0;
int cap = k;
ll res = 0;
while(s.size() > 0){
if(cap == 0){
res += dist(poz, 0);
poz = 0;
cap = k;
continue;
}
int levi = *s.begin();
int desni = *s.rbegin();
int dist1 = dist(levi, poz);
int dist2 = dist(desni, poz);
int najbliza;
if(dist1 < dist2)najbliza = levi;
else najbliza = desni;
if(abs(najbliza - poz) + dist(poz, 0) <= dist(najbliza,0) + dist(poz,0)){
res += abs(najbliza - poz);
poz = najbliza;
cap--;
s.erase(najbliza);
}
else{
res += dist(poz, 0);
poz = 0;
}
}
return res;
}
Compilation message (stderr)
boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:35:25: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
int dist1 = dist(levi, poz);
~~~~^~~~~~~~~~~
boxes.cpp:36:25: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
int dist2 = dist(desni, poz);
~~~~^~~~~~~~~~~~
# | 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... |