Cod sursa(job #1322922)

Utilizator thehuntestshadowDragomir Alexandru thehuntestshadow Data 20 ianuarie 2015 15:26:37
Problema Secventa 2 Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
#include<iostream>
#include<fstream>
#include<string>
using namespace std;

int main ()
{
    int n,k;
    ifstream fin ("secv2.in");
    fin >> n>>k;
    int pos1,pos2=0,sum=0;
    
    int x,temp=0,c=0,o=0;
    for(int i=0;i<n;++i)
    {fin >> x;
    temp+=x;
    c++;
    if(temp>sum&&c>=k){
    pos1=o;sum=temp;pos2=i;}
    if(temp<0)
    {o=i+1;
    c=0;
    temp=0;
    } 
    }
    fin.close();
    ofstream fout ("secv2.out");
    fout << pos1 +1<< " "<< pos2+1 << " " << sum << "\n";
    fout.close();
    return 0;
    
    
    
}