- 注意:输出时,如果同一块牛排在两个锅内完成烹饪,则需要先输出pos+1锅的起始和结束时间,再输出pos锅的起始和结束时间。
accode:
#include <iostream>
#include <stdio.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 +10;
inline ll max(ll a, ll b){return (a > b) ? a : b;}
int n, m, k, T, cnt, flag;
int ans, a[maxn];
ll sum = 0, maxx = 0, f, t;
int main()
{
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; i++)
{
scanf("%d", &a[i]);
sum += a[i];
maxx = max(maxx, 1ll * (a[i]));
}
f = sum / m;
if(sum % m)
f++;
maxx = max(f, maxx);//最小总时间(每口锅的最长烹饪时间)
int pos = 1; //锅的位置
t = 0; //该锅消耗的时间
for(int i = 1; i <= n; i++)
{
if(t + a[i] <= maxx)//满足煎完 a[i]的条件
{
cout<<1<<" "<<pos<<" "<<t<<" "<<t + a[i]<<endl;
t += a[i];
if(t == maxx)
{
t = 0;
pos++;
}
}
else//当前锅烹饪不完第i块肉饼
{
cout<<2<<" "<<pos + 1<<" "<<0<<" "<<a[i] - (maxx - t)<<" "; //注意pos+1排在pos前面
cout<<pos<<" "<<t<<" "<<maxx<<endl;
t = a[i] - (maxx - t);
pos++;
}
}
return 0;
}