이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |