F - Ilya Muromets-
来源:互联网 发布:mac安装jdk1.8教程 编辑:程序博客网 时间:2024/05/02 13:52
一开始算法就错了
错误地认为是 先找到一个max连续k区间 再找一个即可。。。。(这也太简单了吧)
实际是 要找到两个连续k区间的和最大。。两者是不同的。。。。让我发现区别的样例是这个
10 4
38 11 48 90 87 4 90 82 9 85
答案应该是 除去38 和4 之外的数只和
#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <algorithm>#include <iostream>#include <queue>#include <map>#include <list>#include <fstream>#include <vector>using namespace std;__int64 tm[2*100000+5]; __int64 big(__int64 a,__int64 b){if (a<b)return b;return a;}int main(){ __int64 n,k;scanf("%I64d %I64d",&n,&k);__int64 tmp;tm[0]=0;__int64 i;for (i=1;i<=n;i++){scanf("%I64d",&tmp);tm[i]+=tm[i-1]+tmp;} if (n<=2*k){printf("%I64d\n",tm[n]);return 0;} __int64 ans=tm[2*k];__int64 max=tm[k];for (i=k+1;i<=n-k;i++){max=big(max,tm[i]-tm[i-k]);ans=big(ans,tm[i+k]-tm[i]+max);}printf("%I64d\n",ans);return 0; }
0 0
- F - Ilya Muromets-
- Gym 100513F - Ilya Muromets
- CF - 100513F Ilya Muromets(dp)
- codeforces Ilya Muromets 2014 NEERC Southern Subregional Contest F dp
- 2014-2015 ACM-ICPC, NEERC, Southern Subregional Contest F. Ilya Muromets
- 2017寒假集训-小题训练1:F - Ilya and tic-tac-toe game
- f
- f
- f
- f
- f
- F#
- f
- F
- f
- f
- f
- f
- Delphi7学习第二天
- Oracle存储过程突然失效Invalid
- JAVA笔记之环境配置
- Codeforces Round #179 (Div. 2) C Greg and Array 两个线段树
- 关于学习的游泳的原理
- F - Ilya Muromets-
- URL中的保留和不安全字符
- 【算法】2015-2016 阿里、百度、360、豌豆荚、搜狗面试题部分集锦
- static
- leetcode之路004 Median of Two Sorted Arrays
- OC____about API
- 统计字符串第一个空字符前的字符长度
- 【YII2学习笔记】20150725-2
- 网络参数|数据解析