Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cmath>
- #include <algorithm>
- #define task "word"
- #define ld long double
- #define ll long long
- #define ull unsigned long long
- using namespace std;
- const int sizearr = 100003;
- string s[101];
- int n, k, cnt, j = 1;
- inline void fastIOfileinput(){
- ios_base:: sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- if(fopen(task".inp", "r")){
- freopen(task".inp", "r", stdin);
- freopen(task".out", "w", stdout);
- }
- if(fopen(task".in", "r")){
- freopen(task".in", "r", stdin);
- freopen(task".out", "w", stdout);
- }
- }
- inline void subtask(){
- ;
- }
- int main(){
- fastIOfileinput();
- cin >> n >> k;
- for(int i = 1; i <= n; ++i){
- cin >> s[i];
- cnt += s[i].length();
- if(cnt > k){
- for(int t = j; t < i; ++t) cout << s[t] << (t == i - 1 ? "\n" : " ");
- j = i;
- cnt = s[i].length();
- }
- }
- if(cnt <= k){
- for(int t = j; t <= n ; ++t) cout << s[t] << (t == n ? "" : " ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement