# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1102361 | tuannm | Topical (NOI23_topical) | C++17 | 474 ms | 71336 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ii pair<int, int>
#define ll pair<long long, long long>
#define fi first
#define se second
#define pb push_back
using namespace std;
const int mod[2] = {1000000007, 998244353};
const int N = 1e6 + 1;
const string NAME = "";
int n, k;
vector<vector<ii>> r;
vector<vector<int>> u;
vector<int> cur, cnt;
vector<long long> p;
void inp(){
cin >> n >> k;
}
void solve(){
r.resize(k);
u.resize(n, vector<int> (k));
p.resize(k, 0);
cur.resize(k, 0);
cnt.resize(n, 0);
for(int i = 0; i < n; ++i)
for(int j = 0; j < k; ++j){
int x;
cin >> x;
r[j].pb({x, i});
}
for(int i = 0; i < n; ++i)
for(int j = 0; j < k; ++j)
cin >> u[i][j];
int ans = 0;
for(int i = 0; i < k; ++i)
sort(r[i].begin(), r[i].end());
while(1){
vector<int> can_complete;
for(int i = 0; i < k; ++i){
while(cur[i] < n && r[i][cur[i]].fi <= p[i]){
++cnt[r[i][cur[i]].se];
if(cnt[r[i][cur[i]].se] == k)
can_complete.pb(r[i][cur[i]].se);
++cur[i];
}
}
if(can_complete.empty())
break;
ans += can_complete.size();
for(int i : can_complete)
for(int j = 0; j < k; ++j)
p[j] += u[i][j];
}
cout << ans;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen((NAME + ".inp").c_str(), "r")){
freopen((NAME + ".inp").c_str(), "r", stdin);
freopen((NAME + ".out").c_str(), "w", stdout);
}
inp();
solve();
}
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... |