PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000027. Bài toán người thợ giày (Shoemaker's Problem)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Bài toán người thợ giày (Shoemaker's Problem)
Shoemaker's Problem
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
There are jobs. Job takes days and incurs a penalty of for each day before completion. Only one job can be processed at a time. Output an order minimizing the total penalty.
Input
The first line contains . Each of the next lines contains . Jobs are numbered from .
Output
Print an optimal order of job indices; if multiple orders are optimal, prefer smaller indices first.
Constraints
- .
- for .
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): Full constraints.
Examples
Input
4
3 4
1 1000
2 2
5 5
Output
2 1 3 4
Explanation
The sample follows the ordering rule described in the Vietnamese explanation and produces the shown optimum.