牛客多校6 F
题目描述
Riko is ready to cook hamburger steaks. There are m pans and hamburger steaks that need to be fried.
The i-th hamburger steak needs to be fried for ti (which is a positive integer) minutes. Riko can fry it in a certain pan for ti minutes, or in two different pans for ai and bi minutes respectively, where ai and bi are both positive integers and ai + bi = ti .
Riko will start cooking at time 0 and she wants to finish cooking as soon as possible. Please help Riko make a plan to minimize the time spent cooking all the hamburger steaks.
In this problem, we assume that a pan can fry at most one hamburger steak at the same time, and a hamburger steak can be put in at most one pan at the same time. Different pans can fry different hamburger steaks at the same time. We also assume that it takes no time to put a hamburger steak in a pan or take it out.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 105).
The second line contains n integers t1, t2, . . . , tn (1 ≤ ti ≤ 109).
Output
Output n lines. The i-th line describes the cooking plan for the i-th
hamburger steak. Each line begins with an integer k (k∈{1,2}),representing that Riko will fry the hamburger steak in k pans.
Then there follow k integer triples id, l, r (1 ≤ id ≤ m, 0 ≤ l < r ≤ 1018) in chronological order, representing that Riko will fry the hamburger steak in the pan numbered id during time [l, r). If there are multiple answers, output any.
Example standard input
5 3
1 2 3 4 5
standard output
1 1 0 1
1 2 0 2
1 2 2 5
1 1 1 5
1 3 0 5
Other valid outputs, such as the one below, are also acceptable for the example input:
1 1 0 1
1 1 1 3
2 2 0 1 1 3 5
1 2 1 5
1 3 0 5
先算出最大的时间,然后在给每个锅配置这个时间
刚开始以为最大的时间就是总时间/锅子数量,其实错了,如果有个时间大于平均值那么要把他煮熟肯定会大于平均时间的,所以这个最大时间应该是取最大的时间跟平均时间的较大值。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+100;
ll t[maxn];
vector<ll> a[maxn];//这里这样写属实是有点浪费空间了,每次求出一个汉堡牛排的方案直接打印出来就好了
ll b[maxn];
int main() {
ll n,m;
cin>>n>>m;
ll sum=0;
ll mx=0;
for(int i=1; i<=n; i++) {
cin>>t[i];
mx=max(t[i],mx);
sum+=t[i];
}
if(sum%m!=0) {
sum/=m;
sum++;
} else sum/=m;
int cnt=1;
int f=0;
sum=max(sum,mx);
for(int i=1; i<=m; i++){
b[i]=sum;
}
int res=0;
for(int i=1; i<=m;) {
if(t[cnt]<=b[i]) {
a[cnt].push_back(i);
a[cnt].push_back(sum-b[i]);
a[cnt].push_back(sum-b[i]+t[cnt]);
b[i]-=t[cnt];
t[cnt]=0;
}
if(t[cnt]>b[i]) {
a[cnt].push_back(i);
a[cnt].push_back(sum-b[i]);
a[cnt].push_back(sum);
t[cnt]-=b[i];
b[i]=0;
}
if(t[cnt]==0)
cnt++;
if(cnt==n+1){
f=i;
break;
}
if(b[i]==0) {
i++;
}
}
for(int i=1; i<=n; i++) {
int count = a[i].size();
int f;
if(count>3)f=2;
else f=1;
cout<<f<<" ";
if(f==2) {
for(int j=3; j<count; j++) {
cout<<a[i][j]<<" ";
}
for(int j=0; j<3; j++) {
if(j!=2)cout<<a[i][j]<<" ";
else cout<<a[i][j]<<endl;
}
} else {
for(int j=0; j<count; j++) {
if(j!=count-1)cout<<a[i][j]<<" ";
else cout<<a[i][j]<<endl;
}
}
}
return 0;
}