ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1126. Magnetic Storms

easy O(n log m) c++ 0.062 824кб
Posted by Viktor Krivoshchekov`~ 5 Jan 2019 16:36
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:16777216")
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <deque>
#include <stack>
#include <set>
#include <algorithm>
using namespace std;
int main()
{
    int m;
    cin >> m;
    vector<int> a;
    int k;
    cin >> k;
    while (k != -1) {
        a.push_back(k);
        cin >> k;
    }
    multiset<int> b;
    for (int i = 0; i < m; i++) {
        b.insert(a[i]);
    }
    cout << *(b.rbegin()) << '\n';
    b.erase(b.find(a[0]));
    for (int i = m; i < a.size(); i++) {
        b.insert(a[i]);
        cout << *(b.rbegin()) << '\n';
        b.erase(b.find(a[i + 1 - m]));
    }
    return 0;

}