Problem Author: | Pavlo Tsikalyshyn |
Prepared by: | Pavlo Tsikalyshyn |
Editorial by: | Pavlo Tsikalyshyn |
To solve the problem, we just needed to carefully implement what was asked from us in the statement. Check out commented code below.
#include <iostream>
#include <vector>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int n, k, x, i, res=0, curSleep=0;
// Reading input
cin>>n>>k>>x;
vector<int> b(n), c(n);
for(i=0;i<n;++i){
cin>>b[i];
}
for(i=0;i<n;++i){
cin>>c[i];
}
for(i=0;i<n;++i){
// Checking if you currently a sleep
if(k >= x){
// Updating how long have slept and how long you have slept in your last period
++res;
++curSleep;
// Cheking if you will wake up
if(c[i] > curSleep){
// Updating sleepness and length of last period
k = 0;
curSleep = 0;
}
}else{
// Updating current sleepness
k += b[i];
}
}
// Printing answer
cout<<res<<endl;
return 0;
}