#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
long long n,l,k,ans[20000000];
long long s[20000000];
long long tr(long i)
{
if(i==-1)
{
return 1e18;
}
//cout<<i<<endl;
//cout<<i<<endl;
long long num=n-i*k;
long long f=i*l;
long long j;
//cout<<n<<' '<<i*k<<endl;
j=1e18;
if(num<=0)
{
j=min(j,f);
return j;
}
// cout<<num<<endl;
// cout<<num<<endl;
if(s[n-num]>l/2)
{
j=min(j,f+ans[n-num]);
}
for(long y=0;y<num;y++)
{
// cout<<y<<' '<<i*k+y+1<<endl;
f=i*l;
if(s[y]>l/2)
{
break;
}
if(y+i*k+1==n)
{
j=min(j,f+ans[y]);
break;
}
//cout<<y<<endl;
if(y+i*k+1>n)
{
break;
}
if(s[y+i*k+1]<=l/2)
{
continue;
}
//cout<<y<<endl;
f+=ans[y];
f+=ans[i*k+y+1];
j=min(j,f);
// cout<<y<<' '<<i*k+y+1<<endl;
}
// cout<<i<<' '<<j<<endl;
return j;
}
long long delivery(int N, int K, int L, int p[]) {
n=N;
k=K;
l=L;
sort(p,p+n);
for(long i=0;i<n;i++)
{
s[i]=p[i];
}
long long preo[n];
long long pree[n];
long long v=0;
for(long i=0;i<n;i++)
{
if(p[i]>l/2)
break;
if(i<k)
{
ans[i]=p[i]*2;
continue;
}
ans[i]=ans[i-k]+p[i]*2;
}
for(long i=n-1;i>=0;i--)
{
if(p[i]<=l/2)
{
break;
}
long long sum=0;
if(n-1-i<k)
{
ans[i]=(l-p[i])*2;
continue;
}
ans[i]=ans[i+k]+(l-p[i])*2;
}
/* for(long i=0;i<n;i++)
{
cout<<ans[i]<<endl;
}*/
//return v;
long long h=1e18;
long long f=0;
long long i=0;
/* long long u=pow(2,25);
while(u>n/k)
{
u/=2;
}
long long e=u;
/* while(u>=1)
{
u/=2;
if(tr(e-u)>tr(e+u))
{
e+=u;
}else
{
e-=u;
}
}*/
return min(tr(0),tr(1));
}
Compilation message
boxes.cpp:129:3: warning: "/*" within comment [-Wcomment]
129 | /* while(u>=1)
|
boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:105:18: warning: unused variable 'sum' [-Wunused-variable]
105 | long long sum=0;
| ^~~
boxes.cpp:78:14: warning: unused variable 'preo' [-Wunused-variable]
78 | long long preo[n];
| ^~~~
boxes.cpp:79:14: warning: unused variable 'pree' [-Wunused-variable]
79 | long long pree[n];
| ^~~~
boxes.cpp:82:14: warning: unused variable 'v' [-Wunused-variable]
82 | long long v=0;
| ^
boxes.cpp:120:14: warning: unused variable 'h' [-Wunused-variable]
120 | long long h=1e18;
| ^
boxes.cpp:121:14: warning: unused variable 'f' [-Wunused-variable]
121 | long long f=0;
| ^
boxes.cpp:122:14: warning: unused variable 'i' [-Wunused-variable]
122 | long long i=0;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
60 ms |
19828 KB |
Output is correct |
34 |
Correct |
28 ms |
19852 KB |
Output is correct |
35 |
Correct |
31 ms |
19828 KB |
Output is correct |
36 |
Correct |
52 ms |
19772 KB |
Output is correct |
37 |
Correct |
54 ms |
19840 KB |
Output is correct |
38 |
Correct |
63 ms |
19812 KB |
Output is correct |
39 |
Correct |
56 ms |
19788 KB |
Output is correct |
40 |
Correct |
35 ms |
19828 KB |
Output is correct |
41 |
Correct |
63 ms |
19828 KB |
Output is correct |
42 |
Correct |
34 ms |
19816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
60 ms |
19828 KB |
Output is correct |
34 |
Correct |
28 ms |
19852 KB |
Output is correct |
35 |
Correct |
31 ms |
19828 KB |
Output is correct |
36 |
Correct |
52 ms |
19772 KB |
Output is correct |
37 |
Correct |
54 ms |
19840 KB |
Output is correct |
38 |
Correct |
63 ms |
19812 KB |
Output is correct |
39 |
Correct |
56 ms |
19788 KB |
Output is correct |
40 |
Correct |
35 ms |
19828 KB |
Output is correct |
41 |
Correct |
63 ms |
19828 KB |
Output is correct |
42 |
Correct |
34 ms |
19816 KB |
Output is correct |
43 |
Correct |
672 ms |
195944 KB |
Output is correct |
44 |
Correct |
305 ms |
196860 KB |
Output is correct |
45 |
Correct |
335 ms |
197088 KB |
Output is correct |
46 |
Correct |
585 ms |
200176 KB |
Output is correct |
47 |
Correct |
581 ms |
200388 KB |
Output is correct |
48 |
Correct |
577 ms |
200568 KB |
Output is correct |
49 |
Correct |
642 ms |
199980 KB |
Output is correct |
50 |
Correct |
374 ms |
197744 KB |
Output is correct |
51 |
Correct |
670 ms |
200788 KB |
Output is correct |
52 |
Correct |
365 ms |
197892 KB |
Output is correct |