- 문제 링크 : boj.kr/30049
- 난이도 : G4
- 태그 : 구현, 자료구조
코드
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define INF 0x7FFFFFFF
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll, ll>;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m, k;
cin >> n >> m >> k;
vector<int> cnt(n+1);
vector<pii> top(m+1);
map<pii, int> info;
int ans = 0;
auto update = [&](int e, int s, int i) {
int &a = info[{e,s}];
a += i;
if(top[s].second < a) {
if(cnt[top[s].first] == k) ans--;
cnt[top[s].first]--;
cnt[e]++;
if(cnt[e] == k) ans++;
top[s] = {e, a};
}
};
for(int i = 1; i <= n; i++) {
for(int j = 0; j < k; j++) {
int a, b;
cin >> a >> b;
update(i, a, b);
}
}
int q;
cin >> q;
while(q--) {
int e, s, i;
cin >> e >> s >> i;
update(e, s, i);
cout << ans << "\n";
}
return 0;
}
풀이
(직원, 매장) 쌍의 매출액, 직원의 현재 1위하고 있는 매장의 수, 매장의 최고 매출액을 올리고 있는 (직원, 매출액)쌍을 가지고 업데이트 하면 된다.
728x90
'PS' 카테고리의 다른 글
BOJ 25634 : 전구 상태 뒤집기 (0) | 2024.08.10 |
---|---|
BOJ 19951 : 태상이의 훈련소 생활 (0) | 2024.08.09 |
BOJ 28437 : 막대 만들기 (0) | 2024.08.07 |
BOJ 32111 : 관광 코스 (0) | 2024.08.06 |
BOJ 30693 : Unusual competitions (0) | 2024.08.05 |