Codeforces Beta Round #10

A - Power Consumption Calculation

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 n, P1, P2, P3, T1, T2 (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 ≤ 1440, ri < 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

1 3 2 1 5 10
0 10

Output

30

Input

2 8 4 2 5 10
20 30
50 100

Output

570

模拟题,先把使用电脑时段的能耗计算出来,再分别计算不使用的时段。

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;

pair<int, int> arr[105];

int main(void)
{
	int n, p1, p2, p3, t1, t2;
	int ans = 0, time;
	scanf("%d%d%d%d%d%d", &n, &p1, &p2, &p3, &t1, &t2);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d%d", &arr[i].first, &arr[i].second);
		ans += (arr[i].second - arr[i].first) * p1;
	}
	for (int i = 1; i < n ;i++)
	{
		time = arr[i + 1].first - arr[i].second;
		if (time <= t1)
			ans += time * p1;
		else if (time <= t1 + t2)
		{
			ans += t1 * p1;
			ans += (time - t1) * p2;
		}
		else
		{
			ans += t1 * p1;
			ans += t2 * p2;
			ans += (time - t1 - t2) * p3;
		}
	}
	printf("%d\n", ans);
	return 0;
}

D - LCIS

This problem differs from one which was on the online contest.

The sequence a1, a2, …, an is called increasing, if ai < ai + 1 for i < n.

The sequence s1, s2, …, sk is called the subsequence of the sequence a1, a2, …, an, if there exist such a set of indexes 1 ≤ i1 < i2 < … < ik ≤ n that aij = sj. In other words, the sequence s can be derived from the sequence a by crossing out some elements.

You are given two sequences of integer numbers. You are to find their longest common increasing subsequence, i.e. an increasing sequence of maximum length that is the subsequence of both sequences.

Input

The first line contains an integer n (1 ≤ n ≤ 500) — the length of the first sequence. The second line contains n space-separated integers from the range [0, 109] — elements of the first sequence. The third line contains an integer m (1 ≤ m ≤ 500) — the length of the second sequence. The fourth line contains m space-separated integers from the range [0, 109] — elements of the second sequence.

Output

In the first line output k — the length of the longest common increasing subsequence. In the second line output the subsequence itself. Separate the elements with a space. If there are several solutions, output any.

Examples

Input

7
2 3 1 6 5 4 6
4
1 3 5 6

Output

3
3 5 6

Input

5
1 2 0 2 1
3
1 0 1

Output

2
0 1

最长公共上升子序列 + 路径记录。
一开始做这道题时,我的思路有一些问题,但又不想改成其他的思路,突然在网上找到一篇跟我思路一模一样的题解,太高兴了。

一位大佬的题解:https://www.cnblogs.com/yohaha/p/5276748.html

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

const int N = 505;
int a[N], b[N], f[N];
int last[N], path[N];
int n, m;

int main(void)
{
    cin >> n;
    for (int i = 1; i <= n; i++) 
		cin >> a[i];
    cin >> m;
    for (int i = 1; i <= m; i++) 
		cin >> b[i];
		
    for (int i = 1; i <= n; i++)
	{
        int maxv = 0;   //前边最多有多少个满足b[j]<a[i]的
        for (int j = 1; j <= m; j++)
		{
            if (a[i] == b[j] && f[j] < f[maxv] + 1) 
			{
				f[j] = f[maxv] + 1; //更新答案
				last[j] = maxv;
			}

            if (b[j] < a[i] && f[j] > f[maxv]) 
				maxv = j;//更新maxv
        }
    }

    int res = 0, k = 0;
    for (int i = 1; i <= m; i++) 
	{
		if (res < f[i])
		{
			res = f[i];
			k = i;
		} 
	}
	cout << res << endl;
	int idx = 0;
	for (int i = k; i; i = last[i])
		path[idx++] = b[i];
	for (int i = idx - 1; i >= 0; i--)
		cout << path[i] << " ";
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值