#include #include using namespace std; int main() { int n, k, now = 0; string a[101]; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i++) { if (now + a[i].size() <= k) { if (now > 0) { cout << " "; } } else { cout << endl; now = 0; } cout << a[i]; now += a[i].size(); } }