Pagini recente » Cod sursa (job #2131650) | Rating Petre Andreea Cristina (angel_pac) | Cod sursa (job #143534) | Cod sursa (job #2522549) | Cod sursa (job #1486223)
#include <fstream>
#include <iostream>
#include <set>
using namespace std;
int main()
{
int N, K, i, maximum = -30001;
multiset<int> tree;
ifstream f("secventa.in");
f >> N >> K;
int a[N], lastIndex = 0, maxIndex = 0;
for (i = 0; i < N; i++)
f >> a[i];
f.close();
for (i = 0; i < N; i++)
{
tree.insert(a[i]);
if (tree.size() > K)
tree.erase(tree.find(a[lastIndex++]));
if (tree.size() == K && *tree.begin() > maximum)
maximum = *tree.begin(), maxIndex = lastIndex;
}
ofstream g("secventa.out");
g << maxIndex + 1 << " " << maxIndex + K << " " << maximum;
g.close();
return 0;
}