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. cur_ans += ((1 + i) * i / 2) * (cur_x + 1) + ((0 + cur_x) * (cur_x + 1) / 2) * (i + 1);
  21. ans = max(ans, cur_ans);
  22. }
  23. printf("%lld", ans);
  24. }
Success #stdin #stdout 0s 15240KB
stdin
2 3
stdout
25