Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. List < List < Integer >> optimalUtilizationOnlyMani2(int deviceCapacity, List < List < Integer >> foregroundAppList, List < List < Integer >> backgroundAppList) {
  2. if (foregroundAppList == null || foregroundAppList.isEmpty() || backgroundAppList == null || backgroundAppList.isEmpty()) {
  3. return new ArrayList < >();
  4. }
  5.  
  6. // map of memory and id of foreground app, id of background app
  7. List < List < Integer >> output = new ArrayList < >();
  8.  
  9. Integer maximum_memory = Integer.MIN_VALUE;
  10.  
  11. for (List < Integer > forgroundApp: foregroundAppList) {
  12. for (List < Integer > backgroundApp: backgroundAppList) {
  13. Integer combined_memory = forgroundApp.get(1) + backgroundApp.get(1);
  14. if (combined_memory <= deviceCapacity && combined_memory >= maximum_memory) {
  15. if (combined_memory > maximum_memory) {
  16. maximum_memory = combined_memory;
  17. output.clear();
  18. }
  19.  
  20. output.add(Arrays.asList(forgroundApp.get(0), backgroundApp.get(0)));
  21. }
  22. }
  23.  
  24. }
  25.  
  26. return output;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement