제출 #936958

#제출 시각아이디문제언어결과실행 시간메모리
936958qwe1rt1yuiop1Topical (NOI23_topical)C++14
100 / 100
405 ms136672 KiB
#include <bits/stdc++.h> #define int long long using namespace std; using pii = pair<int, int>; void solve() { int n, k; cin >> n >> k; vector<vector<int>> a(n, vector<int>(k)), b = a; for (auto &i : a) for (auto &j : i) cin >> j; for (auto &i : b) for (auto &j : i) cin >> j; /* if (k == 1) { vector<pii> v(n); for (int i = 0; i < n; ++i) v[i].first = a[i][0], v[i].second = b[i][0]; sort(v.begin(), v.end()); int cur = 0, ans = 0; for (int i = 0; i < n; ++i) if (v[i].first <= cur) { cur += v[i].second; ++ans; } cout << ans << '\n'; return; } if (max(n, k) <= 100) { vector<int> cur(k, 0), flag(n, 0); while (1) { int ok = 0; for (int i = 0; i < n; ++i) if (!flag[i]) { int okk = 1; for (int j = 0; j < k; ++j) okk &= cur[j] >= a[i][j]; if (okk) { ok = flag[i] = 1; for (int j = 0; j < k; ++j) cur[j] += b[i][j]; break; } } if (!ok) break; } cout << accumulate(flag.begin(), flag.end(), 0LL) << '\n'; return; } */ vector<vector<pii>> v(k); for (int i = 0; i < n; ++i) for (int j = 0; j < k; ++j) v[j].emplace_back(a[i][j], i); vector<int> cnt(n, 0), cur(k, 0); queue<int> q; for (int i = 0; i < k; ++i) { sort(v[i].begin(), v[i].end()); reverse(v[i].begin(), v[i].end()); while (!v[i].empty()) { if (v[i].back().first > cur[i]) break; cnt[v[i].back().second]++; if (cnt[v[i].back().second] == k) q.emplace(v[i].back().second); v[i].pop_back(); } } int ans = 0; while (!q.empty()) { ++ans; int x = q.front(); q.pop(); for (int i = 0; i < k; ++i) { cur[i] += b[x][i]; while (!v[i].empty()) { if (v[i].back().first > cur[i]) break; cnt[v[i].back().second]++; if (cnt[v[i].back().second] == k) q.emplace(v[i].back().second); v[i].pop_back(); } } } cout << ans << '\n'; } signed main() { ios::sync_with_stdio(0); cin.tie(0); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...