fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define endl '\n'
  4. #define int long long
  5.  
  6. const int MOD = 1e9+7;
  7. const int INF = LLONG_MAX/2;
  8.  
  9. signed main() {
  10. ios::sync_with_stdio(false); cin.tie(NULL);
  11. int t;
  12. cin >> t;
  13. while(t--) {
  14. long long a,b,n;
  15. cin >> a >> b>>n;
  16. vector<long long>x(n);
  17. for(int i=0;i<n;i++){
  18. cin>>x[i];
  19. }
  20. long long maxtime=b;
  21. for(int i=0;i<n;i++){
  22. maxtime+=min(x[i],a-1);
  23. }
  24. cout<<maxtime<<endl;
  25. }
  26. }
  27.  
Success #stdin #stdout 0s 5292KB
stdin
2
5 3 3
1 1 7
7 1 5
1 2 5 6 8
stdout
9
21