#P6642. [CCO 2020] Exercise Deadlines
[CCO 2020] Exercise Deadlines
Description
There are tasks. Task must be finished before time .
Finishing one task takes only unit of time.
The current order is , but obviously, this order may fail to finish all tasks.
You may swap any pair of adjacent tasks to make it possible to finish all tasks.
For example: .
You need to output the minimum number of swaps needed, while ensuring that all tasks can be finished.
If it is impossible to finish all tasks no matter what, output -1.
Input Format
The first line contains an integer .
The second line contains integers .
Output Format
Output one integer on a single line: the minimum number of swaps needed to ensure all tasks can be finished.
If it is impossible no matter what, output -1.
4
4 4 3 2
3
3
1 1 3
-1
Hint
Sample Explanation
Sample 1 Explanation
One valid order is , which requires swaps.
Sample 2 Explanation
Obviously, you cannot do two tasks at the same time.
Subtasks
This problem uses bundled testdata.
- Subtask 1 ( points): .
- Subtask 1 ( points): no special restrictions.
For of the testdata, it is guaranteed that and .
Notes
This problem is translated from Canadian Computing Olympiad 2020 Day 1 T2 Exercise Deadlines.
Translated by ChatGPT 5
京公网安备 11011102002149号