Rezultati

Up. imeNalogaJezikRezultatČas oddaje
pokosimo-2018 Priprava naloge Java 100/100OK 19. apr '18 @ 17:19

Test Točke Porabljen spomin Porabljen čas Status
#1 11/11 93,680 MiB 1,628 s OK
#2 11/11 85,180 MiB 1,247 s OK
#3 11/11 87,934 MiB 1,340 s OK
#4 11/11 85,055 MiB 1,309 s OK
#5 11/11 90,531 MiB 1,560 s OK
#6 11/11 91,531 MiB 1,604 s OK
#7 11/11 32,543 MiB 0,000 s OK
#8 11/11 84,422 MiB 1,329 s OK
#9 12/12 35,086 MiB 0,000 s OK

Ocenjevani program (naloge.java):
import java.util.*;

public class naloge {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long k = sc.nextLong();
        int n = sc.nextInt();
        long[][] tab = new long[2][n];
        long zacCas = 0, zacPom = 0, vsotaPom = 0, maxCena;
        int index = 0;
        for(int i=0; i<n; ++i) {
            tab[0][i] = sc.nextLong();
            tab[1][i] = sc.nextLong();
            if(zacCas < k) {
                zacCas += tab[0][i];
                zacPom += tab[1][i];
                index = i;
            }
            vsotaPom += tab[1][i];
        }
        if(zacCas < k) {
            System.out.println("Tekma bo polom");
            return;
        }
        maxCena = vsotaPom - zacPom;
        int zacetek = 0;
        long cas = zacCas, pomembnost = zacPom;
        for(int i=index+1; i<n; ++i) {
            cas += tab[0][i];
            pomembnost += tab[1][i];
            while(zacetek < i && cas - tab[0][zacetek] >= k) {
                cas -= tab[0][zacetek];
                pomembnost -= tab[1][zacetek];
                zacetek++;
            }
            maxCena = Math.max(maxCena, vsotaPom - pomembnost);
        }
        System.out.printf("%d%n", maxCena);
    }
}