RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
문제 IOIF008 ⇄ 인터랙티브

Boxes with Souvenirs

설명

There are \(n\) souvenirs positioned around a circular street of length \(L\); souvenir \(i\) is at integer position \(p_i\) (measured clockwise from \(0\)). You start and finish at position \(0\) and may carry at most \(k\) souvenirs at once. Moving along the street costs distance equal to the arc travelled (either direction; a full loop costs \(L\)).

Output the minimum total distance to deliver every souvenir and return to \(0\).

Note. This is an adaptation of an IOI function-implementation task to an interactive stdin/stdout problem. The test data is RiseOJ-generated (self-validated against an independent brute force), not the official IOI data.

Interaction / I/O protocol

Input. Line 1: \(n\), \(L\), \(k\). Line 2: \(n\) integers \(p_1 \dots p_n\) (\(0 \le p_i < L\)).

Output. Print one integer: the minimum total travel distance.

Example. n=4, L=10, k=2, positions 1 2 8 9: carry \(\{1,2\}\) clockwise (cost \(4\)) and \(\{8,9\}\) counter-clockwise (cost \(4\)) for a total of 8.

제약
  • \(1 \le n \le 5000\)
  • \(1 \le k \le n\)
  • \(1 \le L \le 10^{6}\), \(\; 0 \le p_i < L\)
입력 형식

Line 1: \(n\), \(L\), \(k\). Line 2: \(n\) integers \(p_1 \dots p_n\) (\(0 \le p_i < L\)).

출력 형식

Print one integer: the minimum total travel distance.

인터랙티브 문제
프로그램이 고정된 입력을 읽는 대신 표준 입출력으로 채점기와 메시지를 주고받습니다. 한 줄을 출력할 때마다 표준 출력을 flush하고(예: cout에 endl / print(..., flush=True) / System.out.flush()), 채점기의 응답을 읽으세요. 파일을 읽거나 쓰면 안 됩니다.
문제 정보

rip 작성

출처 IOI 2015

평가 및 의견

Boxes with Souvenirs

개요
출제자 난이도 Platinum V 플래티넘 V 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Boxes with Souvenirs

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8