RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
문제 COCI00701

Krugomet

설명

\(n\) students gathered in the schoolyard one sunny day and stood in a large circle.
Each person had his own box of balls (person \(i\) has \(a_{i}\) balls), as well as his crush
(maybe even himself), denoted by \(s_{i}\).
They decided to play their favorite game, krugomet. Playing krugomet consists
of \(k\) rounds. In each round, all participants in the game simultaneously throw
all their balls towards their crush. The students are skilled and agile, so they will
always catch all the balls thrown to them in a round. After the balls are caught,
everyone gets ready for the next round, and the whole process is repeated.
The teacher fell asleep on the bench and left the students to play alone. When he woke up, the students
asked him to tell them who won, i.e. to answer 2 questions:
• How many balls does the student with the most balls have after \(k\) rounds of play?
• Who collected the most balls after \(k\) rounds of play?
The teacher knows how many students played krugomet \(n\), the sequence of crushes \(s_{i}\), the initial number
of balls for each student \(a_{i}\), and how many rounds of play \(k\) were played. Unfortunately, the teacher
doesn’t have time to count how many balls each person has, so he leaves that up to you.
Help him and determine the list of students who collected the most balls. In case there is more than one
person with the most balls, print their indices in order from smaller to larger.

제약
입력 형식

In the first line are the two natural numbers \(n\) and \(k\) (\(1 \le n \le 10^{5}\), \(1 \le k \le 10^{9}\)) from the text of the task.
In the second line, there are \(n\) natural numbers \(a_{i}\) (\(1 \le a_{i} \le 1000\)), numbers from the text of the task
In the third line are \(n\) natural numbers \(s_{i}\) (\(1 \le s_{i} \le n\)), numbers from the text of the task.

출력 형식

In the first line, print a single number - the number of balls collected by the student with the most balls.
In the second line, print the indices of the students who collected the most balls. The indices should be
printed in ascending order.

서브태스크
서브태스크점수설명

1

14점

n, \(k \le 1000\)

2

26점

The sequence \(s\) is a permutation, \(s_{i}\)̸ = \(s_{j}\) (\(1 \le i < j \le n\)).

3

30점

No additional constraints. Correctly printing the 1st line earns 50% points for the test example. The remaining 50% points for the test example are earned by correctly printing the 2nd line.

예제 1
입력
2 1
5 6
2 1
출력
6
1
예제 2
입력
4 2
5 5 5 5
1 2 1 1
출력
15
1
예제 3
입력
4 10000000
1 2 3 4
2 1 4 3
출력
4
4
설명

Clarification of the first example: In the only round of krugomet, people labeled 1 and 2 threw all
their balls towards each other and "swapped" how many balls each person had. After the first round,
person labeled 1 had the most balls and was holding 6 balls.

문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2025/2026 Contest 1

평가 및 의견

Krugomet

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

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

풀이 제출

Krugomet

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