P9556 [SDCPC2023] A-Orders 题解

发布时间 2023-08-20 15:26:18作者: xvl

题目传送门

一道模拟题。

可以命名一个订单的结构体,然后将订单的结束时间进行排序。用一个变量模拟货物的数量,每遇到一个订单,货物的数量就会加上距离上一个订单的天数乘上 \(k\)。即对于第 \(i\) 个订单,距离第 \(i-1\) 订单货物数量增加了 \((a_{i}-a_{i-1})\times k\)

如果在模拟过程中出现货物数量不够交付,输出 No

Code

#include <bits/stdc++.h>

namespace xvl_ { 
    #define ll long long
    #define IMAX 1e9
    #define LMAX 1e18
    void debug() { std :: cerr << "debug" << "\n"; } 
    template <typename T> inline T Max(T a, T b) { return a > b ? a : b; }
    template <typename T> inline T Min(T a, T b) { return a < b ? a : b; }
    template <typename T, typename... Args> inline T Max(T a, Args... args) { return a > Max(args...) ? a : Max(args...); }
    template <typename T, typename... Args> inline T Min(T a, Args... args) { return a < Min(args...) ? a : Min(args...); }
}
using namespace std;
using namespace xvl_;
struct order { int x, y; } a[105];
ll T, n, k, sum;
bool flag;
bool cmp(order tmp1, order tmp2) { return tmp1.x < tmp2.x;  }
int main() {
    /*
    freopen("InName.in", "r", stdin);
    freopen("OutName.out", "w", stdout);
    */
    ios :: sync_with_stdio(0);
    cin >> T;
    while (T--) {
        flag = 1, sum = 0;
        cin >> n >> k;
        for (int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y;
        sort(a + 1, a + 1 + n, cmp);
        for (int i = 1; i <= n; i++) {
            sum += (a[i].x - a[i - 1].x) * k;
            if (sum < a[i].y) flag = 0;
            else sum -= a[i].y;
        }
        if (flag) cout << "Yes\n";
        else cout << "No\n";
    }
    return 0;
}