이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
signed main(){
cin.tie(0)-> sync_with_stdio(0);
int n;
cin >> n;
vi people(n);
vi spots(n);
for(int i=0;i<n;++i){
cin >> spots[i];
}
for(int i=0;i<n;++i){
cin >> people[i];
}
int free = 0;
int happy = 0;
int ind = 0;
int unhappy = 0;
for(int i=0;i<n;++i){
int inc = 0;
//give free spots to people
inc = min(free,people[i]);
happy += inc;
free -= inc;
people[i] -= inc;
//move indifferent people to make more happy
inc = min(ind,people[i]);
happy += inc;
unhappy += inc;
ind -= inc;
people[i] -= inc;
//make people indiffernt if there is space (temp until kicked out)
inc = min(spots[i],people[i]);
ind += inc;
spots[i] -= inc;
people[i] -= inc;
unhappy += people[i];
free += spots[i];
//cerr << i << " happy " << happy << " ind " << ind << " unhappy " << unhappy << '\n';
}
cout << happy - unhappy<< '\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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |