AtlassianOA #3
Planning Production
Estimated MediumJudge-ready
Topics (AI-labelled)Greedy
Before starting each product, cash must be at least its worst-case cost w, but only its expected cost e is actually deducted. Production can be arranged in any order; find the minimum initial cash needed to complete all products.
Input
The first line contains n, followed by n lines of w e. Complete original bounds: 1≤n≤100000, 1≤e≤w≤100000. Output an exact integer, not limited to 32 bits by the int in the original example signature.
Output
Output a single integer answer.
Example 1
Input:
2
5 1
4 3
Output:
5
Example 2
Input:
2
5 5
5 5
Output:
10
Example 3
Input:
1
1 1
Output:
1
Example notes
The outputs of the three public examples are, in order: 5; 10; 1. Verified by independent enumeration or direct simulation.
Editorial
Loading solution…