Energy Stones

Hard
greedy sorting optimization scheduling
Problem Description

You have N energy stones, each with initial energy and decay rate per second. You can collect one stone per second, and stones lose energy over time. Find the maximum total energy you can collect by choosing the optimal order.

Input Format
First line contains n (number of stones). Next n lines contain two integers: initial energy and decay rate per second.
Output Format
Maximum total energy that can be collected.
Constraints
• 1 ≤ n ≤ 1000
• 1 ≤ initial energy ≤ 1000
• 1 ≤ decay rate ≤ 100
• Stones with energy ≤ 0 cannot be collected
• Optimal ordering is crucial
Sample Input/Output
Input:
3
100 10
200 20
50 5
Output:
330
Explanation

Optimal order: collect stone 2 (200-20×0=200), then stone 1 (100-10×1=90), then stone 3 (50-5×2=40). Total: 200+90+40=330.

Solution Hints
140
Points
3000ms
Time Limit
256MB
Memory Limit
Code Editor
Register to Submit
Register to Access Code Editor

Create a free account to solve coding problems and track your progress.

Register Now
Feedback