Skip to content
Snippets Groups Projects
Commit 9c28d6ad authored by 김시환's avatar 김시환
Browse files

22.02.14

parent 4a26326e
No related branches found
No related tags found
No related merge requests found
#include<iostream>
#include<queue>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
priority_queue<int, vector<int>, greater<int>> pq;
for(int i=0;i<N*N;i++)
{
int num;
cin >> num;
if(pq.size() < N)
pq.push(num);
else
{
if(pq.top() < num)
{
pq.pop();
pq.push(num);
}
}
}
cout << pq.top();
}
\ No newline at end of file
#include<iostream>
#include<queue>
#include<map>
using namespace std;
struct problem
{
int idx, level;
};
struct compare_max
{
bool operator()(const problem& p1, const problem& p2)
{
if(p1.level == p2.level)
return p1.idx < p2.idx;
return p1.level < p2.level;
}
};
struct compare_min
{
bool operator()(const problem& p1, const problem& p2)
{
if(p1.level == p2.level)
return p1.idx > p2.idx;
return p1.level > p2.level;
}
};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N;
cin >> N;
map<int, int> diff;
priority_queue<problem, vector<problem>, compare_max> max_heap;
priority_queue<problem, vector<problem>, compare_min> min_heap;
for(int i=0;i<N;i++)
{
problem input;
cin >> input.idx >> input.level;
max_heap.push(input);
min_heap.push(input);
diff[input.idx] = input.level;
}
int M;
cin >> M;
for(int i=0;i<M;i++)
{
string op;
cin >> op;
if(op == "add")
{
problem input;
cin >> input.idx >> input.level;
max_heap.push(input);
min_heap.push(input);
diff[input.idx] = input.level;
}
else if(op == "recommend")
{
int x;
cin >> x;
if(x == 1)
{
while(!max_heap.empty() && diff[max_heap.top().idx] != max_heap.top().level)
max_heap.pop();
cout << max_heap.top().idx << "\n";
}
else
{
while(!min_heap.empty() && diff[min_heap.top().idx] != min_heap.top().level)
min_heap.pop();
cout << min_heap.top().idx << "\n";
min_heap.pop();
}
}
else if(op == "solved")
{
int x;
cin >> x;
diff[x] = 0;
}
}
}
\ No newline at end of file
#include<iostream>
#include<map>
#include<string>
using namespace std;
#define int int64_t
struct books{
int v{};
map<string, int> table;
};
map<string, books> Map;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int N, L, F;
string string_L;
cin >> N >> string_L >> F;
int Day_L = stoi(string_L.substr(0,3));
int Hour_L = stoi(string_L.substr(4,2));
int Minute_L = stoi(string_L.substr(7,2));
L = Day_L * 1440 + Hour_L * 60 + Minute_L;
while(N--)
{
string date, time, P, M;
cin >> date >> time >> P >> M;
int Time;
int Month = stoi(date.substr(5,2));
int Day = stoi(date.substr(8,2));
int Hour = stoi(time.substr(0,2));
int Minute = stoi(time.substr(3,2));
int Month_cum = 0;
for(int i=0;i<Month;i++)
Month_cum += month[i];
Time = Month_cum * 1440 + Day * 1440 + Hour * 60 + Minute;
auto& chk = Map[M];
if(chk.table.count(P))
{
if((Time - chk.table[P] - L) > 0)
chk.v += (Time - chk.table[P] - L) * F;
chk.table.erase(P);
}
else
chk.table[P] = Time;
}
bool chk = false;
auto iter = Map.begin();
while(iter != Map.end())
{
if(iter->second.v != 0)
{
chk = true;
cout << iter->first << " " << iter->second.v << "\n";
}
iter++;
}
if(chk == false)
cout << -1 << '\n';
}
\ No newline at end of file
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
using namespace std;
set<pair<int,int>> Q1[101];
set<pair<int,int>> Q2;
set<pair<int,int>> Q3; // 난이도, 번호
int level[100001];
int algo[100001];
void insert(int P, int L, int G)
{
Q1[G].insert(make_pair(L, P));
Q2.insert(make_pair(L, P));
Q3.insert(make_pair(L, P));
}
int re1(int G, int x)
{
if(x == 1)
return prev(Q1[G].end())->second;
else
return Q1[G].begin()->second;
}
int re2(int x)
{
if(x==1)
return prev(Q2.end())->second;
else
return Q2.begin()->second;
}
int re3(int x, int L)
{
if(x==1)
{
auto iter = Q3.upper_bound(make_pair(L-1, 999999));
if(iter == Q3.end())
return -1;
else
return iter->second;
}
else
{
auto iter = Q3.upper_bound(make_pair(L, -1));
if(iter == Q3.begin())
return -1;
else
return prev(iter)->second;
}
}
void del(int P)
{
int L = level[P];
int G = algo[P];
Q1[G].erase(make_pair(L, P));
Q2.erase(make_pair(L, P));
Q3.erase(make_pair(L, P));
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N;
cin >> N;
while(N--)
{
int P, L, G;
cin >> P >> L >> G;
insert(P, L, G);
level[P] = L;
algo[P] = G;
}
int M;
cin >> M;
while(M--)
{
string query;
cin >> query;
if(query == "recommend")
{
int G, x;
cin >> G >> x;
cout << re1(G, x) << endl;
}
else if(query == "recommend2")
{
int x;
cin >> x;
cout << re2(x) << endl;
}
else if(query == "recommend3")
{
int x, L;
cin >> x >> L;
cout << re3(x, L) << endl;
}
else if(query == "add")
{
int P, L, G;
cin >> P >> L >> G;
insert(P, L, G);
level[P] = L;
algo[P] = G;
}
else if(query == "solved")
{
int P;
cin >> P;
del(P);
}
}
}
\ No newline at end of file
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T;
cin >> T;
while(T--)
{
int M;
vector<int> ans;
priority_queue<int, vector<int>, less<int>> max_heap;
priority_queue<int, vector<int>, greater<int>>min_heap;
cin >> M;
for(int i=1;i<=M;i++)
{
int num;
cin >> num;
if(max_heap.size() == min_heap.size())
max_heap.push(num);
else
min_heap.push(num);
if(!max_heap.empty() && !min_heap.empty() && min_heap.top() < max_heap.top())
{
int toMin = max_heap.top();
int toMax = min_heap.top();
max_heap.pop();
min_heap.pop();
max_heap.push(toMax);
min_heap.push(toMin);
}
if(i%2==1)
ans.push_back(max_heap.top());
}
cout << ans.size() << endl;
for(int i=0;i<ans.size();i++)
cout << ans[i] << ' ';
cout << endl;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment