A1. Oh Sweet Beaverette

64 篇文章 0 订阅
53 篇文章 1 订阅

A1. Oh Sweet Beaverette

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

— Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me?

— Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night?

At this point the Smart Beaver got rushing. Everything should be perfect by Friday, so he needed to prepare the belt to the upcoming walk. He needed to cut down several trees.

Let's consider the woodland belt as a sequence of trees. Each tree i is described by the esthetic appeal ai — some trees are very esthetically pleasing, others are 'so-so', and some trees are positively ugly!

The Smart Beaver calculated that he needed the following effects to win the Beaverette's heart:

· The first objective is to please the Beaverette: the sum of esthetic appeal of the remaining trees must be maximum possible;

· the second objective is to surprise the Beaverette: the esthetic appeal of the first and the last trees in the resulting belt must be the same;

· and of course, the walk should be successful: there must be at least two trees in the woodland belt left.

Now help the Smart Beaver! Which trees does he need to cut down to win the Beaverette's heart?

Input

The first line contains a single integer n — the initial number of trees in the woodland belt, 2 ≤ n. The second line contains space-separated integers ai — the esthetic appeals of each tree. All esthetic appeals do not exceed 109 in their absolute value.

· to get 30 points, you need to solve the problem with constraints: n ≤ 100 (subproblem A1);

· to get 100 points, you need to solve the problem with constraints: n ≤ 3·105 (subproblems A1+A2).

Output

In the first line print two integers — the total esthetic appeal of the woodland belt after the Smart Beaver's intervention and the number of the cut down trees k.

In the next line print k integers — the numbers of the trees the Beaver needs to cut down. Assume that the trees are numbered from 1 to n from left to right.

If there are multiple solutions, print any of them. It is guaranteed that at least two trees have equal esthetic appeal.

Examples

input

5
1 2 3 1 2

output

8 1
1

input

5
1 -2 3 1 -2

output

5 2
2 5

 

题目大意:有很多有美丽值的树,要求求拥有最大美丽值和的一个区间且区间的头尾魅力值相同,同时要至少保留两个树,且输出砍掉的坐标

解题思路:首先求前缀和,把小于0的树跳过,然后用map去存每个魅力值存在的下标,重新再扫一遍,找到第一个坐标变化的,因为范围越大,值越大,前缀和跳过了负值,砍树的时候要判断选的头尾是否是正负,然后判一下,选好后扫一遍输出即可


#include<iostream>  
#include<cstdio>
#include<stdio.h>
#include<cstring>  
#include<cstdio>  
#include<climits>  
#include<cmath> 
#include<vector>
#include <bitset>
#include<algorithm>  
#include <queue>
#include<map>
using namespace std;
map<long long int, long long int> f;
int i, n, l, r, tot;
long long int ans, a[105], b[105], sum[105], x, y;
int main()
{
	cin >> n;
	if (n == 2)
	{
		cin >> x >> y;
		cout << x + y << " " << 0 << endl;
		return 0;
	}
	for (i = 1; i <= n; i++)
	{
		cin >> a[i];
		f[a[i]] = i;
	}
	
	if (a[1] > 0)
	{
		sum[1] = a[1];
	}
	else
	{
		sum[1] = 0;
	}
	for (i = 2; i <= n; i++)
	{
		if (a[i] > 0)
		{
			sum[i] = sum[i - 1] + a[i];
		}
		else
		{
			sum[i] = sum[i - 1];
		}
	}
	ans = -99999999999;
	for (i = 1; i <= n; i++)
	{
		if (f[a[i]] != i)
		{
			if (a[i] < 0)
			{
				if (ans <= (sum[f[a[i]]] - sum[i] + 2 * a[i]))
				{
					ans = sum[f[a[i]]] - sum[i] + 2 * a[i];
					l = i;
					r = f[a[i]];
				}
			}
			else
			{
				if (ans <= sum[f[a[i]]] - sum[i - 1])
				{
					ans = sum[f[a[i]]] - sum[i - 1];
					l = i;
					r = f[a[i]];
				}
			}
		}
	}
	tot = 0;
	for (i = 1; i <= n; i++)
	{
		if (i<l || i>r || i <= r&&r >= l&&a[i] < 0)
		{
			if ((l == i || r == i) && a[i] < 0)
			{
				continue;
			}
			b[++tot] = i;
		}
	}
	cout << ans << " " << tot << endl;
	for (i = 1; i <= tot; i++)
	{
		
		if (i == tot)
		{
			cout << b[i] << endl;
		}
		else {
			cout << b[i] << " ";
		}
	}
	
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值