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/Codeforces/Educational Codeforces Round 165/D. Shop Game
Prev
CodeforcesCodeforces
Expert
Educational Codeforces Round 165

D. Shop Game

SortingGreedyOrdered SetArray
Loading...
Solve on Codeforces

Problem Statement

Official algorithmic problem description and constraints.

Open on Codeforces

Alice and Bob are playing a game in the shop. There are π‘› items in the shop; each item has two parameters: π‘Žπ‘– (item price for Alice) and π‘π‘– (item price for Bob).

Alice wants to choose a subset (possibly empty) of items and buy them. After that, Bob does the following:

  • if Alice bought less than π‘˜ items, Bob can take all of them for free;
  • otherwise, he will take π‘˜ items for free that Alice bought (Bob chooses which π‘˜ items it will be), and for the rest of the chosen items, Bob will buy them from Alice and pay π‘π‘– for the π‘–th item.

Alice's profit is equal to βˆ‘π‘–βˆˆπ‘†π‘π‘–βˆ’βˆ‘π‘—βˆˆπ‘‡π‘Žπ‘—, where π‘† is the set of items Bob buys from Alice, and π‘‡ is the set of items Alice buys from the shop. In other words, Alice's profit is the difference between the amount Bob pays her and the amount she spends buying the items.

Alice wants to maximize her profit, Bob wants to minimize Alice's profit. Your task is to calculate Alice's profit if both Alice and Bob act optimally.

Solutions & Walkthrough

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

Connecting secure classroom stream...
Back to Educational Codeforces Round 165
Previous Problem