Algorithm


A. Power Consumption Calculation
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes P3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into n time periods [l1, r1], [l2, r2], ..., [ln, rn]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [l1, rn].

Input

The first line contains 6 integer numbers nP1P2P3T1T2 (1 ≤ n ≤ 100, 0 ≤ P1, P2, P3 ≤ 100, 1 ≤ T1, T2 ≤ 60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0 ≤ li < ri ≤ 1440ri < li + 1 for i < n), which stand for the start and the end of the i-th period of work.

Output

Output the answer to the problem.

Examples
input
Copy
1 3 2 1 5 10
0 10
output
Copy
30
input
Copy
2 8 4 2 5 10
20 30
50 100
output
Copy
570

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <cstdio7gt;

int main(){

    int n(0), P1(0), P2(0), P3(0), T1(0), T2(0);
    scanf("%d %d %d %d %d %d", &n, &P1, &P2, &P3, &T1, &T2);

    long total(0), previousTime(-1);

    for(int k = 0; k < n; k++){

        int start(0), finish(0); scanf("%d %d", &start, &finish);
        if(previousTime < 0){previousTime = start;}
        total += P1 * (finish - start);

        int timeIdle = start - previousTime;
        if(timeIdle > T1 + T2){total += (timeIdle - T1 - T2) * P3; timeIdle = T1+ T2;}
        if(timeIdle > T1){total += (timeIdle - T1) * P2; timeIdle = T1;}
        total += timeIdle * P1;

        previousTime = finish;
    }

    printf("%ld\n", total);

    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
1 3 2 1 5 10
0 10

Output

x
+
cmd
30
Advertisements

Demonstration


COdeforces Solution-A. Power Consumption Calculation-Solution in C, C++, Java, Python

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+