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].
The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1 ≤ n ≤ 100, 0 ≤ P1, P2, P3 ≤ 100, 1 ≤ T1, T2 ≤ 60). The following nlines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0 ≤ li < ri ≤ 1440, ri < li + 1 for i < n), which stand for the start and the end of the i-th period of work.
Output the answer to the problem.
1 3 2 1 5 10 0 10
30
2 8 4 2 5 10 20 30 50 100
570
题目有点长。最主要的一句是: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].
即是输入的时间段内电脑是正常模式下的,消耗为p1。时间段之间电脑是没人碰的。最后一次动作之后的T1分钟内还是正常模式,然后第T1分钟到第T1+T2分钟是消耗为p2的时间段,然后进入睡眠模式,消耗为p3。
java代码:
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int p1 = sc.nextInt();
int p2 = sc.nextInt();
int p3 = sc.nextInt();
int t1 = sc.nextInt();
int t2 = sc.nextInt();
int[] a = new int[n+1];
int[] b = new int[n+1];
int now = 0,x = 0,sum =0;
for(int i = 1;i <= n;i++){
a[i] = sc.nextInt();
b[i] = sc.nextInt();
if(x > 0){
now = a[i]-x;
if(now <= t1)
sum += now*p1;
else if(now <= t1+t2)
sum += t1*p1+(now-t1)*p2;
else
sum += t1*p1+t2*p2+(now-t1-t2)*p3;
}
now = b[i] - a[i];
sum += now*p1;
x = b[i];
}
System.out.println(sum);
}
}