diff --git a/Data Structure 2/11286.cpp b/Data Structure 2/11286.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5035ae0bff8ec1d59023e8f0de543b64c48491bd --- /dev/null +++ b/Data Structure 2/11286.cpp @@ -0,0 +1,69 @@ +#include<iostream> +#include<queue> +using namespace std; + +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + int N; + cin >> N; + + priority_queue<int, vector<int>, greater<int>> plus; + priority_queue<int, vector<int>, less<int>> minus; + + for(int i=0;i<N;i++) + { + int x; + cin >> x; + + if(x == 0) + { + if(plus.empty() && minus.empty()) + { + cout << 0 << "\n"; + } + else if(plus.empty() && !minus.empty()) + { + cout << minus.top() << "\n"; + minus.pop(); + } + else if(!plus.empty() && minus.empty()) + { + cout << plus.top() << "\n"; + plus.pop(); + } + else + { + int p_top = plus.top(); + int m_top = minus.top(); + if(p_top == -1 * m_top) + { + cout << m_top << "\n"; + minus.pop(); + } + else if(p_top > -1 * m_top) + { + cout << m_top << "\n"; + minus.pop(); + } + else + { + cout << p_top << "\n"; + plus.pop(); + } + } + + } + else if(x > 0) + { + plus.push(x); + } + else + { + minus.push(x); + } + } +} \ No newline at end of file diff --git a/Data Structure 2/4358.cpp b/Data Structure 2/4358.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bcc55a38975d89db61a90d8c04226aafacf08ca5 --- /dev/null +++ b/Data Structure 2/4358.cpp @@ -0,0 +1,29 @@ +#include<iostream> +#include<string> +#include<map> +using namespace std; + +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + int cnt=0; + map<string, int> m; + string input; + + while(getline(cin, input)) + { + m[input]++; + cnt++; + } + + cout << fixed; + cout.precision(4); + + for(auto i:m) + { + cout << i.first << " " << (double) i.second * 100 / cnt << endl; + } +} \ No newline at end of file diff --git a/Data Structure 2/7662.cpp b/Data Structure 2/7662.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c6957f536e5e22f322a1d92d5eceefd2af668232 --- /dev/null +++ b/Data Structure 2/7662.cpp @@ -0,0 +1,78 @@ +#include<iostream> +#include<vector> +#include<queue> +#include<map> +using namespace std; + +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + int T; + cin >> T; + while(T--) + { + map<int, int> m; + priority_queue<int, vector<int>, greater<int>> min_heap; + priority_queue<int, vector<int>, less<int>> max_heap; + + int K; + cin >> K; + + while(K--) + { + int n; + char op; + + cin >> op >> n; + + if(op =='D') + { + if(n == 1) + { + while(!max_heap.empty() && m[max_heap.top()] == 0) + max_heap.pop(); + + if(max_heap.empty()) + continue; + else + { + m[max_heap.top()]--; + max_heap.pop(); + } + } + else + { + while(!min_heap.empty() && m[min_heap.top()] == 0) + min_heap.pop(); + + if(min_heap.empty()) + continue; + else + { + m[min_heap.top()]--; + min_heap.pop(); + } + } + } + else + { + max_heap.push(n); + min_heap.push(n); + m[n]++; + } + + while(!max_heap.empty() && m[max_heap.top()] == 0) + max_heap.pop(); + while(!min_heap.empty() && m[min_heap.top()] == 0) + min_heap.pop(); + } + + if(max_heap.empty()) + cout << "EMPTY\n"; + else + cout << max_heap.top() << " " << min_heap.top() << "\n"; + } +} \ No newline at end of file