题解:P11641 【MX-X8-T0】「TAOI-3」分数

思路

根据题意直接模拟,先读入数组然后判断总和并输出答案。

在这里我们有几个优化的点:

代码

这个代码是赛时代码。

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int n, T, z, x, y;
int main()
{
    cin >> n >> T;
    for (int i = 1; i <= n; i++)
    {
        cin >> z;
        x += z;
    }
    if (x < T)
    {
        cout << x << endl;
        return 0;
    }
    for (int i = 1; i <= n; i++)
    {
        cin >> z;
        y += z;
    }
    cout << y << endl;
    return 0;
}