fork download
  1. subsetsum <- function(x) {
  2. if(0 %in% x)
  3. return(T)
  4. neg <- x[x < 0]
  5. pos <- x[x > 0]
  6. dif <- sum(pos) + sum(neg)
  7. if(dif == 0)
  8. return(T)
  9. if(0 %in% c(length(neg), length(pos)))
  10. return(F)
  11. for(i in seq_along(x)) {
  12. base <- subsetsum(x[-i])
  13. if(base) return(base)
  14. }
  15. return(base)
  16. }
  17.  
  18. library(stringr)
  19.  
  20. bonus <- "[-83314, -82838, -80120, -63468, -62478, -59378, -56958, -50061, -34791, -32264, -21928, -14988, 23767, 24417, 26403, 26511, 36399, 78055]
  21. [-92953, -91613, -89733, -50673, -16067, -9172, 8852, 30883, 46690, 46968, 56772, 58703, 59150, 78476, 84413, 90106, 94777, 95148]
  22. [-94624, -86776, -85833, -80822, -71902, -54562, -38638, -26483, -20207, -1290, 12414, 12627, 19509, 30894, 32505, 46825, 50321, 69294]
  23. [-83964, -81834, -78386, -70497, -69357, -61867, -49127, -47916, -38361, -35772, -29803, -15343, 6918, 19662, 44614, 66049, 93789, 95405]
  24. [-68808, -58968, -45958, -36013, -32810, -28726, -13488, 3986, 26342, 29245, 30686, 47966, 58352, 68610, 74533, 77939, 80520, 87195]
  25. [-97162, -95761, -94672, -87254, -57207, -22163, -20207, -1753, 11646, 13652, 14572, 30580, 52502, 64282, 74896, 83730, 89889, 92200]
  26. [-93976, -93807, -64604, -59939, -44394, -36454, -34635, -16483, 267, 3245, 8031, 10622, 44815, 46829, 61689, 65756, 69220, 70121]
  27. [-92474, -61685, -55348, -42019, -35902, -7815, -5579, 4490, 14778, 19399, 34202, 46624, 55800, 57719, 60260, 71511, 75665, 82754]
  28. [-85029, -84549, -82646, -80493, -73373, -57478, -56711, -42456, -38923, -29277, -3685, -3164, 26863, 29890, 37187, 46607, 69300, 84808]
  29. [-87565, -71009, -49312, -47554, -27197, 905, 2839, 8657, 14622, 32217, 35567, 38470, 46885, 59236, 64704, 82944, 86902, 90487]"
  30.  
  31. bonus <- str_replace_all(bonus, "[\\[\\],]", "")
  32.  
  33. input <- read.table(textConnection(bonus))
  34.  
  35. output <- apply(input, 1, subsetsum)
  36. cat(output, sep = "\n")
Success #stdin #stdout #stderr 4.99s 285888KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
/bin/bash: line 15: 28802 CPU time limit exceeded R --vanilla --quiet --slave --encoding=UTF-8 --file=/home/yvJvZw/prog.r > a.out