codeforces A. Level Statistics

在这里插入图片描述

题目

题意:

你有一个序列 p p ,一个序列 c c ,这两个序列要满足 c c 增加的小于 p p 且不能下降, c i < p i c_i<p_i

思路:

题意弄懂了,基本上做起来就没什么问题了,列几个 i f if 就行了。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef vector<int> veci;
typedef vector<ll> vecl;
typedef pair<int, int> pii;
template <class T>
inline void read(T &ret) {
    char c;
    int sgn;
    if (c = getchar(), c == EOF) return ;
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1:1;
    ret = (c == '-') ? 0:(c - '0');
    while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return ;
}
inline void out(int x) {
    if (x > 9) out(x / 10);
    putchar(x % 10 + '0');
}
int main() {
    int t, n;
    read(t);
    while (t--) {
        read(n);
        int max1 = 0, max2 = 0;
        bool flag = false;
        for (int i = 0; i < n; i++) {
            int x, y;
            read(x), read(y);
            if (x < y || x < max1 || y < max2 || y - max2 > x - max1) flag = true;
            max1 = x;
            max2 = y;
        }
        if (flag) printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}

发布了463 篇原创文章 · 获赞 27 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/weixin_45031646/article/details/105469022
今日推荐