[SDCPC2023] Orders(模拟)

题面翻译

【题目描述】

某工厂在第 1 1 1 天开工之前收到了 n n n 笔订单,第 i i i 笔订单可以用两个整数 a i a_i ai b i b_i bi 描述,表示工厂需要在第 a i a_i ai 天结束时交付 b i b_i bi 件货物。

已知工厂每天能生产 k k k 件货物,且第 1 1 1 天开工之前没有任何存货,问该工厂能否完成所有订单。

【输入格式】

有多组测试数据。第一行输入一个整数 T T T 1 ≤ T ≤ 100 1 \le T \le 100 1T100)表示测试数据组数,对于每组测试数据:

第一行输入两个整数 n n n k k k 1 ≤ n ≤ 100 1 \le n \le 100 1n100 1 ≤ k ≤ 1 0 9 1 \le k \le 10^9 1k109)表示订单数量以及工厂每日能生产的货物数量。

对于接下来 n n n 行,第 i i i 行输入两个整数 a i a_i ai b i b_i bi 1 ≤ a i , b i ≤ 1 0 9 1 \le a_i, b_i \le 10^9 1ai,bi109)表示第 i i i 笔订单要求在第 a i a_i ai 天结束时交付 b i b_i bi 件货物。

【输出格式】

每组数据输出一行。若工厂能完成所有订单输出 Yes \texttt{Yes} Yes,否则输出 No \texttt{No} No

【样例解释】

对于第一组样例数据,工厂每天能生产 5 5 5 件货物。

  • 在第 1 1 1 天结束时,工厂共有 5 5 5 件货物,可以完成第 2 2 2 笔订单。交付后,工厂剩余 2 2 2 件货物。
  • 在第 6 6 6 天结束时,工厂又多生产了 25 25 25 件货物,共有 27 27 27 件货物,可以完成第 1 1 1 和第 3 3 3 笔订单。交付后,工厂剩余 0 0 0 件货物。
  • 在第 8 8 8 天结束时,工厂又多生产了 10 10 10 件货物,共有 10 10 10 件货物,可以完成第 4 4 4 笔订单。交付后,工厂剩余 9 9 9 件货物。

对于第二组样例数据,工厂每天能生产 100 100 100 件货物。

  • 在第 3 3 3 天结束时,工厂共有 300 300 300 件货物,可以完成第 1 1 1 笔订单。交付后,工厂剩余 100 100 100 件货物。
  • 在第 4 4 4 天结束时,工厂又多生产了 100 100 100 件货物,共有 200 200 200 件货物,无法完成第 2 2 2 笔订单。

题目描述

A factory receives n n n orders at the beginning of day 1 1 1. The i i i-th order can be described as two integers a i a_i ai and b i b_i bi, indicating that at the end of day a i a_i ai, the factory needs to deliver b i b_i bi products to the customer.

Given that the factory can produce k k k products each day, and at the beginning of day 1 1 1 the factory has no product in stock, can the factory complete all orders?

输入格式

There are multiple test cases. The first line of the input contains an integer T T T ( 1 ≤ T ≤ 100 1 \le T \le 100 1T100) indicating the number of test cases. For each test case:

The first line contains two integers n n n and k k k ( 1 ≤ n ≤ 100 1 \le n \le 100 1n100, 1 ≤ k ≤ 1 0 9 1 \le k \le 10^9 1k109) indicating the number of orders and the number of products the factory can produce each day.

For the following n n n lines, the i i i-th line contains two integers a i a_i ai and b i b_i bi ( 1 ≤ a i , b i ≤ 1 0 9 1 \le a_i, b_i \le 10^9 1ai,bi109) indicating that the i i i-th order require the factory to deliver b i b_i bi products at the end of day a i a_i ai.

输出格式

For each test case output one line. If the factory can complete all orders output Yes \texttt{Yes} Yes, otherwise output No \texttt{No} No.

样例 #1

样例输入 #1

2
4 5
6 12
1 3
6 15
8 1
3 100
3 200
4 300
6 100

样例输出 #1

Yes
No

提示

For the first sample test case, the factory can produce 5 5 5 products each day.

  • At the end of day 1 1 1, there are 5 5 5 products in stock so the factory can complete the 2 2 2-nd order. After delivery, there are 2 2 2 products left in stock.
  • At the end of day 6 6 6, the factory produces 25 25 25 more products. There are 27 27 27 products in stock so the factory can complete the 1 1 1-st and the 3 3 3-rd order. After delivery, there are 0 0 0 products left in stock.
  • At the end of day 8 8 8, the factory produces 10 10 10 more products. There are 10 10 10 products in stock so the factory can complete the 4 4 4-th order. After delivery, there are 9 9 9 products left in stock.

For the second sample test case, the factory can produce 100 100 100 products each day.

  • At the end of day 3 3 3, there are 300 300 300 products in stock and the factory can complete the 1 1 1-st order. After delivery, there are 100 100 100 products left in stock.
  • At the end of day 4 4 4, the factory produces 100 100 100 more products. There are only 200 200 200 products in stock so the factory cannot complete the 2 2 2-nd order.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define inf 1e18
const int mod=1e9+7;
const int N=2e5+5;
int n,k;
struct node{
	int t,w;
}a[N];
void solve(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i].t>>a[i].w;
	}
	sort(a+1,a+n+1,[](node a,node b){
		return a.t==b.t?a.w<b.w:a.t<b.t;
	});
	int pre=0,sum=0;
	for(int i=1;i<=n;i++){
		sum+=(a[i].t-pre)*k;
		pre=a[i].t;
		if(sum>=a[i].w){
			sum-=a[i].w;
		}
		else{
			cout<<"No"<<endl;
			return;
		}
	}
	cout<<"Yes"<<endl;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int tt=1;
	cin>>tt;
	while(tt--) solve();
	return 0;
}
  • 25
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值