A - The Third Cup is Free

水。

 1 #include<bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 const int maxn = 1e5 + 10;
 6 
 7 int n;
 8 int arr[maxn];
 9 
10 int main()
11 {
12     int t;
13     scanf("%d", &t);
14     for(int cas = 1; cas <= t; ++cas)
15     {
16         scanf("%d", &n);
17         for(int i = 1; i <= n; ++i) scanf("%d", arr + i);
18         sort(arr + 1, arr + 1 + n);
19         int ans = 0;
20         int cnt = 0;
21         for(int i = n; i >= 1; --i)
22         {
23             cnt++;
24             if(cnt == 3)
25             {
26                 arr[i] = 0;
27                 cnt = 0;
28             }
29             ans += arr[i];
30         }
31         printf("Case #%d: %d\n", cas, ans);
32     }
33     return 0;
34 }
View Code

相关文章:

  • 2021-06-26
  • 2021-11-26
  • 2021-12-19
  • 2022-01-30
  • 2021-04-10
  • 2021-06-18
  • 2021-11-13
  • 2021-04-21
猜你喜欢
  • 2021-12-07
  • 2022-01-29
  • 2021-09-10
  • 2022-03-08
  • 2021-04-14
  • 2022-01-02
相关资源
相似解决方案