#include <bits/stdc++.h>

bool isPossible(vector<int> arr, int n, int m, long long mid){

long long painterCount = 1;

long long timeSum = 0;

for(int i = 0; i < n; i++){

if(timeSum + arr[i] <= mid){

timeSum += arr[i];

}

else{

painterCount++;

if(painterCount > m || arr[i] > mid){

return false;

}

timeSum = arr[i];

}

}

return true;

}

long long minTime(vector<int>& board, int N, int A, int B)

{

long long s = 0;

long long sum=0;

for(int i = 0; i<N; i++){

sum += board[i];

}

long long e = sum;

long long ans = -1;

long long mid = s + (e -s)/2;

while(s <= e){

if(isPossible(board, N ,A,mid)){

ans = mid*B;

e = mid-1;

}

else{

s = mid +1;

}

mid = s + (e - s)/2;

}

return ans;

}