Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <bits/stdc++.h>
using namespace std;
int const N = 2e5 + 1;
int n, m, a[N];
int main() {
scanf("%d %d", &n, &m);
for(int i = 0; i < n; ++i)
scanf("%d", a + i);
int rem = m;
for(int d = 0; d < n; ++d) {
int cur = a[d], res = 0;
if(cur < rem)
rem -= cur;
else if(cur == rem)
++res, rem = m;
else {
cur -= rem;
rem = m;
++res;
if(cur < rem)
rem -= cur;
else if(cur == rem)
++res, rem = m;
else {
res += cur / rem;
cur = cur % rem;
rem -= cur;
}
}
printf("%d ", res);
}
puts("");
return 0;
}
Copy The Code &
Try With Live Editor
Input
3 5
Output
0 2 1
Demonstration
Codeforces Solution-Death Note-Solution in C, C++, Java, Python,Death Note-Solution,Codeforces Solution