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

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

相关推荐
张张123y1 小时前
DSH 插件调试避坑:client.js 设置面板、热重载与高频报错排查表
开发语言·javascript·人工智能·开源·ecmascript·后端开发·ai agent
Navigator_Z3 小时前
LeetCode //C - 1317. Convert Integer to the Sum of Two No-Zero Integers
c语言·算法·leetcode
wo_jack3 小时前
C++ 入门笔记(十六):第16课 vector 模拟实现十问十答 —— 从三指针到迭代器失效
c++·后端·面试·stl·vector
D e re k ZH3 小时前
C++ 标准库算法全景指南
数据结构·c++·算法
冻柠檬飞冰走茶4 小时前
字母移动游戏题解:贪心求最长可保留连续子串(附 C 实现)
c语言·开发语言·数据结构·算法·动态规划
FRing034 小时前
vue2干货总结7(自定义指令、插槽、单页应用程序、路由的使用(VueRouter))
开发语言·前端·vue.js·vue2
雪落漂泊4 小时前
C++算法 二分查找篇(上)
开发语言·c++·算法
波力海苔夹心脆6755 小时前
C# WPF 资源字典详解:ResourceDictionary、MergedDictionaries 与自定义控件案例
开发语言·c#·wpf·入门教程·resource·资源字典
不会算法的笨小孩6 小时前
异常的使用以及会出现的问题
开发语言·c++·c++11·异常