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
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
ll n, k, cnt;
vector<ll> cur, sm;
vector<vector<ll>> r, u;
vector<set<pair<ll, ll>>> s;
queue<ll> q;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>k;
cur.resize(k);
sm.resize(n);
s.resize(k);
r.resize(n);
u.resize(n);
for (int i=0; i<n; i++) r[i].resize(k), u[i].resize(k);
for (int i=0; i<n; i++) for (int j=0; j<k; j++) cin>>r[i][j], sm[i]+=r[i][j];
for (int i=0; i<n; i++) for (int j=0; j<k; j++) cin>>u[i][j];
for (int i=0; i<n; i++)
{
if (sm[i]==0) q.push(i);
else s[0].insert({r[i][0], i});
}
while (!q.empty())
{
auto x=q.front();
q.pop();
cnt++;
for (int i=0; i<k; i++)
{
cur[i]+=u[x][i];
while (!s[i].empty()&&s[i].begin()->first<=cur[i])
{
ll tmp=s[i].begin()->second;
s[i].erase(s[i].begin());
if (i==k-1) q.push(tmp);
else s[i+1].insert({r[tmp][i+1], tmp});
}
}
}
cout<<cnt;
}
# | 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... |