贪心搞就行,用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)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. Codeforces Round #245 (Div. 2) A - Points and Segments (easy)

    水到家了 #include <iostream> #include <vector> #include <algorithm> using namespace st ...

  6. 构造 - Codeforces Round #319 (Div. 1)C. Points on Plane

    Points on Plane Problem's Link Mean: 在二维坐标中给定n个点,求一条哈密顿通路. analyse: 一开始忽略了“无需保证路径最短”这个条件,一直在套最短哈密顿通路 ...

  7. 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 ...

  8. 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 ...

  9. Codeforces Round #319 (Div. 1)C. Points on Plane 分块思想

                                                                              C. Points on Plane On a pl ...

随机推荐

  1. 基于Visual C++2013拆解世界五百强面试题--题5-自己实现strstr

    请用C语言实现字符串的查找函数strstr, 找到则返回子字符串的地址,没有找到返回为空,请用数组操作与指针操作实现 看到题目想到最简单的方法就是母字符串和子字符串比较,如果不同,将指向母字符串的指针 ...

  2. ajax 中文乱码

     ajax 中文乱码  Firefox 正常,IE 有问题是 解决办法 data:{"name":name,"number":number,"card ...

  3. poj 2503 Babelfish(Map、Hash、字典树)

    题目链接:http://poj.org/bbs?problem_id=2503 思路分析: 题目数据数据量为10^5, 为查找问题,使用Hash或Map等查找树可以解决,也可以使用字典树查找. 代码( ...

  4. CTreeCtrl 控件使用总结

    一 基础操作  1 插入节点 1)插入根节点 [cpp] view plaincopy //插入根节点 HTREEITEM hRoot; CString str=L"ROOT" h ...

  5. delphi webbrowser 经常用法演示样例

    var Form : IHTMLFormElement ; D:IHTMLDocument2 ; begin with WebBrowser1 do begin D := Document as IH ...

  6. golang(2):beego 环境搭建

    本文的原文连接是: http://blog.csdn.net/freewebsys/article/details/46695513 转载请一定注明出处. 1,关于beego beego是一个用Go开 ...

  7. css精灵(css script 技术)

    上班差不多有15天了,感觉每天都有写不完的也页面,每天都有不同的东西需要学习进步,很充实哦.今天接触到css精灵这个东西.其实之前有看过这种技术,但是没有操作过,只是听说这个技术很强大,能干嘛干嘛,但 ...

  8. SharePoint将网站另存为模板

    1.将网站另存为模板 参考文章 http://blog.csdn.net/dyp330/article/details/23180843 http://blog.163.com/berlin1989@ ...

  9. Java多线程之synchronized(一)

    在上节中已经说过了“非线程安全”是如何出现的,链接如下:http://www.cnblogs.com/chentong/p/5650137.html,那么怎么解决“非线程安全”问题呢,只需要在两个线程 ...

  10. iOS推送证书p12转成pem

    首先你需要导出p12格式的证书,具体操作请参考如下: 其次你就可以通过在控制台输入如下命令即可转换: openssl pkcs12 -in 你导出的p12证书 -out 你要转换的pem证书 -nod ...