Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Vehicle {
- public static void main(String[] args) {
- Integer[] outgoing = {2710,300,2500,2800,700};
- Integer[] returning = {2200,289,490};
- int l1=0,l2=0;
- Arrays.sort(outgoing, Collections.reverseOrder());
- Arrays.sort(returning);
- int range = 3000;
- int max = 0;
- int out = 0;
- int ret = 0;
- while(l1<outgoing.length && l2<returning.length) {
- int sum = outgoing[l1]+returning[l2];
- if (sum<=range && sum>max) {
- max = sum;
- out = outgoing[l1];
- ret = returning[l2];
- }
- if(sum>range) {
- l1++;
- } else {
- l2++;
- }
- }
- System.out.println(max);
- System.out.println(out);
- System.out.println(ret);
- }
- }
Add Comment
Please, Sign In to add comment