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! ( ( (尖叫扭曲 ) ) )

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

相关推荐
Coovally AI模型快速验证36 分钟前
农田扫描提速37%!基于检测置信度的无人机“智能抽查”路径规划,Coovally一键加速模型落地
深度学习·算法·yolo·计算机视觉·transformer·无人机
mit6.82438 分钟前
[openvela] Hello World :从零开始的完整实践与问题复盘
c++·嵌入式硬件
pusue_the_sun39 分钟前
数据结构:二叉树oj练习
c语言·数据结构·算法·二叉树
萧鼎1 小时前
Python pyzmq 库详解:从入门到高性能分布式通信
开发语言·分布式·python
RaymondZhao341 小时前
【全面推导】策略梯度算法:公式、偏差方差与进化
人工智能·深度学习·算法·机器学习·chatgpt
艾伦~耶格尔2 小时前
【集合框架LinkedList底层添加元素机制】
java·开发语言·学习·面试
zhangfeng11332 小时前
DBSCAN算法详解和参数优化,基于密度的空间聚类算法,特别擅长处理不规则形状的聚类和噪声数据
算法·机器学习·聚类
yujkss2 小时前
Python脚本每天爬取微博热搜-终版
开发语言·python
yzx9910132 小时前
小程序开发APP
开发语言·人工智能·python·yolo
啊阿狸不会拉杆2 小时前
《算法导论》第 32 章 - 字符串匹配
开发语言·c++·算法