KEMBAR78
Problem - 2104B - Codeforces | PDF | Software | Computer Engineering
0% found this document useful (0 votes)
31 views2 pages

Problem - 2104B - Codeforces

The document describes a programming problem from Codeforces, where participants must manipulate an array of integers by moving elements to the end and calculating the maximum sum of the last k elements for each k from 1 to n. It outlines the input format, constraints, and provides an example of expected output for multiple test cases. The problem is part of the Educational Codeforces Round 178 and is rated for Div. 2 participants.

Uploaded by

Yhlas Yklymow
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views2 pages

Problem - 2104B - Codeforces

The document describes a programming problem from Codeforces, where participants must manipulate an array of integers by moving elements to the end and calculating the maximum sum of the last k elements for each k from 1 to n. It outlines the input format, constraints, and provides an example of expected output for multiple test cases. The problem is part of the Educational Codeforces Round 178 and is rated for Div. 2 participants.

Uploaded by

Yhlas Yklymow
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

9/2/25, 10:28 AM Problem - 2104B - Codeforces

|
stdfloat | Logout

HOME TOP CATALOG CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP RAYAN

PROBLEMS SUBMIT STATUS STANDINGS CUSTOM TEST

Educational Codeforces Round 178


B. Move to the End (Rated for Div. 2)
Finished
time limit per test: 2 seconds
memory limit per test: 512 megabytes Practice
You are given an array a consisting of n integers.

For every integer k from 1 to n , you have to do the following:


→ Virtual participation 
1. choose an arbitrary element of a and move it to the right end of the array (you can choose the last element,
Virtual contest is a way to take part in past contest,
then the array won't change); as close as possible to participation on time. It is
2. print the sum of k last elements of a; supported only ICPC mode for virtual contests. If
you've seen these problems, a virtual contest is not
3. move the element you've chosen on the first step to its original position (restore the original array a). for you - solve these problems in the archive. If you
just want to solve some problem from a contest, a
virtual contest is not for you - solve this problem in
For every k, you choose the element which you move so that the value you print is the maximum possible. the archive. Never use someone else's code, read
the tutorials or communicate with other person
during a virtual contest.
Calculate the value you print for every k.
Start virtual contest
Input
The first line contains one integer t (1 ≤ t ≤ 10
4
) — the number of test cases.
→ Clone Contest to Mashup 
Each test case consists of two lines:

5
the first line contains one integer n (1 ≤ n ≤ 2 ⋅ 10 ); → Submit?
9
the second line contains n integers a1 , a2 , … , an (1 ≤ ai ≤ 10 ).

5 Language: GNU G++20 13.2 (64 bit, winlibs)


Additional constraint on the input: the sum of n over all test cases does not exceed 2 ⋅ 10 .
Choose
Choose File No file chosen
Output file:
For each test case, print n integers. The i -th of these integers should be equal to the maximum value you can print
Submit
if k = i.

Example
→ Contest materials
input Copy

4 Announcement
7
13 5 10 14 8 15 13 Tutorial
6
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
1
42 → CF GetRating
2
7 5 *1000

output Copy Show All Tags


15 28 42 50 63 73 78 Contest Standings
1000000000 2000000000 3000000000 4000000000 5000000000 6000000000
42
7 12

Note
Let's consider the first test case from the statement:

when k = 1, you can move the 6 -th element to the end, the array becomes [13, 5, 10, 14, 8, 13, 15], and the
value you print is 15;
when k = 2, you can move the 6 -th element to the end, the array becomes [13, 5, 10, 14, 8, 13, 15], and the
value you print is 13 + 15 = 28;
when k = 3, you can move the 4 -th element to the end, the array becomes [13, 5, 10, 8, 15, 13, 14], and the
value you print is 15 + 13 + 14 = 42 ;
when k = 4, you can move the 5 -th element to the end, the array becomes [13, 5, 10, 14, 15, 13, 8], and the
value you print is 14 + 15 + 13 + 8 = 50;
when k = 5, you can move the 1 -st element to the end, the array becomes [5, 10, 14, 8, 15, 13, 13], and the
value you print is 14 + 8 + 15 + 13 + 13 = 63;
when k = 6, you can move the 1 -st element to the end, the array becomes [5, 10, 14, 8, 15, 13, 13], and the
value you print is 10 + 14 + 8 + 15 + 13 + 13 = 73;
when k = 7, you can move the 6 -th element to the end, the array becomes [13, 5, 10, 14, 8, 13, 15], and the
value you print is 13 + 5 + 10 + 14 + 8 + 13 + 15 = 78.

Codeforces (c) Copyright 2010-2025 Mike Mirzayanov


The only programming contests Web 2.0 platform

https://codeforces.com/problemset/problem/2104/B 1/2
9/2/25, 10:28 AM Problem - 2104B - Codeforces
Server time: Sep/02/2025 10:27:24UTC+5 (h1).
Desktop version, switch to mobile version.
Privacy Policy | Terms and Conditions

Supported by

https://codeforces.com/problemset/problem/2104/B 2/2

You might also like