fork(1) download
  1. #include <cstdio>
  2. #include <algorithm>
  3.  
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int m, b;
  10. scanf("%d %d", &m, &b);
  11. long long ans = max((1 + b) * b / 2, (1 + b * m) * b * m / 2);
  12. for (int i = 1; i < b; i++)
  13. {
  14. long long cur_ans = 0;
  15. int cur_x = -1 * (i - b) * m;
  16. if (cur_x == 0)
  17. {
  18. continue;
  19. }
  20. for (int x = 0; x <= cur_x; x++)
  21. {
  22. cur_ans += (1 + i) * i / 2 + x * (i + 1);
  23. }
  24. ans = max(ans, cur_ans);
  25. }
  26. printf("%lld", ans);
  27. }
Success #stdin #stdout 0s 16064KB
stdin
2 3
stdout
25