Cod sursa(job #1290293)

Utilizator vladradu2014Radu Vlad Alexandru vladradu2014 Data 11 decembrie 2014 02:44:08
Problema Secventa Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.08 kb
// infoArena.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"

#include<iostream>
#include<vector>
#include<malloc.h>

using namespace std;

int min(int a, int b){ return(a < b) ? a : b; }

int main()
{
	long n, k,el;
	vector<int> secventa;
	freopen("secventa.in", "r", stdin);
	freopen("secventa.out", "w", stdout);
	cin >> n >> k;
	int**a = (int**)malloc(sizeof(int*)*(n + 1));
	for (int i = 1; i <= n; i++)
		a[i] = (int*)calloc(sizeof(int), (n - i + 1));

	for (int i = 0; i < n; i++)
	{
		cin>>el;
		secventa.push_back(el);
	}

	int maxI = 0;
	int maxJ = k-1;

	for (int x = 0; x <= n; x++)
	{
		int i = 1;
		int j = 1;

		while (j <= n)
		{  
			if (x == 0)
			{
				a[i][i] = secventa.at(i-1);
			}
			else
			{
				a[i][i + x] = min(a[i][i + x - 1], a[i + 1][i + x]);
			}
			if (x > k-2)
			{
				if (a[i][i + x] > a[maxI][maxJ])
				{
					maxI = i;
					maxJ = i + x;
				}
			}
			++i;
			j = i + x;
		}
	}
	

	cout << maxI << " " << maxJ << " " << a[maxI][maxJ] << endl;

	return 0;
}