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 <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
const int mxn = 1e6;
int can[mxn];
bool compare(pair<int, int> a, pair<int, int> b){
if(a.first == b.first) return a.second < b.second;
return a.first > b.first;
}
int main(){
int n, k;
cin >> n >> k;
vector<vector<int> > require(n, vector<int>(k)), gain(n, vector<int>(k));
queue<int> q;
vector<vector<pair<int, int> > > tmp(k, vector<pair<int, int> >());
vector<long long> knowledge(k, 0);
for(int i=0; i<n; i++){
for(int j=0; j<k; j++){
cin >> require[i][j];
if(!require[i][j]) can[i]++;
tmp[j].push_back(make_pair(require[i][j], i));
}
if(can[i]==k) q.push(i);
}
for(int i=0; i<n; i++){
for(int j=0; j<k; j++) cin >> gain[i][j];
}
for(int i=0; i<k; i++){
sort(tmp[i].begin(), tmp[i].end(), compare);
}
int ans = 0;
while(!q.empty()){
int cur = q.front(); q.pop();
ans++;
for(int i=0; i<k; i++){
knowledge[i] += gain[cur][i];
while(!tmp[i].empty() && tmp[i].back().first <= knowledge[i]){
int module = tmp[i].back().second;
can[module]++;
if(can[module] == k) q.push(module);
tmp[i].pop_back();
}
}
}
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... |