Language: C++

#include <iostream>
using namespace std;

#define MAX 100000
int n, k;
long long T[MAX];

int check(long long P){
  int i = 0;
  for(int j = 0; j < k; j++){
    long long s = 0;
    while (s + T[i] <= P) {
      s += T[i];
      i++;
      if (i == n) {
        return n;
      }
    }
  }
  return i;
}


long long solve(){
  long long left = 0;
  long long right = 100000 * 100000;
  long long mid;

  while (right - left > 1) {
    mid = (right + left) / 2;
    int v = check(mid);
    if (v >= n) {
      right = mid;
    }else{
      left = mid;
    }
  }

  return right;
}


int main(int argc, char const *argv[]) {
  cin >> n >> k;
  for(int i = 0; i < n; i++)  cin >> T[i];
  long long ans = solve();
  cout << ans << endl;
  return 0;
}
#include <iostream>
using namespace std;

#define MAX 100000
int n, k;
long long T[MAX];

int check(long long P){
  int i = 0;
  for(int j = 0; j < k; j++){
    long long s = 0;
    while (s + T[i] <= P) {
      s += T[i];
      i++;
      if (i == n) {
        return n;
      }
    }
  }
  return i;
}


long long solve(){
  long long left = 0;
  long long right = 100000 * 100000;
  long long mid;

  while (right - left > 1) {
    mid = (right + left) / 2;
    int v = check(mid);
    if (v >= n) {
      right = mid;
    }else{
      left = mid;
    }
  }

  return right;
}


int main(int argc, char const *argv[]) {
  cin >> n >> k;
  for(int i = 0; i < n; i++)  cin >> T[i];
  long long ans = solve();
  cout << ans << endl;
  return 0;
}

Compiler output:
a.cc: In function 'long long int solve()':
a.cc:26:28: warning: integer overflow in expression of type 'int' results in '1410065408' [-Woverflow]
   26 |   long long right = 100000 * 100000;
      |                     ~~~~~~~^~~~~~~~
a.cc: At global scope:
a.cc:54:5: error: redefinition of 'int n'
   54 | int n, k;
      |     ^
a.cc:5:5: note: 'int n' previously declared here
    5 | int n, k;
      |     ^
a.cc:54:8: error: redefinition of 'int k'
   54 | int n, k;
      |        ^
a.cc:5:8: note: 'int k' previously declared here
    5 | int n, k;
      |        ^
a.cc:55:11: error: redefinition of 'long long int T [100000]'
   55 | long long T[MAX];
      |           ^
a.cc:6:11: note: 'long long int T [100000]' previously declared here
    6 | long long T[MAX];
      |           ^
a.cc:57:5: error: redefinition of 'int check(long long int)'
   57 | int check(long long P){
      |     ^~~~~
a.cc:8:5: note: 'int check(long long int)' previously defined here
    8 | int check(long long P){
      |     ^~~~~
a.cc:73:11: error: redefinition of 'long long int solve()'
   73 | long long solve(){
      |           ^~~~~
a.cc:24:11: note: 'long long int solve()' previously defined here
   24 | long long solve(){
      |           ^~~~~
a.cc: In function 'long long int solve()':
a.cc:75:28: warning: integer overflow in expression of type 'int' results in '1410065408' [-Woverflow]
   75 |   long long right = 100000 * 100000;
      |                     ~~~~~~~^~~~~~~~
a.cc: At global scope:
a.cc:92:5: error: redefinition of 'int main(int, const char**)'
   92 | int main(int argc, char const *argv[]) {
      |     ^~~~
a.cc:43:5: note: 'int main(int, const char**)' previously defined here
   43 | int main(int argc, char const *argv[]) {
      |     ^~~~