Analyzing Contracts
Time limit1sMemory limit1024 MB
Clients are added with an end day and daily revenue, and each supplier query asks for the maximum profit from matching an available client to that supplier.
- Level
Hard8 of 10
- Topics
- Geometry, Segment tree, Divide and conquer
- Solved
- No attempts yet
Problem
Doctor Kruskal is starting a tiberium trading business. There are N possible suppliers of tiberium, and many clients want to receive tiberium to run their industries. Calendar days are numbered with positive integers, and each supplier is identified by a distinct integer from 1 to N. Supplier i can supply tiberium from day onwards, but not on earlier days. The supplier charges dollars per day. The list contains only the best suppliers in the city, so and for .
Input
The first line contains N (). Each of the next N lines contains and (). The next line contains Q (). Each of the next Q lines is either c E R (), which adds a client with end day E and daily revenue R to the database, or s I (), which asks for the maximum profit for supplier I. At least one operation of the second type appears.
Output
For each operation of type s, print one line with the maximum possible profit from matching an available client with the given supplier. Print the results in the order the operations appear in the input.