# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1122795 | nhphuc | Topical (NOI23_topical) | C++20 | 595 ms | 140144 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main (){
ios::sync_with_stdio(false); cin.tie(nullptr);
if (fopen("test.inp", "r")){
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
int n, k, ans = 0; cin >> n >> k;
vector<int> cnt(n + 1), id(k + 1), cur(k + 1);
vector<vector<int>> r(n + 1, vector<int>(k + 1)), u(n + 1, vector<int>(k + 1));
vector<pair<int, int>> vec[k + 1];
for (int i = 1; i <= n; ++i){
for (int j = 1; j <= k; ++j){
cin >> r[i][j];
}
}
for (int i = 1; i <= n; ++i){
for (int j = 1; j <= k; ++j){
cin >> u[i][j];
}
}
for (int i = 1; i <= n; ++i){
for (int j = 1; j <= k; ++j){
vec[j].push_back({r[i][j], i});
}
}
for (int i = 1; i <= k; ++i){
sort(vec[i].begin(), vec[i].end());
}
while (true){
vector<int> lst;
for (int i = 1; i <= k; ++i){
while (id[i] < n && vec[i][id[i]].first <= cur[i]){
++cnt[vec[i][id[i]].second];
if (cnt[vec[i][id[i]].second] == k){
lst.push_back(vec[i][id[i]].second);
}
++id[i];
}
}
if (lst.size() == 0){
break;
}
ans += lst.size();
for (int i : lst){
for (int j = 1; j <= k; ++j){
cur[j] += u[i][j];
}
}
}
cout << ans << "\n";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |