#include <iostream>
using namespace std;
int main() {
cin.sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin>>n>>m;
int people[n+1], ovens[m];
people[0] = 0;
for (int i = 1; i <= n; i++) {
cin>>people[i];
}
for (int i = 0; i < m; i++) {
cin>>ovens[i];
}
int results[m];
for (int i = 0; i < m; i++) {
results[i] = 0;
for (int j = 0; j < n; j++) {
results[i] += ovens[i] - (people[j+1] - people[j] > ovens[i] ? ovens[i] : people[j+1] - people[j]);
}
}
for (int i = 0; i < m; i++) {
cout<<results[i]<<"\n";
}
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #include <iostream> using namespace std; int main() { cin.sync_with_stdio(false); cin.tie(nullptr); int n, m; cin>>n>>m; int people[n+1], ovens[m]; people[0] = 0; for (int i = 1; i <= n; i++) { cin>>people[i]; } for (int i = 0; i < m; i++) { cin>>ovens[i]; } int results[m]; for (int i = 0; i < m; i++) { results[i] = 0; for (int j = 0; j < n; j++) { results[i] += ovens[i] - (people[j+1] - people[j] > ovens[i] ? ovens[i] : people[j+1] - people[j]); } } for (int i = 0; i < m; i++) { cout<<results[i]<<"\n"; } return 0; } |
English