题目解析:这就是一题很简单的模拟,直接上代码;
#include<iostream>
using namespace std;
const int N = 10010;
int arr[N];
int main()
{
int n , m;
cin >> n >> m;
int sum = 0;
int res = 0;
for(int i = 0; i < n;i ++) cin >> arr[i];
for(int i = 0;i < n;i ++)
{
if(sum + arr[i] > m)
{
res++;
sum = 0;
}
sum += arr[i];
}
cout << res << endl;
return 0;
}
2.
解析: 这个也是一个很简单的模拟,注意更新他的服药时间
#include<iostream>
using namespace std;
const int N = 10010;
int a[N], last[N];
int main()
{
int n, m;
cin >> n >> m;
for (int i = 1;i <= n; i++)
{
cin >> a[i];
last[i] = -100;
}
int t, k;
while (m--)
{
cin >> t >> k;
int i;
while (k--)
{
cin >> i;
if (a[i] == -1) continue;
if (t - last[i] >= a[i]) last[i] = t;
else
{
printf("Don't take %d at %d!\n", i, t);
}
}
}
return 0;
}