Skip to content

Instantly share code, notes, and snippets.

@phonism
Last active December 24, 2015 06:39
Show Gist options
  • Save phonism/6758048 to your computer and use it in GitHub Desktop.
Save phonism/6758048 to your computer and use it in GitHub Desktop.
Codeforces 349 B. Color the Fence http://codeforces.com/problemset/problem/349/B 贪心
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Main {
public void run() {
InputReader cin = new InputReader(System.in);
PrintWriter cout = new PrintWriter(new OutputStreamWriter(System.out));
int[] a = new int[10];
int min = 1000000000;
//String result = "";
int v = cin.nextInt();
for (int i = 0; i < 9; i++) {
a[i] = cin.nextInt();
min = Math.min(a[i], min);
}
if (v < min) {
cout.println("-1");
} else {
while (v >= min) {
for (int i = 8; i >= 0; i--) {
if (a[i] <= v && (v - a[i]) / min + 1 == v / min) {
cout.print((char) ('1' + i));
v -= a[i];
break;
}
}
}
// cout.println(result);
}
cout.flush();
}
public static void main(String args[]) {
new Main().run();
}
class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public InputReader() throws FileNotFoundException {
reader = new BufferedReader(new FileReader("d:/input.txt"));
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment