C++ very intuitive


#1
#include<bits/stdc++.h>
int Solution::paint(int P, int k, vector<int> &A) {
    const int mod = 10000003;
    int n = A.size();
    long long sum = accumulate(begin(A), end(A), 0, [](auto a, auto b) {
        return (a + b) % mod;
    });
    long long l = *max_element(begin(A), end(A)), r = sum;

         while(l < r) {
            long m = l + (r - l) / 2, total = 0, x = 1;
            for(int i = 0; i < n; i++) {
            total = (total + A[i]) % mod;
            if(total > m) {
                total = A[i], x++;
            }
         }
        if(x > P) l = m + 1;
        else r = m;
    }
    return l*k % mod;
}