(SPOJ) Semente - Solution 2

Link to the problem: http://br.spoj.com/problems/SEMENT14/


If you want to see another solution for this problem, click here.


import java.io.*;
import java.util.*;

class solucao {
    public void process() throws NumberFormatException, IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
       
        String line = br.readLine();
        String[] s = line.split(" ");
        int numBlocks = Integer.parseInt(s[0]);
        int numDrops = Integer.parseInt(s[1]);
       
        line = br.readLine();
        s = line.split(" ");
       
        int max = 0;
        int lastDay = 1;
        for (int i = 0; i < numDrops; i++) {
            int diff = Integer.parseInt(s[i]) - lastDay;
            if (i == 0) {
                max = Math.max(max, diff);
            }
            else {
                max = Math.max(max, (int)Math.floor((double)diff/2));
            }
            lastDay = Integer.parseInt(s[i]);
        }
        max = Math.max(max, numBlocks-lastDay);
       
        bw.write(max+"\n");
           
        bw.flush();
        bw.close();
       
        return;
    }
   
    public static void main(String[] args) throws NumberFormatException, IOException {
        solucao m = new solucao();
        m.process();
       
        System.exit(0);
    }
}

Comments

Popular posts from this blog

(Coderbyte) Dash Insert II - Solução

(Coderbyte) Run Length - Solução

(Coderbyte) Counting Minutes I - Solução