RE求救
查看原帖
RE求救
531306
剑仙不求人楼主2021/12/5 10:51
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
struct abc {
    int b, e, t;
};
bool cmp(abc x,abc y) {
    return x.e <= y.e;
}
abc p[5005];
int n, h, s, ans;
bool a[30005];
int main() {
    scanf("%d%d", &n, &h);
    for (int i = 1; i <= h; i++) {
        scanf("%d%d%d", &p[i].b, &p[i].e, &p[i].t);
    }
    sort(p + 1, p + 1 + h, cmp);
    for (int i = 1; i <= h; i++) {
        s = 0;
        for (int j = p[i].b; j <= p[i].e; j++) {
            s += a[j];
        }
        if (s >= p[i].t) {
            continue;
        }
        for (int j = p[i].e; j >= p[i].b; j--) {
            if (s == p[i].t) {
                break;
            }
            if (!a[j]) {
                ans++;
                a[j] = 1;
                s++;
            }
        }
    }
    printf("%d", ans);
    return 0;
}

样例3,6出错。

2021/12/5 10:51
加载中...