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 pb push_back
#define fo(i, n) for(ll i = 0; i<(n); i++)
#define deb(x) cout << #x << " = " << (x) << endl
#define deb2(x, y) cout << #x << " = " << (x) << ", " << #y << " = " << y << endl
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pl;
typedef vector<pl> vpl;
typedef vector<vpl> vvpl;
int main(){
cin.tie(0)->sync_with_stdio(0);
int n, k;
cin >> n >> k;
vvl r(n, vl(k)), u(n, vl(k));
vvpl cost(k);
queue<ll> onQueue;
vl am(n, 0);
ll ans = 0;
fo(i, n){
bool allZero = 1;
fo(j, k){
cin >> r[i][j];
if(r[i][j]) allZero = 0;
cost[j].pb({r[i][j], i});
}
if(allZero){
onQueue.push(i);
am[i] = k+1;
}
}
fo(i, n){
fo(j, k){
cin >> u[i][j];
}
}
fo(i, k) sort(rall(cost[i]));
vl p(k, 0);
while(!onQueue.empty()){
ll current = onQueue.front();
onQueue.pop();
ans++;
fo(i, k){
p[i]+=u[current][i];
while(cost[i].size() && cost[i][cost[i].size()-1].F<=p[i]){
ll pos = cost[i][cost[i].size()-1].S;
cost[i].pop_back();
am[pos]++;
if(am[pos] == k) onQueue.push(pos);
}
}
}
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... |