Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // NgJaBach: Forever Meadow <3
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long int ll;
- typedef unsigned long long ull;
- #define pb push_back
- #define pob pop_back
- #define mp make_pair
- #define upb upper_bound
- #define lwb lower_bound
- #define bend(a) a.begin(),a.end()
- #define rev(x) reverse(bend(x))
- #define mset(a) memset(a, 0, sizeof(a))
- #define fi first
- #define se second
- #define gcd __gcd
- #define getl(s) getline(cin, s);
- #define setpre(x) fixed << setprecision(x)
- #define endl '\n'
- const int N=200050,M=1000000007;
- const ll INF=1e18+7;
- int main(){
- ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);
- freopen("word.in","r",stdin);
- freopen("word.out","w",stdout);
- int n,k,cnt=0,m;
- string s,str;
- str.clear();
- cin>>n>>k;
- for(int i=0;i<n;++i){
- cin>>s;
- m=s.size();
- if(cnt+m<=k){
- cnt+=m;
- if(!str.empty()) str.pb(' ');
- str+=s;
- }
- else{
- cout<<str<<endl;
- str=s; cnt=m;
- }
- }
- cout<<str;
- return 0;
- }
- /*
- ==================================+
- INPUT: |
- ------------------------------ |
- ------------------------------ |
- ==================================+
- OUTPUT: |
- ------------------------------ |
- ------------------------------ |
- ==================================+
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement