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 ...
随机推荐
- MVC 优缺点
MVC是一个架构,或者说是一个设计模式,它就是强制性使应用程序的输入,处理和输出分开.将一个应用程序分为三个部分:Model,View,Controller. 1. MVC的优点 (1) 可以为一个模 ...
- 基于Visual C++2013拆解世界五百强面试题--题5-自己实现strstr
请用C语言实现字符串的查找函数strstr, 找到则返回子字符串的地址,没有找到返回为空,请用数组操作与指针操作实现 看到题目想到最简单的方法就是母字符串和子字符串比较,如果不同,将指向母字符串的指针 ...
- live555 RTSP服务器建立及消息处理流程
DynamicRTSPServer::creatnew(): 1.调用继承自RTPSever::setUpOurSocket: 1.调用 GroupsockHelper 的 set ...
- 搞不清FastCgi与PHP-fpm之间是个什么样的关系 - SegmentFault
搞不清FastCgi与PHP-fpm之间是个什么样的关系 - SegmentFault 搞不清FastCgi与PHP-fpm之间是个什么样的关系 3赞 踩 收藏 我在网上查fastcgi与php-fp ...
- Scrambled Polygon(凸多边形,斜率)
Scrambled Polygon Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 7805 Accepted: 3712 ...
- Android开发之TextView高级应用
Android开发之TextView高级应用 我们平时使用TextView往往让它作为一个显示文字的容器,但TextView的功能并不局限于此.以下就和大家分享一下TextView的一些使用技巧. A ...
- HDU1325 &&poj1308 基础并查集
和上一道小希的迷宫差点儿相同,可是在HDU上提交一直WA,POJ过了 HDU的数据太强了吧,强的我感觉数据有问题 题意:输入若干对点,推断是否是一颗树,转化过来也就是是否存在环 点数-边数=1,还要推 ...
- Unity 对象池 生产 保存
Unity对象池主要是保存那些常用的物体,避免他们在不断销毁和创造中损坏性能. 主要思路为:创造物体时,判断是否存在,如果存在则调用并使其显示.如果不存在则创造一个新的. 当销毁时,调用协程延时隐藏物 ...
- js 获取单项复选的值
html: 单选框-----> 25岁以下 25~35岁 35~50岁 50岁以上 获值 var question1 = $('input:radio[name="radio" ...
- MVCC 多版本并发控制
关于事务的介绍暂且不谈. InnoDB行级锁,虽然在很大程度上提高了事务的并发性,但是终究还是要耗费很大的.为了更进一步的提高并发性同时降低开销,存储引擎会同时实现MVCC. InnoDB实现MVCC ...