Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- import java.text.*;
- import java.math.*;
- import java.util.regex.*;
- public class Solution {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- int g = in.nextInt();
- for(int a0 = 0; a0 < g; a0++){
- int n = in.nextInt();
- int m = in.nextInt();
- int x = in.nextInt();
- int[] a = new int[n];
- for(int a_i=0; a_i < n; a_i++){
- a[a_i] = in.nextInt();
- }
- int[] b = new int[m];
- for(int b_i=0; b_i < m; b_i++){
- b[b_i] = in.nextInt();
- }
- int tmp = 0;
- int pointer = 0;
- int count = 0;
- while(pointer < n){
- if(tmp+a[pointer] > x){
- pointer--;
- break;
- }
- tmp += a[pointer];
- pointer++;
- count++;
- }
- if(pointer >= n){
- pointer = n-1;
- }
- pointer++;
- int max = count;
- int pointer2 = 0;
- while(pointer2 < m){
- while(tmp <= x){
- if(tmp+b[pointer2] > x){
- break;
- }
- tmp += b[pointer2];
- count++;
- pointer2++;
- if(pointer2 == m){
- break;
- }
- }
- max = count > max ? count : max;
- count--;
- pointer--;
- if(pointer < 0){
- break;
- }
- tmp -= a[pointer];
- }
- System.out.println(max);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement