이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//23 minutes
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAXN (1000005)
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);
ll N,K;
cin>>N>>K;
priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > > pq[K];
ll need[N][K];
for(ll i = 0;i < N;i++){
for(ll j = 0;j < K;j++){
cin>>need[i][j];
pq[j].push({need[i][j],i});
}
}
ll gain[N][K];
for(ll i = 0;i < N;i++){
for(ll j = 0;j < K;j++){
cin>>gain[i][j];
}
}
ll numoftopic[N];
memset(numoftopic,0,sizeof(numoftopic));
ll curtopic[K];
memset(curtopic,0,sizeof(curtopic));
queue<ll> can;
ll sum = 0;
for(ll i = 0;i < N;i++){
for(ll j = 0;j < K;j++){
while(!pq[j].empty() && pq[j].top().first <= curtopic[j]){
numoftopic[pq[j].top().second]++;
if(numoftopic[pq[j].top().second] >= K){
can.push(pq[j].top().second);
}
pq[j].pop();
}
}
while(!can.empty()){
sum++;
ll x = can.front();
for(ll j = 0;j < K;j++){
curtopic[j] += gain[x][j];
}
can.pop();
}
}
cout<<sum<<'\n';
}
# | 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... |