[二分答案] P2920 Time Management

news/2024/10/23 12:27:50/

 

推导贪心条件

排序

二分

输出

 

//#pragma GCC optimize(2)
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;const int MAXN = 1e6 + 10;pair <ll, ll> arr[MAXN];int N;bool cmp(pair <ll, ll> a, pair <ll, ll> b)
{return a.second < b.second;
}bool judge(int x)
{ll sum = x;for(int i = 0; i < N; i++){sum += arr[i].first;if(sum > arr[i].second)return false;}return true;}void bsearch()
{int fst = 0, lst = MAXN, mid, ans;if(!judge(0)){cout<<"-1"<<endl;return ;}while(fst <= lst){mid = (fst + lst) / 2;if(judge(mid)){ans = mid;fst = mid + 1;}elselst = mid - 1;}cout<<ans<<endl;}int main()
{//ios::sync_with_stdio(false);//cin.tie(0);     cout.tie(0);cin>>N;for(int i = 0; i < N; i++)cin>>arr[i].first>>arr[i].second;sort(arr, arr + N, cmp);bsearch();return 0;
}

 


http://www.ppmy.cn/news/505730.html

相关文章

Spring Boot 中自定义数据校验注解

Spring Boot 中自定义数据校验注解 在 Spring Boot 中&#xff0c;我们可以使用 JSR-303 数据校验规范来校验表单数据的合法性。JSR-303 提供了一些常用的数据校验注解&#xff0c;例如 NotNull、NotBlank、Size 等。但是&#xff0c;在实际开发中&#xff0c;我们可能需要自定…

【莫比乌斯反演】BZOJ2920-YY的GCD

【题目大意】 给定N, M,求1<x<N, 1<y<M且gcd(x, y)为质数的(x, y)有多少对。 【思路】 太神了这道题……蒟蒻只能放放题解&#xff1a;戳&#xff0c;明早再过来看看还会不会推导过程…… 实用的结论&#xff1a; 嗯…… /***************************************…

2920集五福_支付宝集五福攻略 ▏顺便学点营销活动传播套路

到今天为止&#xff0c;你一共收齐了几张福卡了呢&#xff1f; 本月5号&#xff0c;支付宝在微信公众号里发了《新年俗 集五福》的推文&#xff0c;“2月6日0点&#xff0c;支付宝里见&#xff0c;有你们就有福”。 同时&#xff0c;一名叫“青春、已不在”的网友立马在下方评论…

2920X

演讲不是讲自己的话&#xff0c;而是将听众的话&#xff0c;还记得那些演讲失败者&#xff0c;离开舞台的最后一段话&#xff0c;他们的感言就是我们失败的原因历史总是惊人的相似举例子是为了增加信服性历史是如此的悠久&#xff0c;还有什么故事不能符合我任何贪婪的意愿我的…

java多线程简明笔记(5)线程礼让 yield

关键字&#xff1a;yield 官方文档就不说了&#xff0c;简单理解&#xff0c;礼让 线程礼让 yield正在执行的线程暂停&#xff0c;不阻塞 示例代码&#xff1a; public class ThreadTest7 implements Runnable{public static void main(String[] args) {ThreadTest7 tnew Th…

雅思词汇真经单词共3672个

雅思词汇真经 / Vocabulary for IELTS / 学为贵 赢未来 / 英语真经派学习法 一本书精通雅思词汇 / 刘洪波 编著 / 涵盖&#xff1a;雅思必备核心词汇刘洪波老师原创雅思考点词库 逻辑词群记忆法&#xff0c;一群一群记单词&#xff0c;快速备考无负责 时尚插图&#xff0c;趣味…

大一上:英语复习:Word in use(新视野大学英语读写教程1:第一、三、四、六单元翻译+注释)【四大人工智能翻译辅助系统助力翻译更准确】

文档下载地址&#xff1a;https://pan.baidu.com/s/1qYDT6rU Word in use Unit 1 A 1.Given the chance to show his ability, he regained confidence and began to succeed in school. [自然智力神经系统翻译&#xff08;我翻译的&#xff09;]自从获得了…

智能家庭本周锋闻:小米进军移动医疗

投资九安医疗旗下iHealth智能血压仪&#xff0c;小米为何选择这个时间、进入这个领域&#xff1f;原因大概有这几点&#xff0c;首先可以借助国庆“送礼”时机&#xff1b;其次移动医疗切合小米的年轻用户群体敬老&#xff1b;再者移动医疗前景看好&#xff0c;且可搭配小米手机…