2 条题解

  • 0
    @ 2026-2-1 19:50:28

    一道十分()的题,按题意直接模拟即可。

    AC code:

    #include <bits/stdc++.h>
    using namespace std;
    
    int main() {
        int n;
        while (cin >> n) {
            long long sum = 0;
            for (int i = 0; i < n; ++i) {
                long long a;
                cin >> a;
                if (a < 0) {
                    sum += -a;
                }
            }
            cout << sum << endl;
        }
        return 0;
    }
    
    • 0
      @ 2026-1-5 0:26:21

      找出所有 ai<0a_i < 0 的食品累加它们的相反数即可。

      #include <bits/stdc++.h>
      using namespace std;
      int main()
      {
      	long long n, x, s = 0;
      	while (cin >> n)
      	{
      		s = 0;
      		for (int i = 1; i <= n; i++)
      		{
      			cin >> x;
      			if (x < 0) s -= x;
      		}
      		cout << s << endl;
      	}
      	return 0;
      }
      
      • 1

      [2026 January TFOJ Easy Round] Supermarket Promotion 1

      信息

      ID
      204
      时间
      1000ms
      内存
      512MiB
      难度
      1
      标签
      递交数
      8
      已通过
      4
      上传者