제출 #1298334

#제출 시각아이디문제언어결과실행 시간메모리
1298334the_commando_x선물상자 (IOI15_boxes)C++17
10 / 100
1 ms576 KiB
#include "boxes.h"
#include <algorithm>

long long delivery(int N, int K, int L, int p[])
{
    auto dist = [&](long long x)
    {
        return std::min(x, (long long)L - x);
    };

    long long ans = 0;
    if (K == 1)
        for (int i = 0; i < N; ++i)
            ans += 2LL * std::max(0ll, dist(p[i]));

    else if (K == N)
    {
        ans = std::min({L, 2 * p[N - 1], L - 2 * p[0]});
        long long split1 = 0, split2 = 0;
        int i = (int)(std::lower_bound(p, p + N, L / 2) - p);
            if (i>0)
                split1 =p[i-1];
            if (i<N)
                split2 = L - p[i];

        ans = std::min(ans, 2 * (split1 + split2));
    }

    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...