Test instructions: The Prince buys M bulbs a month for n rooms for light bulbs, if the current number of light bulbs is enough to change the first room of the list, until the bulb is not enough, to give a query, query x months has changed several houses, the number of light bulbs left in hand.
Solution: Water problem ... Small simulations.
Code:
#include <stdio.h> #include <iostream> #include <algorithm> #include <string> #include < string.h> #include <math.h> #include <limits.h> #include <time.h> #include <stdlib.h># include<map> #include <queue> #include <set> #include <stack> #include <vector> #define LL Long longusing namespace Std;int a[1005], Ans[100005][2];int main () {int n, m; while (~SCANF ("%d%d", &n, &m)) {int cnt = 0; for (int i = 0; i < n; i++) {scanf ("%d", &a[i]); } Ans[0][0] = 0, ans[0][1] = 0; int j = 0; for (int i = 1; I <= 100000; i++) {cnt++; Ans[i][0] = ans[i-1][0]; ANS[I][1] = ans[i-1][1] + m; while (J < n && A[j] <= ans[i][1]) {ans[i][0]++; ANS[I][1]-= a[j]; j + +; } if (j = = n) break; } int q; scanf ("%d", &q); while (q--) {int x; scanf ("%d", &x); if (x > CNT) x = CNT; printf ("%d%d\n", ans[x][0], ans[x][1]); }} return 0;}
CF GYM 100703B Energy Saving