跳到正文

题解

题解:P14336 [JOI2020 预选赛 R2] 草莓 / Strawberry

Gartjock约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年5月4日
篇幅
约 1 分钟
题目
P14336

版本

  1. v1当前

思路

对于每个草莓返回时间有两种情况

1.无需等待成熟,时间为 ai×2a_i \times 2 。

2.需要等待成熟,时间为 ai+tia_i + t_i 。

所以我们处理每个草莓所需时间,其中的最大值一定覆盖了其他草莓所需时间,最后在处理最大往返所需时间,最大值就是答案。

代码

C++
#include<bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;
const int N=1e6+6;
int n,mx,ans;
struct node{
	int a,t;
}c[N];
bool cmp(node b,node d){
	return b.a>d.a;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>c[i].a>>c[i].t;
	sort(c+1,c+n+1,cmp);
	for(int i=1;i<=n;i++){
		ans=max(ans,c[i].t+c[i].a);
		ans=max(ans,2*c[i].a);
	}
	mx=c[1].a;
	ans=max(ans,2*mx);
	cout<<ans;
	return 0;
}
原文