Learn DSADSAContests
coding75 logo
LeetCode POTDPOTDSheets
coding75 Pro
coding75 logo
Dashboard
Learn DSA
Course RoadmapFlow
DSA Topic TreeNew πŸš€
Contest SolutionsPractice
Practice Sheets
MasterclassesLive πŸ‘¨πŸ»β€πŸ’»

coding75 ProPRO

Live Classes & Placement Guidance

coding75 logo

The premier developer platform for mastering Data Structures & Algorithms, exploring contest editorials, building ATS-ready resumes, and accelerating your tech career.

Connect & Community

DSA & Contests

  • Learn DSA
  • Contest Solutions
  • LeetCode POTDDaily
  • Practice Sheets
  • MasterclassesSoon

Interview Prep

  • Portfolio Projects
  • CS Fundamentals
  • System DesignSoon
  • Interview ExperiencesSoon
  • Mock InterviewsSoon

Career & Pro

  • Jobs & Internships
  • Resume BuilderATS
  • coding75 Pro
  • Submit Feedback
Β© 2026coding75β€’crackDSAβ„’β€’Maa Lalita Edtech Private Limited. All Rights Reserved.
Privacy PolicyTerms & ConditionsContact Support
Registered Office: Kanpur 208021β€’Regional Office: Indiranagar, Bangalore, 560008
Maa Lalita Edtech Private Limited
Contests/CodeChef/Starters 134/3out1in
Prev
CodeChefCodeChef
5 Star
Starters 134

3out1in

ArrayOrdered SetGreedyPrefix Sum
Loading...
Solve on CodeChef

Problem Statement

Official algorithmic problem description and constraints.

Open on CodeChef

Given an array B containing M (where M is odd) integers, you have to perform the following operation on B until it consists of only a single element.

  • Choose distinct indices i, j, k of the array B.
  • Remove π΅π‘–,𝐡𝑗,π΅π‘˜β€‹ from the array.
  • Append (𝐡𝑖+π΅π‘—βˆ’π΅π‘˜).

Note that the operation reduces the length of B by 2.

For example, if π΅=[2,5,3,4,2], you can choose indices (3,1,4), delete the values π΅3,𝐡1,𝐡4 from B, and append π΅3+𝐡1βˆ’π΅4=3+2βˆ’4=1 to it, obtaining π΅=[5,2,1].

Your aim is to maximize the value of the final element remaining in the array.

Let this maximum value be π‘“(𝐡)

You are given an array A of length N. Answer Q queries on it.

In the i-th query, you are given an integer Ki​, which is guaranteed to be odd.

Compute π‘“([𝐴1,𝐴2,…,𝐴𝐾𝑖]).

That is, compute the answer when considering only the first Ki​ elements of A.

Each query is independent, so the array remains unchanged across queries.

Solutions & Walkthrough

Detailed video explanations, mathematical intuition, and clean C++ implementation code.

Connecting secure classroom stream...
Back to Starters 134
Previous Problem