Codeforces 331A2 - Oh Sweet Beaverette (70 points)
贪心搞就行,用map记录每个数出现的下标,每次都取首尾两个。将中间权值为负的删掉后取sum值最大的就行。
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#define FF(i, a, b) for(int i=a; i<b; i++)
#define FD(i, a, b) for(int i=a; i>b; i--)
#define REP(i, n) for(int i=0; i<n; i++)
#define CLR(a, b) memset(a, b, sizeof(a))
#define LL long long using namespace std; const int maxn = 333333;
int n, a[maxn], l, r, k, ans[maxn];
LL s[maxn];
map<int, vector<int> > mp;
map<int, vector<int> > :: iterator it; int main()
{
while(~scanf("%d", &n))
{
s[0] = 0; mp.clear();
LL sum = -111111111111, tmp;
FF(i, 1, 1+n)
{
scanf("%d", &a[i]);
if(a[i] > 0) s[i] = s[i-1] + a[i];
else s[i] = s[i-1];
mp[a[i]].push_back(i);
}
for(it = mp.begin(); it != mp.end(); it++)
{
int nc = it->second.size();
if(nc >= 2)
{
tmp = s[it->second[nc-1]] - s[it->second[0]-1];
if(it->first < 0) tmp += it->first*2;
if(tmp > sum)
{
sum = tmp, l = it->second[0], r = it->second[nc-1];
}
}
}
k = 0;
FF(i, 1, l) ans[k++] = i;
FF(i, l+1, r) if(a[i] < 0) ans[k++] = i;
FF(i, r+1, n+1) ans[k++] = i;
printf("%I64d %d\n", sum, k);
REP(i, k) printf("%d ", ans[i]);
}
return 0;
}
Codeforces 331A2 - Oh Sweet Beaverette (70 points)的更多相关文章
- Codeforces Round #486 (Div. 3) D. Points and Powers of Two
Codeforces Round #486 (Div. 3) D. Points and Powers of Two 题目连接: http://codeforces.com/group/T0ITBvo ...
- Codeforces Round #319 (Div. 1) C. Points on Plane 分块
C. Points on Plane Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/576/pro ...
- Codeforces Round #466 (Div. 2) -A. Points on the line
2018-02-25 http://codeforces.com/contest/940/problem/A A. Points on the line time limit per test 1 s ...
- Codeforces Round #245 (Div. 2) A. Points and Segments (easy) 贪心
A. Points and Segments (easy) Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...
- Codeforces Round #245 (Div. 2) A - Points and Segments (easy)
水到家了 #include <iostream> #include <vector> #include <algorithm> using namespace st ...
- 构造 - Codeforces Round #319 (Div. 1)C. Points on Plane
Points on Plane Problem's Link Mean: 在二维坐标中给定n个点,求一条哈密顿通路. analyse: 一开始忽略了“无需保证路径最短”这个条件,一直在套最短哈密顿通路 ...
- Codeforces Round #501 (Div. 3) 1015A Points in Segments (前缀和)
A. Points in Segments time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #466 (Div. 2) A. Points on the line[数轴上有n个点,问最少去掉多少个点才能使剩下的点的最大距离为不超过k。]
A. Points on the line time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #319 (Div. 1)C. Points on Plane 分块思想
C. Points on Plane On a pl ...
随机推荐
- type,isinstance判断一个变量的数据类型
type,isinstance判断一个变量的数据类型 import types type(x) is types.IntType # 判断是否int 类型 type(x) is types.Strin ...
- AndroidStudio项目移植到Eclipse
原文件结构: 在AndroidStudio中 main目录对应eclipse中的src目录 可以看看每个文件夹下的目录 没有src或者main这些文件夹的都可以删掉 我这里只有app下的东西是需要留着 ...
- GTW likes math(简单数学)
GTW likes math Accepts: 472 Submissions: 2140 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- H面试程序(27):字串转换
//1 字串转换 //问题描述: //将输入的字符串(字符串仅包含小写字母‘a’到‘z’),按照如下规则,循环转换后输出:a->b,b->c,…,y->z,z->a: //若输 ...
- DevExpress ASP.NET 使用经验谈(4)-CriteriaOperator的使用
上一节中,我们已经介绍了,使用CriteriaOperator表达式,获取对象数据. CriteriaOperator criteria = CriteriaOperator.Parse(" ...
- 【转】CTE(公用表表达式)
本文转自:爽朗的微笑 http://www.cnblogs.com/shuangnet/archive/2013/03/22/2975929.html 公用表表达式 (CTE) 具有一个重要的优点, ...
- SQL中distinct的用法(转)
原文:http://www.cnblogs.com/rainman/archive/2013/05/03/3058451.html 在表中,可能会包含重复值.这并不成问题,不过,有时您也许希望仅仅列出 ...
- Map 的遍历
一.Map的遍历 在后面java的开发过程中会遇到Map类的使用,然而map的遍历是一大问题. Map遍历用两种比较交代的方法: package edu.map; import java.util.H ...
- 在Visual Studio中使用FFTW库
FFTW不用做过多介绍,一般都是在linux下使用,包括放出windows版的作者也自己声明:we don't use Windows ourselves 但是由于要和MIC混合编程,想先在本地使用, ...
- Usaco 2.3 Zero Sums(回溯DFS)--暴搜
Zero SumConsider the sequence of digits from 1 through N (where N=9) in increasing order: 1 2 3 ... ...