Artim_Anton

Untitled

Apr 6th, 2021 (edited)
937
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import 'package:trotter/trotter.dart';
  2.  
  3. int chooseBestDistance(int t, int k, List<int> ls) {
  4.  if((t>=0) && (k>=1) && (ls.length!=0)){
  5.   var max = 0;
  6.    var dist = 0;
  7.     var combos = Combinations(k, ls);
  8.     for (final combo in combos()) {
  9.       for(int i=1; i<=k; i++){dist=dist+combo[i];}
  10.       if ((dist>max) && (dist<=t) ){max = dist;}
  11.     }
  12.          
  13.    if (max!=0 && (k<=ls.length)) {
  14.      return max;
  15.    }else{
  16.     return -1;
  17.     }
  18.   }
  19. }
  20.  
  21. void main(){
  22. chooseBestDistance(174, 3, [51, 56, 58, 59, 61]); //173
  23. chooseBestDistance(163, 3, [50]); // -1
  24. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×