Codeforces 813 A The Contest

本文解析了CodeForces上的一道A级题目,通过计算完成所有任务所需的总时间,并找到能够覆盖这一总时间的最早时间段来确定提交时机。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目地址:http://codeforces.com/contest/813/problem/A
题意:题目就是说有n道题,分别告诉你每道题你解决需要的时间,然后告诉你在m个时间段内可以提交,让你告诉他,他什么时候可以提交完所有的题目,提交不算时间。
思路:其实你会发现因为提交不要时间所有你先把解决所有题目的总时间算出来,再找这个大于或者包括这个总时间的最早的时间段就好了。

#include <iostream>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#define N 1000
#define inf 0x3f3f3f3f
using namespace std;
int main() {
    cin.sync_with_stdio(false);
    int n, m;
    int sum, num, a, b;
    while (cin >> n) {
        sum = 0;
        for (int i = 0; i < n; i++) {
            cin >> num;
            sum += num;
        }
        cin >> m;
        int flag = 1;
        for (int i = 0; i < m; i++) {
            cin >> a >> b;
            if (b >= sum&&flag) {
                flag = 0;
                cout << max(sum, a) << endl;
            }
        }
        if (flag) {
            cout << -1 << endl;
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值