This page is still under construction.

Parts of this page are still being built. What you see may change.

Conference - Rectification

Time limit1sMemory limit128 MB

Summary
Choose a subset of whole reservations to keep so that total income from ticket sales minus room rent is maximized.
Level

Hard8 of 10

Topics
Dynamic programming, Greedy, Brute force, Implementation
Solved
No attempts yet

Problem

You may recall the Great Bitonic Conference from the related "Conference" problem. Its organizers need your help once more.

The old registration system maximized the conference income by cancelling some already booked tickets, because fewer attendees means fewer rented rooms and therefore lower expenses. Attendees dislike this: a single reservation groups several tickets booked together, and the old system could cancel part of a reservation while keeping the rest. You must change the system so the income is still maximized, but a reservation may only be cancelled as a whole (either every ticket in it is kept, or every ticket in it is cancelled).

There are mm presentations. Every attendee of presentation ii pays the ticket price cic_i. The attendees of one presentation are seated in rooms that each hold kk people, and every rented room costs ss. If presentation ii keeps tt attendees, it needs ⌈t/k⌉\lceil t / k \rceil rooms and earns ci⋅t−s⋅⌈t/k⌉c_i \cdot t - s \cdot \lceil t / k \rceil. Presentations are independent of each other.

Write a program that reads the ticket prices, the room capacity, the room rental cost and the list of reservations, computes the largest total income obtainable when only whole reservations may be cancelled, and prints it.

Input

The first line contains four integers mm, ll, kk and ss (1≤m≤1001 \le m \le 100, 2≤l≤1 000 0002 \le l \le 1\,000\,000, 2≤k≤4002 \le k \le 400, 1≤s≤1 0001 \le s \le 1\,000), separated by single spaces: the number of presentations, the number of reservations, the capacity of one room, and the cost of renting one room.

The second line contains mm integers c1,c2,…,cmc_1, c_2, \ldots, c_m separated by single spaces, where cic_i is the ticket price of presentation ii. Each price satisfies ci≤sc_i \le s and ci⋅⌊k/2⌋≥sc_i \cdot \lfloor k / 2 \rfloor \ge s (so a room is already profitable once it is half full).

Each of the next ll lines describes one reservation by two integers pip_i and rir_i (1≤pi≤m1 \le p_i \le m, 1≤ri≤1 0001 \le r_i \le 1\,000) separated by a single space: the presentation number and the number of tickets booked in that reservation. A reservation may only be cancelled as a whole.

Output

Print a single integer: the largest total income that can be obtained by cancelling only whole reservations.

Examples4

  1. Example 1

    Input
    3 2 10 30
    7 10 8
    1 9
    3 13
    
    Expected output
    77
    
  2. Example 2

    Input
    1 4 10 30
    6
    1 10
    1 10
    1 10
    1 3
    
    Expected output
    90
    
  3. Example 3

    Input
    1 2 10 30
    6
    1 1
    1 1
    
    Expected output
    0
    
  4. Example 4

    Input
    1 5 10 30
    6
    1 10
    1 10
    1 10
    1 10
    1 2
    
    Expected output
    120