Mai intai trebuie sa te autentifici.
Cod sursa(job #1566531)
Utilizator | Data | 12 ianuarie 2016 11:19:36 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 0 |
Compilator | java | Status | done |
Runda | Arhiva educationala | Marime | 1.51 kb |
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ssm;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
/**
*
* @author Sorin
*/
class Ssm {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException, IOException {
// TODO code application logic here
File f=new File("ssm.in");
Scanner sc=new Scanner(f);
int dim=sc.nextInt();
int []v=new int[dim];
for (int i=0;i<dim;i++)
v[i]=sc.nextInt();
int [] l=new int[dim],p=new int[dim];
l[0]=v[0];
p[0]=0;
for (int i=1;i<dim;i++)
if (l[i-1]>0)
{
l[i]=v[i]+l[i-1];
p[i]=p[i-1];
}
else
{
l[i]=v[i];
p[i]=i;
}
int max=0,pt=0;
for (int i=0;i<dim;i++)
{
if (l[i]>max)
{
max=l[i];
pt=i;
}
}
FileWriter f2=new FileWriter("ssm.out");
PrintWriter writer=new PrintWriter(f2);
writer.printf("%d %d %d",max,p[pt]+1,pt+1);
writer.close();
}
}