Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma warning (disable : 4996)
- #pragma comment(linker, "/STACK:36777216")
- #include <stdlib.h>
- #include <iostream>
- #include <vector>
- #include <string>
- #include <assert.h>
- #include <stack>
- #include <algorithm>
- #include <ios>
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- #include <queue>
- #include <set>
- #include <functional>
- #include <cmath>
- #include <sstream>
- #include <map>
- #include <memory.h>
- #include <stdio.h>
- #include <cassert>
- #include <string.h>
- #include <deque>
- #include <ctime>
- #include <list>
- #include <unordered_set>
- #include <unordered_map>
- #include <limits>
- #define forn(i , n) for (int i = 0; i < n; ++i)
- #define down(i, n) for (int i = (n) - 1; i >= 0; --i)
- using namespace std;
- typedef unsigned long long int u64;
- typedef long long int i64;
- typedef vector<int> vint;
- typedef vector<i64> vi64;
- typedef pair<int, int> pint;
- typedef pair<i64, i64> pi64;
- #define FILE_NAME "file"
- #define CONTEST "hard"
- #define M_PI 3.14159265358979323846
- #define ALL(a) (a).begin(), (a).end()
- #define N 100000000
- int main()
- {
- clock_t start = clock();
- srand(13);
- srand(start);
- cout << fixed << setprecision(10);
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- #ifdef FILE_INPUT
- freopen("file.in", "r", stdin);
- freopen("file.out", "w", stdout);
- #endif // FILE_INPUT
- unsigned k;
- cin >> k;
- int currAnswer = INT_MIN;
- set<int> s; // red-black tree https://en.cppreference.com/w/cpp/container/set.
- while (!cin.eof()) // enf of stream.
- {
- int c;
- cin >> c;
- if (c < currAnswer && s.size() == k)
- {
- // do nothing, O(1).
- }
- else
- {
- s.insert(c); // O(ln(n));
- if (s.size() > k)
- {
- auto currMin = s.begin(); // O(ln(n));
- s.erase(currMin); // O(ln(n));
- }
- // if (s.size() == k) it depends on what you want to see before you have k elements.
- currAnswer = *s.begin(); // min element of the set, O(ln(n));
- }
- cout << currAnswer << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement