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 ...
- php:检测用户当前浏览器是否为IE浏览器
/** * 检测用户当前浏览器 * @return boolean 是否ie浏览器 */ function chk_ie_browser() { $userbrowser = $_SERVER['HT ...
- CheckBox控件实现选项的选中
1:设置控件属性 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xml ...
- Python之路Day15
主要内容:WEB框架.Django基础 WEB框架 Web请求流程 -- 原始Web框架 -- 自定义Web框架 -- MVC 和 MTV # Models Views Controllers # 模 ...
- [WPF疑难]如何禁用WPF窗口的系统菜单(SystemMenu)
原文 [WPF疑难]如何禁用WPF窗口的系统菜单(SystemMenu) [WPF疑难]如何禁用WPF窗口的系统菜单(SystemMenu) 周银辉 点击窗口左上角图标时弹出来的菜单也就是这里所说的系 ...
- pythonxy 安装
安装Numpy,发现错误: No module named msvccompiler in numpy.distutils; trying from distutils 目前python除了在 Win ...
- stackoverflow,stackexchange,zhihu,ilewen,segmentfault,answerhub,question2answer,,
http://stackexchange.com/ http://question2answer.org/ http://answerhub.com/qa/ http://segmentfault.c ...
- pod update --verbose --no-repo-update
最近使用CocoaPods来添加第三方类库,无论是执行pod install还是pod update都卡在了Analyzing dependencies不动 原因在于当执行以上两个命令的时候会升级Co ...
- C 语言统计关键字出现次数
#include <stdio.h> #include <ctype.h> #include <string.h> #define NKEYS (sizeof ke ...
- Android 5.0五大安全特性
全盘加密(Full Disk Encryption, FDE) 对所有闪存数据加密.性能下降较大 Nexus 6,Nexus 9无法关闭FDE 对于其它设备.Google推荐开启 多用户支持 4.2中 ...