2015 Bestcoder 47# A

Senior‘s Array

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 514    Accepted Submission(s): 199

Problem Description

One day, Xuejiejie gets an array A.
Among all non-empty intervals of A,
she wants to find the most beautiful one. She defines the beauty as the sum of the interval. The beauty of the interval---[L,R] is
calculated by this formula : beauty(L,R) = A[L]+A[L+1]+……+A[R].
The most beautiful interval is the one with maximum beauty.

But as is known to all, Xuejiejie is used to pursuing perfection. She wants to get a more beautiful interval. So she asks Mini-Sun for help. Mini-Sun is a magician, but he is busy reviewing calculus. So he tells Xuejiejie that he can just help her change one
value of the element of A to P .
Xuejiejie plans to come to see him in tomorrow morning.

Unluckily, Xuejiejie oversleeps. Now up to you to help her make the decision which one should be changed(You must change one element).

Input

In the first line there is an integer T,
indicates the number of test cases.

In each case, the first line contains two integers n and P. n means
the number of elements of the array. P means
the value Mini-Sun can change to.

The next line contains the original array.

1≤n≤1000, ?109≤A[i],P≤109。

Output

For each test case, output one integer which means the most beautiful interval‘s beauty after your change.

Sample Input

2
3 5
1 -1 2
3 -2
1 -1 2

Sample Output

8
2

Source

BestCoder Round #47 ($)

Recommend

hujie   |   We have carefully selected several similar problems for you:  5283 5282 5281 5279 5278

题意:给你一个数值 改变数值中某个元素的值(a[i] = p)求改变后数组的最大子串和 必须改

思路:就是数据比较坑 如果不用__int64会被heck掉

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
__int64 a[1005];
__int64 sum[1005];
__int64 ssum[1005];

int main()
{
    __int64  t;
    scanf("%I64d",&t);
    while(t--)
    {
        __int64 n,p;
        scanf("%I64d%I64d",&n,&p);
        a[0] = 0;
        sum[0] = 0;

        __int64 Mx=-999999999;

        for(__int64 i = 0; i < n; i++)
            scanf("%I64d",&a[i]);

        for(__int64 i = 0; i < n; i++)
        {
            __int64 tp = a[i];
            a[i] = p;
             for (__int64 j = 0;j < n;j++)
            {
                if (j)
                sum[j] = a[j] > sum[j-1]+a[j] ? a[j] : sum[j-1]+a[j];
                else
                    sum[j]=a[j];
                if (sum[j]>Mx)
                    Mx=sum[j];
//                cout<<sum[j]<<endl;
            }
            a[i] = tp;
        }
        printf("%I64d\n",Mx);
    }
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2025-01-02 03:20:10

2015 Bestcoder 47# A的相关文章

Bestcoder #47 B Senior&#39;s Gun

Senior's Gun Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 875    Accepted Submission(s): 319 Problem Description Xuejiejie is a beautiful and charming sharpshooter. She often carries n guns,

BestCoder #47 1001&amp;amp;&amp;amp;1002

[比赛链接]clikc here~~ ps:真是wuyu~~做了两小时.A出两道题,最后由于没加longlong所有被别人hack掉!,最后竟然不知道hack别人不成功也会掉分.还一个劲的hack 别人的代码,昨天真是个悲催的比赛,~~~~(>_<)~~~~,以下弱弱献上代码~~ 1002比1001还简单~~ 1002  Senior's Gun /* BestCoder Round #47 1002 Senior's Gun */ #include <iostream> #inc

BestCoder #47 1001&amp;&amp;1002

[比赛链接]clikc here~~ ps:真是wuyu~~做了两小时,A出两道题,最后因为没加longlong全部被别人hack掉!,最后居然不知道hack别人不成功也会掉分,还一个劲的hack 别人的代码,昨天真是个悲催的比赛,~~~~(>_<)~~~~,下面弱弱献上代码~~ 1002比1001还简单~~ 1002  Senior's Gun /* BestCoder Round #47 1002 Senior's Gun */ #include <iostream> #inc

bestcoder 47# wyh2000 and a string problem (水题)

wyh2000 and a string problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 484    Accepted Submission(s): 232 Problem Description Young theoretical computer scientist wyh2000 is teaching you

2015第47周三

保持收集信息的习惯.一是善于利用网络收集需要的信息.二是善于从身边的各个圈子获取信息.即使你不善于社交,或者不愿意在社交上投入过多时间,你可以选择在各个圈子结交一两个人,或者打入他们组织的沟通渠道,每天抽一点时间快速筛选出有用信息. 人脉的实质是人情的消耗和利益的交换,提高自己比广泛社交更高效.半衰期更长.认识的人多,不代表人脉广,能对你产生价值的,才叫人脉.要让别人为你产生价值,要么是你们之间的情分足够,要么是你本身有价值因而值得别人的投资.前者,一个正常人只能维持在个位数.后者,才是真正没有

rman异机恢复

rman异机恢复 注意事项: 1.源数据库与目标数据库的目录结构相同 2.目标数据库只需要安装ORACLE软件(但是参数文件中指定的目录要创建) 3.要将源数据库的数据文件,参数文件,控制文件,密码文件,归档日志统统备份 1.源数据库备份 参数文件与控制文件自动备份 CONFIGURE CONTROLFILE AUTOBACKUP ON; CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/home/oracle/r

Bean自动装配-XML最小化配置

上一个讲了怎样用xml配置所有的Bean以及进行依赖注入,但是这样太麻烦了,对于每一个bean都要写一个xml,可以有几种方式进行自动装配. 四种装配方式 byName(通过名字装配,这时属性的名字必须与bean名字一致) byType(通过类型,匹配与interface或class相同的类型),这种是找到对应的方法,然后进行setter方法进行注入的 constructor(也是通过类型匹配,但是是通过new的进行装配的) 最佳自动装配(先用constructor装配,然后再用byType)

JAVA基础学习day25--Socket基础二-多线程

一.上传图片 1.1.示例 /* 上传图片 */ import java.net.*; import java.io.*; import java.util.*; import java.text.*; /* 客户端 1.建立客户端服务 2.读取客户端已经有数据,,将文件名发送给服务端 3.通过Scoket,输出流将数据发送给服务端 4.接收服务端返回信息 5.关流Socket和流资源 */ class UploadClient1 { public static void main(String

Kernel compiling for Pi 2

https://www.raspberrypi.org/forums/viewtopic.php?f=66&t=101188&p=807579&hilit=cross+compile+pi+source+code#p807579 by Seabug » Sat Feb 21, 2015 4:20 pm Hi, I am trying to compile the Raspbian kernel for my new Pi 2 ( I need support for ELO / E