C. The Delivery Dilemma

啊!我的推!你帅亖我了!(封面)

哈哈哈哈哈哈哈哈哈又是我
等等我先发个颠

没错叕是题目:
C . T h e D e l i v e r y D i l e m m a C. The Delivery Dilemma C.TheDeliveryDilemma

咳咳,思路 : : :

假设我们所有菜都让他们送过来,则 a n s ans ans= m a x max max( a 1 a_1 a1 , a 2 a_2 a2 ... , a N a_N aN),

不妨开一个 a n s ans ans表示当前自己去拿已经花费的时间,

由于自己买的时候花费时累加的,

我们先将 a 1 a_1 a1 , a 2 a_2 a2 , ... , a N a_N aN从大

到小排序,

若 a i > a n s + b i a_i > ans + b_i ai>ans+bi

则第 i i i个物品可以通过自己买来代替,否则直接输出答案。

AC时刻

cpp 复制代码
#include <iostream>		// 基本入出力ストリーム
#include <algorithm>	// 一般的なアルゴリズム(ソート、ルックアップ、やり直し、二分ルックアップなど)
#include <vector>		// 動的配列(スペースが足りないと自動的に拡張されます)
#include <queue>		//  スタック(先に入って先に出ます)
#include <stack>		// スタック(先に入ってから出ます)
#include <set>			// 集合(反復しない順序)です
#include <map>			// キー値対コンテナ(マッピング)
#include <list>			//  両方向リスト
#include <math.h>		//  すうがくかんすう
#include <functional>	// 通用的函数绑定和调用机制一般的なバインディングと呼び出しの仕組み

#define endl '\n'
#define pii pair<int, int>
#define pdd pair<double, double>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using namespace std;
struct cjdl {
	long long a, b;
} c[200005];
long long t = 0, n = 0;
bool cmp(cjdl x, cjdl y) { //a[i]和b[i],由a[i]从大到小排序
	return x.a > y.a;
}
const int inf = 1e9 + 7;
const int mod = 998244353;
const int N = 2e5 + 10, M = N << 1;

void solve() {
	// 竞赛程序
	cin>>n;
	for(int  i = 1; i <= n; i++) {
		cin >> c[i].a;
	}
	for(int i = 1; i <= n; i++) {
		cin >> c[i].b;
	}
	sort(c + 1, c + n + 1, cmp);
	bool flag = 0;
	long long ans = 0;
	for(int i = 1; i <= n; i++) {
		if(c[i].a > ans + c[i].b) { //有a[i]>ans+b[i]
			ans += c[i].b;//ans加上自己取的时间
		} else { //否则直接输出答案
			cout << max(c[i].a, ans) << endl;
			flag = 1;
			break;
		}
	}
	if(!flag) {
		cout << ans << endl;
	}
}

signed main() {

	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int t = 1;
	cin >> t;	// 非多组测试数据请注释该行
	while(t--) solve();
	return 0;
}

最后我还要声明一下:

我到底还要说多少遍我写代码用的是CPP! ( ( (尖叫扭曲 ) ) )

实在不行你看我洛谷简介 ( ( (裂开 ) ) )

相关推荐
专注仿真25 分钟前
智能体训练之模仿学习:GAIL 算法详解与实战
python·算法·仿真·多智能体强化学习·afsim智能体训练
whitelbwwww34 分钟前
CUDA C++实战--中级
开发语言·前端·c++
FungLeo1 小时前
FengCMS · PHP+MySQL 升级实录 · 内容写入一致性:锁等待超时与跨模型子树删除竞态
开发语言·mysql·php·工程实践·fengcms
leobertlan2 小时前
痛苦系列 | DSP-04 截断时空的“窗”:FIR 滤波器设计与线性相位
算法
谙弆悕博士3 小时前
多智能体架构详解:市场拍卖式架构(Market-based / 竞价协商)
开发语言·架构·去中心化·多智能体·智能体·拍卖架构
ShineWinsu3 小时前
对于Qt:QMessageBox的解析
开发语言·c++·qt·面试·客户端·qmessagebox·消息对话框
承渊政道3 小时前
【Python编程快速上手—让繁琐工作自动化】(列表:把数据排成队,从下标取值到深拷贝)
开发语言·python·pycharm·自动化·列表
秋天的怀念_David3 小时前
算法一千零一夜 · 第三十五夜 · 恢复风暴
java·程序人生·算法
躺柒4 小时前
2026年10月总结及随笔之国庆天天乐
程序人生·总结·国庆·随笔·读后感