Pagini recente » Cod sursa (job #2796303) | Cod sursa (job #1990111) | Cod sursa (job #800185) | Cod sursa (job #1673928) | Cod sursa (job #2647807)
// InfoArena.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <fstream>
using namespace std;
//ifstream f("secv2.in");
//ofstream out("secv2.out");
int main()
{
int v[50000];
unsigned short int N, K , first_position = 0, last_position = 0;
int suma_2 = 0, suma= 0;
bool all_positive = true;
cin >> N;
cin >> K;
for (int i = 1; i <= N; i++) {
cin >> v[i];
suma += v[i];
if (i == 1)
for (int h = i; h <= K; h++)
suma_2 += v[h];
if (v[i] < 0)
all_positive = false;
if (all_positive && i == N) {
cout << 1 << " " << N << " " << suma;
return 0;
}
}
for (int i = K; i <= N; i++) {
for (int b = 1; b <= N; b++) {
int suma_1 = 0;
for (int h = 0; h <= i-1; h++)
suma_1 += v[b + h];
if (suma_2 < suma_1) {
suma_2 = suma_1;
for (int k_1 = 1; k_1 <= i; k_1++) {
if (k_1 == 1)
first_position = b;
if (k_1 == i)
last_position = b + (k_1-1);
}
}
if (b == 1 + (N - i))
break;
cout << suma_1 << " < " << suma_2 << endl;
}
}
cout << first_position << " " << last_position << " " << suma_2;
}