当前位置:网站首页>Maximum continuous subsequence -- daily question
Maximum continuous subsequence -- daily question
2022-07-23 06:18:00 【Like a few dollars】
Given KK A sequence of integers {N0,N1,…,NK−1}{N0,N1,…,NK−1}, Its arbitrary continuous subsequence can be expressed as {Ni,Ni+1,…,Nj}{Ni,Ni+1,…,Nj}, among 0≤i≤j<K0≤i≤j<K.
The largest continuous subsequence is the largest sum of all the elements in the continuous subsequence , For example, given a sequence {−2,11,−4,13,−5,−2}{−2,11,−4,13,−5,−2}, The maximum continuous subsequence is {11,−4,13}{11,−4,13} , The largest sum is 2020.
Write a program to get the sum of the largest subsequence and output the subscripts of the first and last elements of the subsequence .
Input format
Input contains multiple sets of test data .
The percentage of data in each group 22 That's ok , The first 11 Line gives a positive integer KK.
The first 22 Line is given KK It's an integer N1,…,NKN1,…,NK.
Output format
Output a row of results for each group of data , Contains the sum of the largest subsequence and the first subscript of the subsequence ii And the subscript of the last element jj.
All elements are subscripted 0∼K−10∼K−1.
If the largest subsequence is not unique , select ii The smallest subsequence , If it's still not unique , select ii In the smallest subsequence jj The smallest subsequence .
If all KK Both elements are negative numbers , Then its maximum sum is defined as 00, Output
0 0 0.Data range
1≤K≤1051≤K≤105,
−10000≤Ni≤10000−10000≤Ni≤10000,
The input can contain at most 1010 Group data .sample input :
8 6 -2 11 -4 13 -5 -2 10 5 10 -10 10 -10 10 8 -1 -5 -2 3 -1 0 -2 0 4 -1 -2 -4 -3sample output :
27 0 7 10 0 0 3 3 3 0 0 0
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=100010;
int w[N];
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=0;i<n;i++) cin>>w[i];
int res=0,left=0,right=0,f=0,g=0;
for(int i=n-1;i>=0;i--)
{
if(f<=0)
{
f=0;
g=i;
}
f+=w[i];
if(f>=res)
{
res=f;
left=i;
right=g;
}
}
cout<<res<<" "<<left<<" "<<right<<endl;
}
return 0;
}2022/7/19
边栏推荐
- Transformer
- 1.从键盘上输入一个百分制成绩score,按下列原则输出其等级:score≥90,等级为A;80≤score<90,等级为B;70≤score<80,等级为C;60≤score<70,等级为D;sco
- Sentence Bert + Milvus to realize intelligent question answering system
- 7. 求100~300间能被3整除的数的和。
- Solution of cross domain problems
- 2019 Bar _ Aaai ICCN
- 栈溢出基础练习题——6(字符串漏洞64位下)
- Saisissez une chaîne de caractères à partir du clavier et affichez différents caractères et le nombre d'occurrences de chaque caractère. (la sortie n'est pas séquentielle) résoudre le problème en util
- pwn ——ret2libc3
- pwn1_ sctf_ two thousand and sixteen
猜你喜欢

Introduction to 51 single chip microcomputer (dedicated to the most understandable article for beginners) update

30出头成为复旦博导,陈思明:敲代码和写诗,我两样都要

Saisissez une chaîne de caractères à partir du clavier et affichez différents caractères et le nombre d'occurrences de chaque caractère. (la sortie n'est pas séquentielle) résoudre le problème en util

中国电子信息产业发展研究院院长张立:打造我国主导的开源价值链

初学者备战蓝桥杯历程(大学编程学习历程记录,题目思路献给需要备考蓝桥杯的同学)

ROPgadget初识 ——— ret2syscall

攻防世界 —— hacknote

Stack overflow basic exercise - 5 (string vulnerability)

2020_ ACL_ A Transformer-based joint-encoding for Emotion Recognition and Sentiment Analysis

栈溢出基础练习题——3 (内有32和64位区别的对比)
随机推荐
接口文档进化图鉴, 用过第一款接口文档工具的人暴露年龄了
centos7安装和卸载mysql5.7
hcip--复习第二天作业
影響接口查詢速度的情况
13. 编写程序,其中自定义一函数,用来判断一个整数是否为素数,主函数输入一个数,输出是否为素数。
栈溢出基础练习题——5(字符串漏洞)
[强网杯 2019]随便注
NLP-语言模型
Theoretical basis of machine learning
最大连续子序列--每日一题
2019_ACL_Multimodal Transformer for Unaligned Multimodal Language Sequences
Saisissez une chaîne de caractères à partir du clavier et affichez différents caractères et le nombre d'occurrences de chaque caractère. (la sortie n'est pas séquentielle) résoudre le problème en util
中国电子信息产业发展研究院院长张立:打造我国主导的开源价值链
Transformer
ESP IDF vscode configuration from downloading tool chain to creating project, step record
PWN stack overflow basic exercise - 2
BUUCTF 杂项——二维码
Encoder decoder (seq2seq)
1.从键盘上输入一个百分制成绩score,按下列原则输出其等级:score≥90,等级为A;80≤score<90,等级为B;70≤score<80,等级为C;60≤score<70,等级为D;sco
Buuctf miscellaneous - QR code