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 ...
随机推荐
- mfc添加气球式提示栏
// TOOLTIPWND.H 添加气球式提示栏 #if !defined(AFX_TOOLTIPWND_H__2C52D3E4_2F5B_11D2_8FC9_000000000000__IN ...
- HDU 1348 Wall
题解:计算凸包周长 #include <iostream> #include <cmath> #include <algorithm> const int size ...
- poj 2593 Max Sequence(线性dp)
题目链接:http://poj.org/problem?id=2593 思路分析:该问题为求给定由N个整数组成的序列,要求确定序列A的2个不相交子段,使这m个子段的最大连续子段和的和最大. 该问题与p ...
- http://qt-project.org/wiki/Category:Developing_with_Qt::QtWebKit#ff7c0fcd6a31e735a61c001f75426961
404: Not Found | Qt Project QtWebKit documentation http://dwz.cn/hr2013
- 过河(bfs)
Problem 2188 过河I Accept: 112 Submit: 277 Time Limit: 3000 mSec Memory Limit : 32768 KB Proble ...
- IT忍者神龟之Struts2.xml配置全然正确流程能走通可是有红叉解决
一:Multiple annotations found at this line:Undefined actionName parameter Undefined actionnamespace ...
- poj1201 Intervals【差分约束+SPFA】
转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4303365.html ---by 墨染之樱花 题目链接:http://poj.org/pr ...
- 融合python2和python3
很多情况下你可能会想要开发一个程序能同时在python2和python3中运行. 想象一下你开发了一个模块,成百上千的人都在使用它,但不是所有的用户都同时使用python 2和3.这种情况下你有两个选 ...
- Javabean的理解
1.Javabean是指满足指定规则的Java类.满足的规则由Sun公司提出,如x,setX,getX等规范,public无参构造函数等 2.Javabean其实也是一种规范.
- PreTranslateMessage和TranslateMessage区别(转)
PreTranslateMessage是消息在送给TranslateMessage函数之前被调用的,绝大多数本窗口的消息都要通过这里,比较常用,当需要在MFC之前处理某些消息时,常常要在这里添加代码. ...