CSES - KILO 2016 4/5 - Results
Submission details
Task:Blocks
Sender:PILIPOJAT!!
Submission time:2016-09-27 17:59:06 +0300
Language:Java
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.10 sdetails
#2ACCEPTED0.10 sdetails
#3ACCEPTED0.10 sdetails
#4ACCEPTED0.09 sdetails
#5ACCEPTED0.13 sdetails
#6ACCEPTED0.11 sdetails
#7ACCEPTED0.10 sdetails
#8ACCEPTED0.11 sdetails
#9ACCEPTED0.10 sdetails
#10ACCEPTED0.11 sdetails
#11ACCEPTED0.10 sdetails
#12ACCEPTED0.11 sdetails
#13ACCEPTED0.13 sdetails
#14ACCEPTED0.11 sdetails
#15ACCEPTED0.10 sdetails
#16ACCEPTED0.11 sdetails
#17ACCEPTED0.10 sdetails
#18ACCEPTED0.10 sdetails
#19ACCEPTED0.11 sdetails
#20ACCEPTED0.10 sdetails
#21ACCEPTED0.13 sdetails
#22ACCEPTED0.10 sdetails
#23ACCEPTED0.11 sdetails
#24ACCEPTED0.11 sdetails
#25ACCEPTED0.10 sdetails
#26ACCEPTED0.11 sdetails
#27ACCEPTED0.10 sdetails
#28ACCEPTED0.11 sdetails
#29ACCEPTED0.10 sdetails
#30ACCEPTED0.10 sdetails

Code

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

//package cses5teht;

import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;

/**
 *
 * @author eamiller
 */
public class Cses5teht {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        IO io = new IO();
        
        int AT = 0;
        int GC = 0;
        
        int l = io.nextInt();
        int[] blocks =  new int[l];
        
        int torneja = 1;
        ArrayList<Integer> huiput = new ArrayList<>();
        
        for(int i = 0; i<l; i++) {
            blocks[i] = io.nextInt();
        }
        
        huiput.add(blocks[0]);
        int pieninMahdollinenHuippu=Integer.MAX_VALUE;
        int indeksi =0 ;
        
        for(int i = 1; i<l; i++) {
            pieninMahdollinenHuippu=Integer.MAX_VALUE;
            boolean huiputOnPienempia = true;
//            for(int h : huiput){
//                indeksi++;
//                if(h > blocks[i]){
//                    huiputOnPienempia = false;
//                    apuIndeksi = indeksi;
//                    if(h < pieninMahdollinenHuippu){
//                        pieninMahdollinenHuippu = h;
//                    }
//                }
//            }
            
            for(int j=0; j<huiput.size(); j++) {
                if(huiput.get(j) > blocks[i]){
                    huiputOnPienempia = false;
                    if(huiput.get(j) < pieninMahdollinenHuippu){
                        pieninMahdollinenHuippu = huiput.get(j);
                        indeksi = j;
                    }
                }
            }
            huiput.add(blocks[i]);
            if(!huiputOnPienempia){
                huiput.remove(indeksi);
            }
        }
        
        System.out.println(huiput.size());
        
    }
    
    
    
    
    
    
    
    public static class IO extends PrintWriter {
	private InputStreamReader r;
	private static final int BUFSIZE = 1 << 15;
	private char[] buf;
	private int bufc;
	private int bufi;
	private StringBuilder sb;
	
	public IO() {
		super(new BufferedOutputStream(System.out));
		r = new InputStreamReader(System.in);
		
		buf = new char[BUFSIZE];
		bufc = 0;
		bufi = 0;
		sb = new StringBuilder();
	}
	
	private void fillBuf() throws IOException {
		bufi = 0;
		bufc = 0;
		while(bufc == 0) {
			bufc = r.read(buf, 0, BUFSIZE);
			if(bufc == -1) {
				bufc = 0;
				return;
			}
		}
	}
	
	private boolean pumpBuf() throws IOException {
		if(bufi == bufc) {
			fillBuf();
		}
		return bufc != 0;
	}
	
	private boolean isDelimiter(char c) {
		return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f';
	}
	
	private void eatDelimiters() throws IOException {
		while(true) {
			if(bufi == bufc) {
				fillBuf();
				if(bufc == 0) throw new RuntimeException("IO: Out of input.");
			}
			
			if(!isDelimiter(buf[bufi])) break;
			++bufi;
		}
	}
	
	public String next() {
		try {
			sb.setLength(0);
			
			eatDelimiters();
			int start = bufi;
			
			while(true) {
				if(bufi == bufc) {
					sb.append(buf, start, bufi - start);
					fillBuf();
					start = 0;
					if(bufc == 0) break;
				}
				
				if(isDelimiter(buf[bufi])) break;
				++bufi;
			}
			
			sb.append(buf, start, bufi - start);
			
			return sb.toString();
		} catch(IOException e) {
			throw new RuntimeException("IO.next: Caught IOException.");
		}
	}
	
	public int nextInt() {
		try {
			int ret = 0;
			
			eatDelimiters();
			
			boolean positive = true;
			if(buf[bufi] == '-') {
				++bufi;
				if(!pumpBuf()) throw new RuntimeException("IO.nextInt: Invalid int.");
				positive = false;
			}
			
			boolean first = true;
			while(true) {
				if(!pumpBuf()) break;
				if(isDelimiter(buf[bufi])) {
					if(first) throw new RuntimeException("IO.nextInt: Invalid int.");
					break;
				}
				first = false;
				
				if(buf[bufi] >= '0' && buf[bufi] <= '9') {
					if(ret < -214748364) throw new RuntimeException("IO.nextInt: Invalid int.");
					ret *= 10;
					ret -= (int)(buf[bufi] - '0');
					if(ret > 0) throw new RuntimeException("IO.nextInt: Invalid int.");
				} else {
					throw new RuntimeException("IO.nextInt: Invalid int.");
				}
				
				++bufi;
			}
			
			if(positive) {
				if(ret == -2147483648) throw new RuntimeException("IO.nextInt: Invalid int.");
				ret = -ret;
			}
			
			return ret;
		} catch(IOException e) {
			throw new RuntimeException("IO.nextInt: Caught IOException.");
		}
	}
	
	public long nextLong() {
		try {
			long ret = 0;
			
			eatDelimiters();
			
			boolean positive = true;
			if(buf[bufi] == '-') {
				++bufi;
				if(!pumpBuf()) throw new RuntimeException("IO.nextLong: Invalid long.");
				positive = false;
			}
			
			boolean first = true;
			while(true) {
				if(!pumpBuf()) break;
				if(isDelimiter(buf[bufi])) {
					if(first) throw new RuntimeException("IO.nextLong: Invalid long.");
					break;
				}
				first = false;
				
				if(buf[bufi] >= '0' && buf[bufi] <= '9') {
					if(ret < -922337203685477580L) throw new RuntimeException("IO.nextLong: Invalid long.");
					ret *= 10;
					ret -= (long)(buf[bufi] - '0');
					if(ret > 0) throw new RuntimeException("IO.nextLong: Invalid long.");
				} else {
					throw new RuntimeException("IO.nextLong: Invalid long.");
				}
				
				++bufi;
			}
			
			if(positive) {
				if(ret == -9223372036854775808L) throw new RuntimeException("IO.nextLong: Invalid long.");
				ret = -ret;
			}
			
			return ret;
		} catch(IOException e) {
			throw new RuntimeException("IO.nextLong: Caught IOException.");
		}
	}
	
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

    

}


Test details

Test 1

Verdict: ACCEPTED

input
5
1 2 3 4 5

correct output
5

user output
5

Test 2

Verdict: ACCEPTED

input
3
2000 1999 1998

correct output
1

user output
1

Test 3

Verdict: ACCEPTED

input
6
888947812 255632128 310470259 ...

correct output
3

user output
3

Test 4

Verdict: ACCEPTED

input
4
617082542 842820809 770021951 ...

correct output
3

user output
3

Test 5

Verdict: ACCEPTED

input
8
714278219 784227423 409319089 ...

correct output
2

user output
2

Test 6

Verdict: ACCEPTED

input
4
323548620 170481297 889562264 ...

correct output
2

user output
2

Test 7

Verdict: ACCEPTED

input
1
476683151

correct output
1

user output
1

Test 8

Verdict: ACCEPTED

input
2
629714376 581892911

correct output
1

user output
1

Test 9

Verdict: ACCEPTED

input
6
523198668 325464999 948349338 ...

correct output
2

user output
2

Test 10

Verdict: ACCEPTED

input
6
822568264 254647499 434272192 ...

correct output
4

user output
4

Test 11

Verdict: ACCEPTED

input
433
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
433

user output
433

Test 12

Verdict: ACCEPTED

input
554
2000 1999 1998 1997 1996 1995 ...

correct output
1

user output
1

Test 13

Verdict: ACCEPTED

input
630
882563506 195731667 430976596 ...

correct output
49

user output
49

Test 14

Verdict: ACCEPTED

input
335
488807609 178110205 512054465 ...

correct output
33

user output
33

Test 15

Verdict: ACCEPTED

input
120
174580714 91110553 34218342 94...

correct output
20

user output
20

Test 16

Verdict: ACCEPTED

input
593
34099449 759420722 786869557 3...

correct output
41

user output
41

Test 17

Verdict: ACCEPTED

input
97
393681127 117745478 576906971 ...

correct output
16

user output
16

Test 18

Verdict: ACCEPTED

input
780
596776372 178963013 27288301 3...

correct output
56

user output
56

Test 19

Verdict: ACCEPTED

input
769
927650514 16537731 669979959 5...

correct output
53

user output
53

Test 20

Verdict: ACCEPTED

input
253
939795028 916965543 553106661 ...

correct output
26

user output
26

Test 21

Verdict: ACCEPTED

input
1000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
1000

user output
1000

Test 22

Verdict: ACCEPTED

input
1000
2000 1999 1998 1997 1996 1995 ...

correct output
1

user output
1

Test 23

Verdict: ACCEPTED

input
1000
645404707 986143091 145611946 ...

correct output
58

user output
58

Test 24

Verdict: ACCEPTED

input
1000
341727972 757181419 834201886 ...

correct output
56

user output
56

Test 25

Verdict: ACCEPTED

input
1000
140851913 102736547 916629519 ...

correct output
55

user output
55

Test 26

Verdict: ACCEPTED

input
1000
32986064 260267921 970027433 9...

correct output
64

user output
64

Test 27

Verdict: ACCEPTED

input
1000
164970760 259631575 668929944 ...

correct output
54

user output
54

Test 28

Verdict: ACCEPTED

input
1000
259307867 630607450 309297823 ...

correct output
56

user output
56

Test 29

Verdict: ACCEPTED

input
1000
543833880 613702937 41531951 2...

correct output
58

user output
58

Test 30

Verdict: ACCEPTED

input
1000
652483687 571130341 552217195 ...

correct output
59

user output
59