Ankit_132

A

Sep 18th, 2023
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  7.  
  8. int main()
  9. {
  10.     _test
  11.     {
  12.         int n, k, mx;
  13.         cin>>n>>k>>mx;
  14.  
  15.         if(k>n || k>mx+1)
  16.         {
  17.             cout<<-1<<"\n";
  18.             continue;
  19.         }
  20.  
  21.         int x = 0;
  22.         int ans = 0;
  23.  
  24.         for(int i=0; i<n; i++)
  25.         {
  26.             if(x == k)      x = mx;
  27.             if(x > mx)      x=mx;
  28.             if(x == k)      x--;
  29.  
  30.             ans += x;
  31.  
  32.             x++;
  33.         }
  34.  
  35.         cout<<ans<<"\n";
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment