fork download
  1. #include<bits/stdc++.h>
  2. #define f1(i, n) for(int i=1;i<=n;++i)
  3. #define f0(i, n) for(int i=0;i<n;++i)
  4. #define ull unsigned long long
  5. #define ll long long
  6. #define rev(a) reverse(a.begin(),a.end())
  7. #define all(x) x.begin(),x.end()
  8. #define so(A, n) sort(A+1, A+n+1)
  9. using namespace std;
  10. const int maxn = 1e6 + 1;
  11. const int N = 2e5 + 1;
  12. const ll MOD = 1e9 + 7;
  13. ll A[N], pre[N];
  14. string multiply(string num1, string num2) {
  15. int len1 = num1.size();
  16. int len2 = num2.size();
  17. vector<int> result(len1 + len2, 0);
  18.  
  19. // Nhân từng chữ số
  20. for (int i = len1 - 1; i >= 0; i--) {
  21. for (int j = len2 - 1; j >= 0; j--) {
  22. int mul = (num1[i] - '0') * (num2[j] - '0');
  23. int pos1 = i + j;
  24. int pos2 = i + j + 1;
  25. int sum = mul + result[pos2];
  26.  
  27. result[pos2] = sum % 10;
  28. result[pos1] += sum / 10;
  29. }
  30. }
  31.  
  32. // Chuyển vector kết quả thành chuỗi
  33. string product = "";
  34. for (int digit : result) {
  35. if (!(product.empty() && digit == 0)) {
  36. product += to_string(digit);
  37. }
  38. }
  39.  
  40. return product.empty() ? "0" : product;
  41. }
  42. int compareBigNumbers(string a, string b) {
  43. // Bỏ số 0 ở đầu (nếu có)
  44. a.erase(0, a.find_first_not_of('0'));
  45. b.erase(0, b.find_first_not_of('0'));
  46.  
  47. // So độ dài trước
  48. if (a.length() > b.length()) return 1;
  49. if (a.length() < b.length()) return -1;
  50.  
  51. // Nếu độ dài bằng nhau thì so từng chữ số
  52. for (size_t i = 0; i < a.length(); ++i) {
  53. if (a[i] > b[i]) return 1;
  54. if (a[i] < b[i]) return -1;
  55. }
  56.  
  57. return 0; // Hai số bằng nhau
  58. }
  59. int main() {
  60. ios_base::sync_with_stdio(0);
  61. cin.tie(0);
  62. cout.tie(0);
  63. int n;
  64. cin >> n;
  65. f1(i, n) {
  66. cin >> A[i];
  67. pre[i] = pre[i - 1] + A[i];
  68. }
  69. ll pos = 1;
  70. string max_sum = "0";
  71. for (ll i = 1; i < n; ++i) {
  72. string motcaigiday = multiply(to_string(pre[i]), to_string((pre[n] - pre[i])));
  73. int comp = compareBigNumbers(motcaigiday, max_sum);
  74. if (comp == 1) {
  75. max_sum = motcaigiday;
  76. pos = i;
  77. }
  78. }
  79. cout << pos;
  80.  
  81.  
  82. }
  83.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
1