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>
using namespace std;
#define ll long long
#define int ll
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n+1)
#define pii pair<int, int>
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())
#define f first
#define s second
#define pb push_back
#define IOS() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
const ll maxn = 1e6+5;
const ll inf = 1ll<<60;
const ll mod = 1e9+7;
int n, k;
vector<pii> nw[maxn];
vector<int> nwptr(maxn);
vector<int> val(maxn);
vector<int> sat(maxn); // how many topics satisfies for each module
vector<vector<int>> bonus;
signed main(){
IOS();
cin>>n>>k;
REP(i, n){
REP(j, k){
int x; cin>>x;
nw[j].pb({x, i});
}
}
REP(j, k) sort(ALL(nw[j]));
bonus.resize(n);
REP(i, n){
bonus[i].resize(k);
REP(j, k){
cin>>bonus[i][j];
}
}
// initial
queue<int> qu;
REP(j, k){
for (int &i = nwptr[j]; i < n && nw[j][i].f <= val[j]; i++){
sat[nw[j][i].s]++;
if (sat[nw[j][i].s] == k) {
qu.push(nw[j][i].s);
}
}
}
int ans = 0;
while(SZ(qu)){
ans++;
int x = qu.front(); qu.pop();
REP(l, k){
val[l] += bonus[x][l];
}
REP(j, k){
for (int &i = nwptr[j]; i < n && nw[j][i].f <= val[j]; i++){
sat[nw[j][i].s]++;
if (sat[nw[j][i].s] == k) {
qu.push(nw[j][i].s);
}
}
}
}
cout<<ans<<endl;
}
# | 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... |