Codeforces 813A 暴力

传送门:题目

题意:

一个人做n题,每道题都要花费一些时间解决,给你每道题花费的时间。但是他只能在特定的时间段交题,交题不需要时间,给你每个时间段,问它最早完成考试的时间点。

题解:

暴力就好,我们统计出他做题的总用时,我们规定只有他在做完最后一道题才能交题,这样比较容易,只交题一次,然后判断最后一次能不能交成功就好了。

AC代码:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define debug(x) cout<<#x<<" = "<<x<<endl;
#define INF 0x3f3f3f3f
using namespace std;

int main(void) {
    int n, m, sum = 0, l, r, temp, mmax = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> temp, sum += temp;
    cin >> m;
    for (int i = 0; i < m; i++)
        cin >> l >> r, mmax = max(r, mmax);

    if (sum > mmax)
        cout << -1 << endl;
    else
        cout << max(sum, l) << endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/shadandeajian/article/details/81668245