Submission
Status:
[PP-SSSSSSSSSSSSSSS]
Subtask/Task Score:
{0/100}
Score: 0
User: navysrimuang
Problemset: การจัดแนวข้อความ
Language: cpp
Time: 0.002 second
Submitted On: 2026-03-15 00:25:38
#include<bits/stdc++.h>
using namespace std;
int main(){
cin.tie(0)->sync_with_stdio(0);
int n,m;
cin >> n >> m;
int left = m;
int chleft = m;
vector<string> t;
for(int i = 0;i<n;i++){
string w;
cin >> w;
if(w.length()+1<= left){
t.push_back(w);
left -= (w.size()+1);
chleft -= w.size();
continue;
}else{
int sp = t.size()-1;
if(!sp){
for(string s : t) cout << s;
for(int k = 0;k<=chleft;k++) cout << " ";
cout << "\n";
t.clear();
t.push_back(w);
left = m - w.length() - 1;
chleft = m - w.length();
continue;
}
int per = chleft/sp;
int ext = chleft%sp;
for(int j = 0;j<t.size();j++){
cout << t[j];
if(j == t.size()-1) continue;
if(!j){
for(int k = 0;k<ext;k++) cout << " ";
}
for(int k = 0;k<per;k++) cout << " ";
}
cout << "\n";
t.clear();
t.push_back(w);
left = m - w.length() - 1;
chleft = m - w.length();
}
}
if(t.size())
for(string s : t) cout << s << " ";
return 0;
}
// foo.bar.koo.zaa....