#include <bits/stdc++.h>
#include "boxes.h"
using namespace std ;
const int M_N = 1e5 + 7 ;
long long solve1(int N , int K, int L , int p[]){
long long ret = 0 , pivot = -1 ;
sort(p , p + N) ;
for(int i =0 ; i < N ; i++){
if(p[i] <=L /2 )
pivot = i ;
}
long long cur = 0 , swp = -1 ;
for(int i = 0 ; i <=pivot ; i++){
cur++;
if(cur==K){
ret+=2ll*p[i] ;
cur = 0 ;
swp = i ;
}
}
for(int i = 0 ; i <=swp ; i++)p[i] = 0;
cur = 0 , swp = N ;
for(int i = N-1 ; i>pivot ; i--){
cur++ ;
if(cur==K){
ret+=2ll*(L - p[i]) ;
cur = 0 ;
swp = i ;
}
}
for(int i = swp ; i <N ; i++)p[i] = 0 ;
long long road1 = 0 , road2 = 0, road3 = 0;
for(int i = 0 ; i < N;i++){
if(i<=pivot){
road1 = 2ll * p[i] ;
}else if(!road2 && p[i]){
road2 = 2ll*(L - p[i]) ;
}
}
return ret + road1 + road2 ;
}
long long delivery(int N, int K, int L, int p[]) {
long long ret = solve1(N , K , L , p) ;
return ret ;
vector<pair<int , int > > v ;
for(int i = 0 ; i < min(N, K) ; i++){
v.push_back({ -min(p[i] , L - p[i]) , i}) ;
}
for(int i = 0 ; i < min(N , K) ; i++){
p[v[i].second] = 0 ;
}
ret = min(ret , L + solve1(N , K , L , p)) ;
return ret;
}
Compilation message
boxes.cpp: In function 'long long int solve1(int, int, int, int*)':
boxes.cpp:33:17: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
for(int i = swp ; i <N ; i++)p[i] = 0 ;
^~~
boxes.cpp:34:38: warning: unused variable 'road3' [-Wunused-variable]
long long road1 = 0 , road2 = 0, road3 = 0;
^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
128 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
128 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Incorrect |
4 ms |
256 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
128 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Incorrect |
4 ms |
256 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
128 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Incorrect |
4 ms |
256 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |