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;
using ll = long long;
#define fi first
#define si second
#define ar array
#define pb push_back
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;
typedef vector<int> vi;
template<typename T> bool chmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
int n, k;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin.exceptions(ios::badbit|ios::failbit);
cin >> n >> k;
vector<vector<int>> r(n, vector<int>(k));
vector<vector<int>> u(n, vector<int>(k));
vector<int> cnt(n, k);
queue<int> q;
for (int i = 0; i < n; ++i) {
ll sum = 0;
for (int j = 0; j < k; ++j) cin >> r[i][j], sum += r[i][j];
if (!sum) q.push(i), cnt[i] = 0;
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < k; ++j) cin >> u[i][j];
}
vector<vector<int>> order(k, vector<int>(n));
for (int i = 0; i < k; ++i) {
iota(order[i].begin(), order[i].end(), 0);
sort(order[i].begin(), order[i].end(), [&](int x, int y) {
return r[x][i] < r[y][i];
});
}
vector<ll> cur(k);
vector<int> id(k);
int ans = 0;
while (q.size()) {
int x = q.front(); q.pop();
++ans;
for (int j = 0; j < k; ++j) {
cur[j] += u[x][j];
while (id[j] < n && cur[j] >= r[order[j][id[j]]][j]) {
if (!--cnt[order[j][id[j]]]) q.push(order[j][id[j]]);
++id[j];
}
}
}
cout << ans;
return 0;
}
# | 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... |