CSES - Datatähti 2015 loppu - Results
Submission details
Task:Urkupillit
Sender:Kuha
Submission time:2015-01-29 12:39:49 +0200
Language:Java
Status:READY
Result:45
Feedback
groupverdictscore
#1ACCEPTED12
#2ACCEPTED33
#30
Test results
testverdicttimegroup
#1ACCEPTED0.04 s1details
#2ACCEPTED0.05 s1details
#3ACCEPTED0.05 s1details
#4ACCEPTED0.04 s1details
#5ACCEPTED0.05 s1details
#6ACCEPTED0.04 s2details
#7ACCEPTED0.04 s2details
#8ACCEPTED0.04 s2details
#9ACCEPTED0.04 s2details
#10ACCEPTED0.06 s2details
#11--3details
#120.03 s3details
#130.07 s3details
#140.04 s3details
#15--3details

Code

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

public class Main {
    public static void main(String[] args) {
        IO io = new IO();
        int n = io.nextInt();
        int k = io.nextInt();
        
        int[] urut = new int[n];
        int i = 0;
        int val = 1;
        
        while (i != k) {
            urut[Math.min(n - val, k - i)] = val;
            i += Math.min(n - val, k - i);
            val++;
        }
        
        int index = 0;
        while (val <= n) {
            if (urut[index] == 0) {
                urut[index] = val;
                val++;
            }
            index++;
        }
        
        io.println(arr(urut));
        
        io.close();
    }
    
    private static String arr (int[] a) {
        String str = "";
        for (int n : a) {
            str += n + " ";
        }
        return str;
    }
}

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

Group: 1

Verdict: ACCEPTED

input
5 0

correct output
1 2 3 4 5 

user output
1 2 3 4 5 

Test 2

Group: 1

Verdict: ACCEPTED

input
5 10

correct output
5 4 3 2 1 

user output
5 4 3 2 1 

Test 3

Group: 1

Verdict: ACCEPTED

input
5 3

correct output
4 1 2 3 5 

user output
2 3 4 1 5 

Test 4

Group: 1

Verdict: ACCEPTED

input
5 1

correct output
2 1 3 4 5 

user output
2 1 3 4 5 

Test 5

Group: 1

Verdict: ACCEPTED

input
5 2

correct output
3 1 2 4 5 

user output
2 3 1 4 5 

Test 6

Group: 2

Verdict: ACCEPTED

input
100 0

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

Test 7

Group: 2

Verdict: ACCEPTED

input
100 4950

correct output
100 99 98 97 96 95 94 93 92 91...

user output
100 99 98 97 96 95 94 93 92 91...

Test 8

Group: 2

Verdict: ACCEPTED

input
100 2279

correct output
100 99 98 97 96 95 94 93 92 91...

user output
28 29 30 31 32 33 34 35 36 37 ...

Test 9

Group: 2

Verdict: ACCEPTED

input
100 2528

correct output
100 99 98 97 96 95 94 93 92 91...

user output
31 32 33 34 35 36 37 38 39 40 ...

Test 10

Group: 2

Verdict: ACCEPTED

input
100 4483

correct output
100 99 98 97 96 95 94 93 92 91...

user output
70 71 72 73 74 75 76 77 78 79 ...

Test 11

Group: 3

Verdict:

input
100000 0

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
(empty)

Test 12

Group: 3

Verdict:

input
100000 4999950000

correct output
100000 99999 99998 99997 99996...

user output
(empty)

Error:
Exception in thread "main" java.lang.RuntimeException: IO.nextInt: Invalid int.
	at IO.nextInt(Main.java:148)
	at Main.main(Main.java:10)

Test 13

Group: 3

Verdict:

input
100000 2969035543

correct output
100000 99999 99998 99997 99996...

user output
(empty)

Error:
Exception in thread "main" java.lang.RuntimeException: IO.nextInt: Invalid int.
	at IO.nextInt(Main.java:148)
	at Main.main(Main.java:10)

Test 14

Group: 3

Verdict:

input
100000 2495939870

correct output
100000 99999 99998 99997 99996...

user output
(empty)

Error:
Exception in thread "main" java.lang.RuntimeException: IO.nextInt: Invalid int.
	at IO.nextInt(Main.java:148)
	at Main.main(Main.java:10)

Test 15

Group: 3

Verdict:

input
100000 1279770330

correct output
100000 99999 99998 99997 99996...

user output
(empty)