Pagini recente » Cod sursa (job #193089) | Cod sursa (job #1008024) | Cod sursa (job #201210) | Cod sursa (job #2729076) | Cod sursa (job #1569107)
/*
* 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 javaapplication4;
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 Dan
*/
class JavaApplication4 {
/**
* @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 n=sc.nextInt();
int []a=new int[n];
int []v=new int[n];
for (int i=0;i<n;++i)
a[i]=sc.nextInt();
int max=a[0];
v[0]=a[0];
int j=0;
for(int i=1;i<n;++i)
{
v[i]=a[i];
if(v[i]<v[i-1]+a[i])
v[i]=v[i-1]+a[i];
if(v[i]>max)
{max=v[i];
j=i;
}
}
int k;
int max1=max;
k=j;
while(max1>0)
{
max1=max1-a[k];
if(max1>0)
k--;
}
FileWriter f2=new FileWriter("ssm.out");
try (PrintWriter writer = new PrintWriter(f2)) {
writer.printf("%d %d %d",max,k+1,j+1);
}
}
}