AmazonOA #72
Get Maximum Cost (Subscription Plan)
Estimated MediumJudge-ready
Topics (AI-labelled)HashingGreedyStacks & Heaps
Choose one plan and one feature; the given incompatible index pairs cannot be chosen. At least one compatible combination exists; find the maximum total price.
Input
The first line contains n m X; 2≤n,m≤100000, 1≤X≤min(200000,nm−1); then two lines of price arrays (1..10⁹); followed by X lines of incompatible pairs, numbered from 1.
Output
Output a single integer answer.
Example 1
Input:
2 2 1
5 8
4 7
2 2
Output:
12
Example 2
Input:
2 2 3
1 2
3 4
1 1
1 2
2 1
Output:
6
Example 3
Input:
2 2 1
9 1
8 1
2 2
Output:
17
Example notes
Example 1: 8+4 and 5+7 both give 12; 8+7 is forbidden. Example 2: only plan 2 and feature 2 can be paired, for a total price of 6. Example 3: the highest pair 9+8 is allowed, for a total price of 17.
Editorial
Loading solution…