F-Hamburger Steak 2021牛客多校6

链接:https://ac.nowcoder.com/acm/contest/11257/F

题目描述:

Riko is ready to cook hamburger steaks. There are m pans and n 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.

输入描述:

The first line of the input contains two integers n and m (1≤n,m≤10^5).

The second line contains n integers t1,t2,…,tn (1≤ti≤10^9).

输出描述:

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≤10^18) in chronological order, representing that Riko will fry the hamburger steak in the pan numbered ididid during time [l,r).

If there are multiple answers, output any.

示例1

输入

5 3

1 2 3 4 5

输出

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

题意:

题目给定两个整数n和m,分别代表n个需要煎的汉堡牛排和m个可以使用的平底锅。随后输入n个整数,代表每个汉堡牛排i需要煎的时间ti。

规定第i个汉堡可以只用一个锅煎ti分钟,也可以使用两个锅,一个煎ai分钟,另一个煎bi分钟,保证ai + bi = ti即可。从0开始计算,使总的时间尽可能短。每个平底锅只能煎一份汉堡,但可以同时使用多个锅。放锅和拿取汉堡的时间不计。

输出n行。每行包括一个整数k表示使用k个锅煎,随后按时间顺序输出k组数据,每组包括三个整数id,l,r,分别表示使用第id个锅煎,开始煎的时刻l和结束煎的时刻r。

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
ll n,m,sum,t;
ll a[N];
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		t = max(t,a[i]);	//t记录花费最长的时间 
		sum += a[i];		//sum记录花费的总时间 
	}
	t = max(t,(sum+m-1)/m);
	int pan = 1;			//pan记录使用的平底锅编号 
	ll start = 0;			//start开始时刻 
	for(int i=1;i<=n;i++){ 
		if(start+a[i] <= t){	//使用一个锅 
			cout<<"1 "<<pan<<" "<<start<<" "<<start+a[i]<<'\n';
			start += a[i];		//更新下一个的开始时刻 
			if(start == t){
				pan++;
				start = 0;
			}
		}else{	//使用两个锅 
			cout<<"2 ";
			cout<<pan+1<<" "<<0<<" "<<start+a[i]-t<<" ";
			cout<<pan<<" "<<start<<" "<<t<<'\n';
			pan++;
			start = start+a[i]-t;
		}
	} 
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值