Skip to content

Instantly share code, notes, and snippets.

@kubo39
Created December 8, 2013 02:43
Show Gist options
  • Select an option

  • Save kubo39/7852743 to your computer and use it in GitHub Desktop.

Select an option

Save kubo39/7852743 to your computer and use it in GitHub Desktop.
paiza problem
import std.algorithm, std.conv, std.stdio, std.string;
void main() {
string[] arr = stdin.readln.strip.split(" ");
int num = arr[0].to!int;
int days = arr[1].to!int;
int[] prices;
foreach (string line; stdin.lines) {
if (line == "\n") break;
prices ~= line.strip.to!int;
}
int[] items = prices[0 .. num];
int[] perms;
for (int i; i < num-1; ++i)
for (int j=i+1; j < num; ++j)
perms ~= items[i] + items[j];
auto perms_range = perms.sort!("a < b");
foreach (goal; prices[num .. num+days]) {
if (goal < perms_range.front) {
writeln("0");
continue;
}
writeln(perms_range.lowerBound(goal+1).back); // dirty hack
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment