fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios::sync_with_stdio(0); cin.tie(0);
  6. int t; cin >> t; while (t--) {
  7. int n, m; cin >> n >> m;
  8. int sum = 0;
  9. int ans = n;
  10. for (int i = 0; i < n; i++) {
  11. string s; cin >> s;
  12. if (sum + s.size() > m and ans == n) {
  13. ans = i;
  14. }
  15. sum += s.size();
  16. }
  17. cout << ans << endl;
  18. }
  19. return 0;
  20. }
Success #stdin #stdout 0s 5288KB
stdin
5
3 1
a
b
c
2 9
alpha
beta
4 12
hello
world
and
codeforces
3 2
ab
c
d
3 2
abc
ab
a
stdout
1
2
2
1
0