Problem p02270 (C++) — buggy submission, verdict: Runtime Error

/**
 * ????????????????????? wi(i=0,1,...n???1) ??? n
??????????????????????????????????????¢?????????????????????????????????????????????????????????
k
??°????????????????????????????????????????????????????????£?¶??????? 0
?????\\??????????????????????????¨?????§??????????????????????????????????????????????????????????????§?????????
P
????¶?????????????????????????????????§????????? P
?????????????????????????????§??±?????§??????

n???k???wi
???????????????????????§?????????????????????????????????????????????????????§?????????
P
???????°????????±???????????????°????????????????????????????????????

??\\???
??????????????????????????° n ??¨?????????????????° k
????????????????????§??????????????????????¶???? n ?????? n
????????´??° wi ?????????????????????????????????????????????

??????
P ???????°???????????????????????????????????????????

??¶?´?
1???n???100,000
1???k???100,000
1???wi???10,000
??\\?????? 1
5 3
8
1
7
3
9
????????? 1
10
?????°????????????????????????????????????
{8,1},?????°????????????????????????????????????
{7,3}????????°???????????????????????????????????? {9}
???????????§????????§????????????????°??????? 10
??¨???????????????


??\\?????? 2
4 2
1
2
2
6
????????? 2
6
?????°????????????????????????????????????
{1,2,2},?????°???????????????????????????????????? {6}
????????§????????§????????????????°??????? 6 ??¨???????????????
 */

#include <algorithm>
#include <iostream>
#include <numeric>
#include <sstream>
#include <stack>
#include <vector>

bool isAllocated(std::vector<unsigned short> W, unsigned int P,
                 unsigned int k) {
  std::stack<unsigned int> Trucks;
  Trucks.push(0);
  for (const auto &e : W) {
    unsigned int Packet = Trucks.top();
    if (Packet + e > P) {
      Trucks.push(e);
    } else {
      Trucks.pop();
      Trucks.push(Packet + e);
    }
  }
  if (Trucks.size() <= k) {
    return true;
  } else {
    return false;
  }
}

int main(int argc, char const *argv[]) {
  std::string Param;
  std::istringstream Stream;
  unsigned int n = 0;
  unsigned int k = 0;
  std::vector<unsigned short> W;

  getline(std::cin, Param);
  Stream.str(Param);
  Stream >> n >> k;
  Stream.clear();
  for (size_t i = 0; i < n; i++) {
    getline(std::cin, Param);
    Stream.str(Param);
    unsigned short Wi = 0;
    Stream >> Wi;
    Stream.clear();
    W.push_back(Wi);
  }

  std::deque<unsigned int> Trucks{0};

  unsigned int Left = *(std::max_element(W.begin(), W.end()));
  unsigned int Right = std::accumulate(W.begin(), W.end(), 0);

  while (Left < Right) {
    unsigned int P = (Left + Right) / 2;
    if (isAllocated(W, P, k)) {
      Right = P;
    } else {
      Left = P + 1;
    }
  }

  std::cout << Left << std::endl;

  return 0;
}

Error: 0

Fixed submission:

/**
 * ????????????????????? wi(i=0,1,...n???1) ??? n
??????????????????????????????????????¢?????????????????????????????????????????????????????????
k ??°????????????????????????????????????????????????????????£?¶??????? 0
?????\\??????????????????????????¨?????§??????????????????????????????????????????????????????????????§?????????
P ????¶?????????????????????????????????§????????? P
?????????????????????????????§??±?????§??????

n???k???wi
???????????????????????§?????????????????????????????????????????????????????§?????????
P ???????°????????±???????????????°????????????????????????????????????

??\\???
??????????????????????????° n ??¨?????????????????° k
????????????????????§??????????????????????¶???? n ?????? n ????????´??° wi
?????????????????????????????????????????????

??????
P ???????°???????????????????????????????????????????

??¶?´?
1???n???100,000
1???k???100,000
1???wi???10,000
??\\?????? 1
5 3
8
1
7
3
9
????????? 1
10
?????°????????????????????????????????????
{8,1},?????°????????????????????????????????????
{7,3}????????°???????????????????????????????????? {9}
???????????§????????§????????????????°??????? 10 ??¨???????????????


??\\?????? 2
4 2
1
2
2
6
????????? 2
6
?????°????????????????????????????????????
{1,2,2},?????°???????????????????????????????????? {6}
????????§????????§????????????????°??????? 6 ??¨???????????????
 */

#include <algorithm>
#include <iostream>
#include <numeric>
#include <sstream>
#include <vector>

int main(int argc, char const *argv[]) {
  std::string Param;
  std::istringstream Stream;
  unsigned short n = 0;
  unsigned short k = 0;
  std::vector<unsigned short> W;

  getline(std::cin, Param);
  Stream.str(Param);
  Stream >> n >> k;
  Stream.clear();
  for (size_t i = 0; i < n; i++) {
    getline(std::cin, Param);
    Stream.str(Param);
    unsigned short Wi = 0;
    Stream >> Wi;
    Stream.clear();
    W.push_back(Wi);
  }

  std::vector<unsigned int> Trucks;

  unsigned int Average = (std::accumulate(W.begin(), W.end(), 0) + k - 1) / k;
  unsigned int p = 0;
  for (const auto &e : W) {
    if (p + e <= Average) {
      p += e;
    } else {
      Trucks.push_back(p);
      p = e;
      if (e == W.back()) {
        Trucks.push_back(e);
      }
    }
  }

  unsigned int P = *(std::max_element(Trucks.begin(), Trucks.end()));

  std::cout << P << std::endl;

  return 0;
}