Problem p03646 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// #define MOD 1000000007
// #define INF 1000000001

using namespace std;
// typedef unsigned long long ull;
typedef long long ll;

template <class T> ostream &operator<<(ostream &o, const vector<T> &obj) {
  o << "[";
  for (int i = 0; i < (int)obj.size(); ++i)
    o << (i > 0 ? ", " : "") << obj[i];
  o << "]";
  return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &obj) {
  o << "(" << obj.first << ", " << obj.second << ")";
  return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U> &obj) {
  o << "{";
  for (auto itr = obj.begin(); itr != obj.end(); ++itr)
    o << (itr != obj.begin() ? ", " : "") << *itr;
  o << "}";
  return o;
}
template <class T> ostream &operator<<(ostream &o, const set<T> &obj) {
  o << "{";
  for (auto itr = obj.begin(); itr != obj.end(); ++itr)
    o << (itr != obj.begin() ? ", " : "") << *itr;
  o << "}";
  return o;
}

void print() { cout << "\n"; }
template <class Head, class... Body> void print(Head head, Body... body) {
  cout << head << " ";
  print(body...);
}

int main(int argc, char const *argv[]) {
  ll K;
  cin >> K;
  // int N = 10;
  int N;
  cin >> N;
  int m = K % N;
  for (int i = 0; i < N; ++i) {
    ll a;
    if (i < m) {
      a = N + K / N;
    } else {
      a = N - 1 - m + K / N;
    }
    cout << a << (i < N - 1 ? " " : "");
  }
  cout << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// #define MOD 1000000007
// #define INF 1000000001

using namespace std;
// typedef unsigned long long ull;
typedef long long ll;

template <class T> ostream &operator<<(ostream &o, const vector<T> &obj) {
  o << "[";
  for (int i = 0; i < (int)obj.size(); ++i)
    o << (i > 0 ? ", " : "") << obj[i];
  o << "]";
  return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &obj) {
  o << "(" << obj.first << ", " << obj.second << ")";
  return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U> &obj) {
  o << "{";
  for (auto itr = obj.begin(); itr != obj.end(); ++itr)
    o << (itr != obj.begin() ? ", " : "") << *itr;
  o << "}";
  return o;
}
template <class T> ostream &operator<<(ostream &o, const set<T> &obj) {
  o << "{";
  for (auto itr = obj.begin(); itr != obj.end(); ++itr)
    o << (itr != obj.begin() ? ", " : "") << *itr;
  o << "}";
  return o;
}

void print() { cout << "\n"; }
template <class Head, class... Body> void print(Head head, Body... body) {
  cout << head << " ";
  print(body...);
}

int main(int argc, char const *argv[]) {
  ll K;
  cin >> K;
  int N = 50;
  cout << N << endl;
  // int N; cin >> N;
  int m = K % N;
  for (int i = 0; i < N; ++i) {
    ll a;
    if (i < m) {
      a = N + K / N;
    } else {
      a = N - 1 - m + K / N;
    }
    cout << a << (i < N - 1 ? " " : "");
  }
  cout << endl;
  return 0;
}