exec_outcome stringclasses 1 value | code_uid stringlengths 32 32 | file_name stringclasses 111 values | prob_desc_created_at stringlengths 10 10 | prob_desc_description stringlengths 63 3.8k | prob_desc_memory_limit stringclasses 18 values | source_code stringlengths 117 65.5k | lang_cluster stringclasses 1 value | prob_desc_sample_inputs stringlengths 2 802 | prob_desc_time_limit stringclasses 27 values | prob_desc_sample_outputs stringlengths 2 796 | prob_desc_notes stringlengths 4 3k ⌀ | lang stringclasses 5 values | prob_desc_input_from stringclasses 3 values | tags listlengths 0 11 | src_uid stringlengths 32 32 | prob_desc_input_spec stringlengths 28 2.37k ⌀ | difficulty int64 -1 3.5k ⌀ | prob_desc_output_spec stringlengths 17 1.47k ⌀ | prob_desc_output_to stringclasses 3 values | hidden_unit_tests stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PASSED | a3244d8e04eaa186b96be286e1f5c486 | train_003.jsonl | 1574862600 | Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.Your house has $$$n$$$ rooms. In the $$$i$$$-th room you can install at most $$$c_i$$$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $$$k$$$ sections is equal to $$$k^2$$$ burles.Since rooms can have different sizes, you calculated that you need at least $$$sum_i$$$ sections in total in the $$$i$$$-th room. For each room calculate the minimum cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | 256 megabytes | import java.util.*;
import java.io.*;
public class heating {
public static void main(String[] args) {
Scanner in = new Scanner(new BufferedInputStream(System.in));
int n = in.nextInt();
int c, sum, q, r, val;
int ans[] = new int[n];
for (int i = 0; i < n; i++) {
c = in.nextInt();
sum = in.nextInt();
if (c > sum)
ans[i] = sum;
else {
int cost = 0;
q = sum / c;
r = sum % c;
for (int j = 0; j < c; j++) {
val = q + (r > 0 ? 1 : 0);
cost = cost + val * val;
r--;
}
ans[i] = cost;
}
}
in.close();
for (int a: ans)
System.out.println(a);
}
} | Java | ["4\n1 10000\n10000 1\n2 6\n4 6"] | 1 second | ["100000000\n1\n18\n10"] | NoteIn the first room, you can install only one radiator, so it's optimal to use the radiator with $$$sum_1$$$ sections. The cost of the radiator is equal to $$$(10^4)^2 = 10^8$$$.In the second room, you can install up to $$$10^4$$$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.In the third room, there $$$7$$$ variants to install radiators: $$$[6, 0]$$$, $$$[5, 1]$$$, $$$[4, 2]$$$, $$$[3, 3]$$$, $$$[2, 4]$$$, $$$[1, 5]$$$, $$$[0, 6]$$$. The optimal variant is $$$[3, 3]$$$ and it costs $$$3^2+ 3^2 = 18$$$. | Java 11 | standard input | [
"math"
] | 0ec973bf4ad209de9731818c75469541 | The first line contains single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of rooms. Each of the next $$$n$$$ lines contains the description of some room. The $$$i$$$-th line contains two integers $$$c_i$$$ and $$$sum_i$$$ ($$$1 \le c_i, sum_i \le 10^4$$$) — the maximum number of radiators and the minimum total number of sections in the $$$i$$$-th room, respectively. | 1,000 | For each room print one integer — the minimum possible cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | standard output | |
PASSED | ecb60c03a748dc4b6ce03847b813806b | train_003.jsonl | 1574862600 | Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.Your house has $$$n$$$ rooms. In the $$$i$$$-th room you can install at most $$$c_i$$$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $$$k$$$ sections is equal to $$$k^2$$$ burles.Since rooms can have different sizes, you calculated that you need at least $$$sum_i$$$ sections in total in the $$$i$$$-th room. For each room calculate the minimum cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | 256 megabytes | import java.util.Scanner;
public class CF {
static Scanner sc=new Scanner(System.in);
public static void main(String[] args) {
int tc;
tc=sc.nextInt();
for(int i=0;i<tc;i++)
{
int a,b,r,d,res;
res=0;
b=sc.nextInt();
a=sc.nextInt();
r=a%b;
d=a/b;
for(int j=0;j<b;j++)
{
if(r>0)
{
res+=(d+1)*(d+1);
r--;
}
else {
res+=(d*d);
}
}
System.out.println(res);
}
}
}
| Java | ["4\n1 10000\n10000 1\n2 6\n4 6"] | 1 second | ["100000000\n1\n18\n10"] | NoteIn the first room, you can install only one radiator, so it's optimal to use the radiator with $$$sum_1$$$ sections. The cost of the radiator is equal to $$$(10^4)^2 = 10^8$$$.In the second room, you can install up to $$$10^4$$$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.In the third room, there $$$7$$$ variants to install radiators: $$$[6, 0]$$$, $$$[5, 1]$$$, $$$[4, 2]$$$, $$$[3, 3]$$$, $$$[2, 4]$$$, $$$[1, 5]$$$, $$$[0, 6]$$$. The optimal variant is $$$[3, 3]$$$ and it costs $$$3^2+ 3^2 = 18$$$. | Java 11 | standard input | [
"math"
] | 0ec973bf4ad209de9731818c75469541 | The first line contains single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of rooms. Each of the next $$$n$$$ lines contains the description of some room. The $$$i$$$-th line contains two integers $$$c_i$$$ and $$$sum_i$$$ ($$$1 \le c_i, sum_i \le 10^4$$$) — the maximum number of radiators and the minimum total number of sections in the $$$i$$$-th room, respectively. | 1,000 | For each room print one integer — the minimum possible cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | standard output | |
PASSED | 8474ff85d1edbcce519b86aae9cc9f2f | train_003.jsonl | 1574862600 | Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.Your house has $$$n$$$ rooms. In the $$$i$$$-th room you can install at most $$$c_i$$$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $$$k$$$ sections is equal to $$$k^2$$$ burles.Since rooms can have different sizes, you calculated that you need at least $$$sum_i$$$ sections in total in the $$$i$$$-th room. For each room calculate the minimum cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | 256 megabytes | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
public class Main {
// static math M;
public static void main(String[] args) throws IOException {
FastScanner in = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = in.nextInt();
for (int i = 0; i < n; i++) {
int c = in.nextInt();
int s = in.nextInt();
int r[] = new int[c];
int ans = 0;
int nd = s / c;
for (int j = 0; j < c; j++) {
r[j] = nd;
}
int lft = s % c;
for (int j = 0; j < c; j++) {
if(lft < 1)break;
r[j]++;
lft--;
}
for (int j = 0; j < c; j++) {
ans+=r[j] * r[j];
}
out.println(ans);
}
out.close();
}
}
class math {
static long mod = (int) 1e9 + 7;
long add(long a, long b) {
if (a + b >= mod) return a + b - mod;
return a + b;
}
long sqr(long a) {
if (a * a >= mod) return a * a % mod;
return a * a;
}
long mp(long a, long b) {
if (a * b >= mod) return a * b % mod;
return a * b;
}
long pow(long a, int n) {
if (n == 0) return 1;
if (n == 1) return a;
if ((n & 1) == 0) {
long pw = pow(a, n / 2);
return sqr(pw);
}
return mp(a, pow(a, n - 1));
}
}
class RANDOMIZER {
static Random rnd = new Random();
static int randomize() {
return rnd.nextInt();
}
}
class array {
long a[];
array(long a[]) {
this.a = a;
}
array(int n) {
a = new long[n];
}
void shuffle() {
for (int i = 0; i < a.length; i++) {
int id1 = ((RANDOMIZER.randomize() % a.length) + a.length) % a.length;
int id2 = ((RANDOMIZER.randomize() % a.length) + a.length) % a.length;
long t = a[id1];
a[id1] = a[id2];
a[id2] = t;
}
}
void reverse(int l, int r) {
for (int i = l; i < l + ((r - l + 1) >> 1); i++) {
long t = a[i];
a[i] = a[r - i + l];
a[r - i + l] = t;
}
}
long[] right_shift(int shift) {
long aa[] = new long[a.length];
for (int i = 0; i < a.length; i++) {
aa[(i + shift) % a.length] = a[i];
}
return aa;
}
void add(int l, int r, long val) {
for (int i = l; i <= r; i++) {
a[i] += val;
}
}
void print(PrintWriter out) {
for (int i = 0; i < a.length; i++) {
out.print(a[i] + " ");
}
}
void copy(long t[]) {
for (int i = 0; i < a.length; i++) {
a[i] = t[i];
}
}
void scan(FastScanner in) throws IOException {
for (int i = 0; i < a.length; i++) {
a[i] = in.nextLong();
}
}
long getSum() {
long sum = 0;
long md = (long) 1e16;
for (int i = 0; i < a.length; i++) {
sum += a[i];
sum %= md;
}
return sum;
}
long getMin() {
long min = Long.MAX_VALUE;
for (int i = 0; i < a.length; i++) {
min = min(min, a[i]);
}
return min;
}
long getMax() {
long max = Long.MIN_VALUE;
for (int i = 0; i < a.length; i++) {
max = max(max, a[i]);
}
return max;
}
int ceilingID(long val) {
int l = 0;
int r = a.length - 1;
while (l + 1 != r) {
int m = (l + r) >> 1;
if (a[m] >= val) r = m;
else l = m;
}
int pr = l;
if (pr > 0 && a[pr - 1] >= val) pr--;
if (a[pr] < val) pr++;
if (pr < a.length && a[pr] < val) pr++;
return pr;
}
}
class dsu {
int p[];
int max[];
dsu(int n) {
p = new int[n];
max = new int[n];
for (int i = 0; i < n; i++) {
p[i] = i;
max[i] = i;
}
}
int get(int a) {
if (p[a] == a) return a;
return p[a] = get(p[a]);
}
void merge(int a, int b) {
a = get(a);
b = get(b);
if (a != b) {
p[a] = b;
max[b] = max(max[a], max[b]);
}
}
}
class vertex {
int next[];
}
class trie {
vertex t[];
int sz = 1;
int k;
trie(int k) {
this.k = k;
t = new vertex[300000];
for (int i = 0; i < t.length; i++) {
t[i] = new vertex();
t[i].next = new int[k];
for (int j = 0; j < k; j++) {
t[i].next[j] = -1;
}
}
}
void add(String s, int id) {
int v = 0;
for (int i = 0; i < s.length(); i++) {
char rc = (char) (s.charAt(i) - 'a');
if (t[v].next[rc] == -1) {
t[v].next[rc] = sz++;
}
v = t[v].next[rc];
}
}
}
class StringHelper {
char[] s;
long hash[];
long px[];
long mod = (int) 1e9 + 7;
long x = 255;
int n;
public StringHelper(String s) {
this.s = s.toCharArray();
n = s.length();
}
int[] pi() {
int pi[] = new int[n];
for (int i = 1; i < n; i++) {
int j = pi[i - 1];
while (j > 0 && s[i] != s[j]) j = pi[j - 1];
pi[i] = s[i] == s[j] ? j + 1 : j;
}
return pi;
}
void calcHash() {
hash = new long[n + 1];
px = new long[n + 3];
px[0] = 1;
for (int i = 1; i < n + 3; i++) {
px[i] = px[i - 1] * x % mod;
}
for (int i = 1; i < n + 1; i++) {
hash[i] = (hash[i - 1] * x % mod + s[i - 1] + mod) % mod;
}
}
long getHash(int l, int r) {
return (hash[r + 1] - hash[l] * px[r - l + 1] % mod + mod) % mod;
}
}
class IMPLICITDT {
long val;
int y;
int sz;
IMPLICITDT l, r;
static int getSize(IMPLICITDT t) {
return t == null ? 0 : t.sz;
}
private static void recalc(IMPLICITDT t) {
if (t == null) return;
int LSZ = t.l == null ? 0 : t.l.sz;
int RSZ = t.r == null ? 0 : t.r.sz;
t.sz = LSZ + RSZ + 1;
}
IMPLICITDT() {
}
IMPLICITDT(long cost, int y, IMPLICITDT l, IMPLICITDT r) {
this.val = cost;
this.y = y;
this.l = l;
this.r = r;
recalc(this);
}
IMPLICITDT(long cost, int y) {
this.val = cost;
this.y = y;
recalc(this);
}
static long get(IMPLICITDT t, int id) {
int LSZ = getSize(t.l);
if (LSZ == id) return t.val;
if (LSZ < id) return get(t.r, id - LSZ - 1);
return get(t.l, id);
}
static IMPLICITDT split(IMPLICITDT T, int x) {
IMPLICITDT RES = new IMPLICITDT();
if (T == null) {
return RES;
}
if (getSize(T.l) > x) {
IMPLICITDT lsplit = split(T.l, x);
RES.l = lsplit.l;
RES.r = T;
T.l = lsplit.r;
} else {
IMPLICITDT rsplit = split(T.r, x - getSize(T.l) - 1);
RES.r = rsplit.r;
RES.l = T;
T.r = rsplit.l;
}
recalc(RES);
recalc(T);
return RES;
}
static IMPLICITDT merge(IMPLICITDT L, IMPLICITDT R) {
if (L == null) return R;
if (R == null) return L;
if (L.y > R.y) return new IMPLICITDT(L.val, L.y, L.l, merge(L.r, R));
else return new IMPLICITDT(R.val, R.y, merge(L, R.l), R.r);
}
static IMPLICITDT insert(IMPLICITDT T, long val, int id) {
if (T == null) return new IMPLICITDT(val, RANDOMIZER.randomize());
IMPLICITDT _T = split(T, id);
IMPLICITDT _TR = new IMPLICITDT(val, RANDOMIZER.randomize());
IMPLICITDT NEWTREAP = merge(_T.l, _TR);
IMPLICITDT TREAP = merge(NEWTREAP, _T.r);
recalc(TREAP);
return TREAP;
}
}
class stSUM {
int t[];
int a[];
stSUM(int a[]) {
this.a = a;
t = new int[a.length * 4];
}
void build(int v, int l, int r) {
if (l == r) t[v] = a[l];
else {
int m = (l + r) >> 1;
build(v * 2, l, m);
build(v * 2 + 1, m + 1, r);
t[v] = t[v * 2] + t[v * 2 + 1];
}
}
void upd(int v, int l, int r, int pos, int x) {
if (l == r) t[v] = x;
else {
int m = (l + r) >> 1;
if (pos <= m) upd(v * 2, l, m, pos, x);
else upd(v * 2 + 1, m + 1, r, pos, x);
t[v] = t[v * 2] + t[v * 2 + 1];
}
}
int query(int v, int l, int r, int ql, int qr) {
if (ql <= l && r <= qr) return t[v];
if (l > qr || ql > r) return 0;
int m = (l + r) >> 1;
return query(v * 2, l, m, ql, qr) + query(v * 2 + 1, m + 1, r, ql, qr);
}
}
class stMIN {
int t[];
int a[];
stMIN(int a[]) {
this.a = a;
t = new int[a.length * 4];
}
void build(int v, int l, int r) {
if (l == r) t[v] = a[l];
else {
int m = (l + r) >> 1;
build(v * 2, l, m);
build(v * 2 + 1, m + 1, r);
t[v] = min(t[v * 2], t[v * 2 + 1]);
}
}
void upd(int v, int l, int r, int pos, int x) {
if (l == r) t[v] = x;
else {
int m = (l + r) >> 1;
if (pos <= m) upd(v * 2, l, m, pos, x);
else upd(v * 2 + 1, m + 1, r, pos, x);
t[v] = min(t[v * 2], t[v * 2 + 1]);
}
}
int query(int v, int l, int r, int ql, int qr) {
if (ql <= l && r <= qr) return t[v];
if (l > qr || ql > r) return Integer.MAX_VALUE;
int m = (l + r) >> 1;
return min(query(v * 2, l, m, ql, qr), query(v * 2 + 1, m + 1, r, ql, qr));
}
}
class DT {
long val;
int x, y;
int sz;
DT l, r;
DT() {
recalc(this);
}
DT(int x, int y, long val) {
this.x = x;
this.y = y;
this.val = val;
recalc(this);
}
DT(int x, int y, DT l, DT r, long val) {
this.x = x;
this.y = y;
this.l = l;
this.r = r;
this.val = val;
recalc(this);
}
static DT split(DT t, int x) {
DT res = new DT();
if (t == null) {
res.l = null;
res.r = null;
return res;
}
if (x < t.x) {
DT lsplit = split(t.l, x);
res.l = lsplit.l;
res.r = t;
t.l = lsplit.r;
} else {
DT rsplit = split(t.r, x);
res.r = rsplit.r;
res.l = t;
t.r = rsplit.l;
}
recalc(t);
recalc(res);
return res;
}
static DT merge(DT t1, DT t2) {
if (t1 == null || t2 == null)
return t1 == null ? t2 : t1;
if (t1.y < t2.y) {
t1.r = merge(t1.r, t2);
recalc(t1);
return t1;
} else {
t2.l = merge(t1, t2.l);
recalc(t2);
return t2;
}
}
static void recalc(DT t) {
if (t == null) return;
int lsz = t.l == null ? 0 : t.l.sz;
int rsz = t.r == null ? 0 : t.r.sz;
t.sz = lsz + rsz + 1;
}
static DT insert(DT t, int x, long val) {
try {
if (t == null) {
DT ret = new DT(x, RANDOMIZER.randomize(), val);
recalc(ret);
return ret;
}
DT split = split(t, x);
DT prelast = merge(split.l, new DT(x, RANDOMIZER.randomize(), val));
DT newtreap = merge(prelast, split.r);
recalc(newtreap);
return newtreap;
} catch (Exception e) {
System.exit(0);
return new DT();
}
}
static long find_kth(DT t, int k) {
if (t.l == null && k == 1)
return t.val;
if (t.l != null && t.l.sz == k - 1)
return t.val;
if (t.l != null && t.l.sz >= k)
return find_kth(t.l, k);
else
return find_kth(t.r, k - (t.l == null ? 0 : t.l.sz) - 1);
}
}
class FT {
private int[] a;
private long[] t;
FT(int[] a) {
this.a = a;
t = new long[a.length];
}
void inc(int i, int delta) {
for (; i < a.length; i = (i | (i + 1)))
t[i] += delta;
}
long sum(int l, int r) {
return sum(r) - sum(l - 1);
}
private long sum(int r) {
long sum = 0;
for (; r >= 0; r = (r & (r + 1)) - 1) {
sum += t[r];
}
return sum;
}
}
class LAZY_ST {
long min[], sum[], set[];
int last;
long not_set = Long.MAX_VALUE;
LAZY_ST(long a[]) {
int n = a.length;
last = n - 1;
min = new long[4 * n];
sum = new long[4 * n];
set = new long[4 * n];
for (int i = 0; i < 4 * n; i++) {
set[i] = not_set;
}
build(0, 0, last, a);
}
void build(int v, int l, int r, long a[]) {
if (l == r) {
min[v] = a[l];
return;
}
int m = ((l + r) >> 1);
build(v * 2 + 1, l, m, a);
build(v * 2 + 2, m + 1, r, a);
min[v] = Math.min(min[v * 2 + 1], min[v * 2 + 2]);
}
void push(int v) {
if (set[v] != not_set) {
min[v] = set[v];
sum[v * 2 + 1] = sum[v * 2 + 2] = 0;
set[v * 2 + 1] = set[v * 2 + 2] = set[v];
set[v] = not_set;
}
min[v] += sum[v];
sum[v * 2 + 1] += sum[v];
sum[v * 2 + 2] += sum[v];
sum[v] = 0;
}
void upd(int v) {
min[v] = Math.min(get_el(v * 2 + 1), get_el(v * 2 + 2));
}
long get_el(int v) {
return (set[v] == not_set ? min[v] : set[v]) + sum[v];
}
void set(int l, int r, long x) {
set(0, 0, last, l, r, x);
}
void set(int v, int l, int r, int left, int right, long x) {
if (l > right || r < left) return;
if (l >= left && r <= right) {
sum[v] = 0;
set[v] = x;
return;
}
push(v);
int m = ((l + r) >> 1);
set(v * 2 + 1, l, m, left, right, x);
set(v * 2 + 2, m + 1, r, left, right, x);
upd(v);
}
void add(int l, int r, long x) {
add(0, 0, last, l, r, x);
}
void add(int v, int l, int r, int left, int right, long x) {
if (l > right || r < left) return;
if (l >= left && r <= right) {
sum[v] += x;
return;
}
push(v);
int m = ((l + r) >> 1);
add(v * 2 + 1, l, m, left, right, x);
add(v * 2 + 2, m + 1, r, left, right, x);
upd(v);
}
long get(int l, int r) {
return get(0, 0, last, l, r);
}
long get(int v, int l, int r, int left, int right) {
if (l > right || r < left) return (long) 1e17;
if (l >= left && r <= right) {
return get_el(v);
}
push(v);
int m = ((l + r) >> 1);
long ans = Math.min(get(v * 2 + 1, l, m, left, right), get(v * 2 + 2, m + 1, r, left, right));
upd(v);
return ans;
}
}
class multiset {
TreeMap<Long, Integer> t;
void insert(long val) {
t.put(val, t.getOrDefault(val, 0) + 1);
}
void erase(long val) {
int nw = t.getOrDefault(val, 1);
if (nw == 1) t.remove(val);
else t.put(val, nw - 1);
}
long ceiling(long val) {
return t.ceilingKey(val);
}
long floor(long val) {
return t.floorKey(val);
}
long higher(long val) {
return t.higherKey(val);
}
long lower(long val) {
return t.lowerKey(val);
}
int count(long val) {
return t.getOrDefault(val, 0);
}
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
FastScanner(File f) throws FileNotFoundException {
br = new BufferedReader(new FileReader(f));
}
FastScanner(InputStream is) {
br = new BufferedReader(new InputStreamReader(is));
}
String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
}
class tree {
ArrayList<Integer> g[];
int n;
ArrayList<Integer> order;
int first[];
int h[];
int t[];
int rt;
tree(ArrayList<Integer> g[]) {
this.g = g;
this.n = g.length;
order = new ArrayList<>();
first = new int[n];
fill(first, -1);
h = new int[n];
rt = 0;
dfs(rt, -1);
prepare();
}
void dfs(int v, int p) {
if (first[v] == -1) first[v] = order.size();
order.add(v);
for (int to : g[v]) {
if (to == p) continue;
h[to] = h[v] + 1;
dfs(to, v);
order.add(v);
}
}
void prepare() {
t = new int[order.size() * 4];
build(1, 0, order.size() - 1);
}
void build(int v, int l, int r) {
if (l == r) t[v] = order.get(l);
else {
int m = (l + r) >> 1;
build(v * 2, l, m);
build(v * 2 + 1, m + 1, r);
t[v] = h[t[v * 2]] < h[t[v * 2 + 1]] ? t[v * 2] : t[v * 2 + 1];
}
}
int query(int v, int l, int r, int ql, int qr) {
if (l > qr || ql > r) return Integer.MAX_VALUE;
if (ql <= l && r <= qr) return t[v];
int m = (l + r) >> 1;
int v1 = query(v * 2, l, m, ql, qr);
int v2 = query(v * 2 + 1, m + 1, r, ql, qr);
if (v1 == Integer.MAX_VALUE) return v2;
if (v2 == Integer.MAX_VALUE) return v1;
return h[v1] < h[v2] ? v1 : v2;
}
int lca(int a, int b) {
int l = first[a];
int r = first[b];
return query(1, 0, order.size() - 1, min(l, r), max(l, r));
}
}
| Java | ["4\n1 10000\n10000 1\n2 6\n4 6"] | 1 second | ["100000000\n1\n18\n10"] | NoteIn the first room, you can install only one radiator, so it's optimal to use the radiator with $$$sum_1$$$ sections. The cost of the radiator is equal to $$$(10^4)^2 = 10^8$$$.In the second room, you can install up to $$$10^4$$$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.In the third room, there $$$7$$$ variants to install radiators: $$$[6, 0]$$$, $$$[5, 1]$$$, $$$[4, 2]$$$, $$$[3, 3]$$$, $$$[2, 4]$$$, $$$[1, 5]$$$, $$$[0, 6]$$$. The optimal variant is $$$[3, 3]$$$ and it costs $$$3^2+ 3^2 = 18$$$. | Java 11 | standard input | [
"math"
] | 0ec973bf4ad209de9731818c75469541 | The first line contains single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of rooms. Each of the next $$$n$$$ lines contains the description of some room. The $$$i$$$-th line contains two integers $$$c_i$$$ and $$$sum_i$$$ ($$$1 \le c_i, sum_i \le 10^4$$$) — the maximum number of radiators and the minimum total number of sections in the $$$i$$$-th room, respectively. | 1,000 | For each room print one integer — the minimum possible cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | standard output | |
PASSED | e0baf426371307ae1ad6cb5a12dbaa9d | train_003.jsonl | 1574862600 | Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.Your house has $$$n$$$ rooms. In the $$$i$$$-th room you can install at most $$$c_i$$$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $$$k$$$ sections is equal to $$$k^2$$$ burles.Since rooms can have different sizes, you calculated that you need at least $$$sum_i$$$ sections in total in the $$$i$$$-th room. For each room calculate the minimum cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | 256 megabytes | /*package whatever //do not write package name here */
import java.io.*;
import java.util.*;
public class s {
public static void main (String[] args) {
Scanner k = new Scanner(System.in);
int n = k.nextInt();
for(int j=1;j<=n;j++){
int c = k.nextInt();
int sum = k.nextInt();
int[] arr = new int[c];
for(int i=0;i<c;i++){
arr[i] = 0;
}
while(true){
if(sum>0){
for(int i=0;i<c;i++){
arr[i]++;
sum--;
if(sum==0)
break;
}
}
else
break;
}
//System.out.println(arr[0]);
int total = 0;
for(int i=0;i<c;i++){
total += (arr[i]*arr[i]);
}
System.out.println(total);
}
}
} | Java | ["4\n1 10000\n10000 1\n2 6\n4 6"] | 1 second | ["100000000\n1\n18\n10"] | NoteIn the first room, you can install only one radiator, so it's optimal to use the radiator with $$$sum_1$$$ sections. The cost of the radiator is equal to $$$(10^4)^2 = 10^8$$$.In the second room, you can install up to $$$10^4$$$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.In the third room, there $$$7$$$ variants to install radiators: $$$[6, 0]$$$, $$$[5, 1]$$$, $$$[4, 2]$$$, $$$[3, 3]$$$, $$$[2, 4]$$$, $$$[1, 5]$$$, $$$[0, 6]$$$. The optimal variant is $$$[3, 3]$$$ and it costs $$$3^2+ 3^2 = 18$$$. | Java 11 | standard input | [
"math"
] | 0ec973bf4ad209de9731818c75469541 | The first line contains single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of rooms. Each of the next $$$n$$$ lines contains the description of some room. The $$$i$$$-th line contains two integers $$$c_i$$$ and $$$sum_i$$$ ($$$1 \le c_i, sum_i \le 10^4$$$) — the maximum number of radiators and the minimum total number of sections in the $$$i$$$-th room, respectively. | 1,000 | For each room print one integer — the minimum possible cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | standard output | |
PASSED | b98db8fc735c1d058657e98621e041a6 | train_003.jsonl | 1574862600 | Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.Your house has $$$n$$$ rooms. In the $$$i$$$-th room you can install at most $$$c_i$$$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $$$k$$$ sections is equal to $$$k^2$$$ burles.Since rooms can have different sizes, you calculated that you need at least $$$sum_i$$$ sections in total in the $$$i$$$-th room. For each room calculate the minimum cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | 256 megabytes | import java.util.*;
public class cfr77div2A {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int j=1;j<=t;j++)
{int c=sc.nextInt();
int s=sc.nextInt();
int sum=0;
int q=s/c,r=s%c;
sum=q*q*(c-r)+(q+1)*(q+1)*r;
System.out.println(sum);}
sc.close();
}
} | Java | ["4\n1 10000\n10000 1\n2 6\n4 6"] | 1 second | ["100000000\n1\n18\n10"] | NoteIn the first room, you can install only one radiator, so it's optimal to use the radiator with $$$sum_1$$$ sections. The cost of the radiator is equal to $$$(10^4)^2 = 10^8$$$.In the second room, you can install up to $$$10^4$$$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.In the third room, there $$$7$$$ variants to install radiators: $$$[6, 0]$$$, $$$[5, 1]$$$, $$$[4, 2]$$$, $$$[3, 3]$$$, $$$[2, 4]$$$, $$$[1, 5]$$$, $$$[0, 6]$$$. The optimal variant is $$$[3, 3]$$$ and it costs $$$3^2+ 3^2 = 18$$$. | Java 11 | standard input | [
"math"
] | 0ec973bf4ad209de9731818c75469541 | The first line contains single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of rooms. Each of the next $$$n$$$ lines contains the description of some room. The $$$i$$$-th line contains two integers $$$c_i$$$ and $$$sum_i$$$ ($$$1 \le c_i, sum_i \le 10^4$$$) — the maximum number of radiators and the minimum total number of sections in the $$$i$$$-th room, respectively. | 1,000 | For each room print one integer — the minimum possible cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | standard output | |
PASSED | d9fc4c39ed7f9433f0291b7f72058dae | train_003.jsonl | 1574862600 | Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.Your house has $$$n$$$ rooms. In the $$$i$$$-th room you can install at most $$$c_i$$$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $$$k$$$ sections is equal to $$$k^2$$$ burles.Since rooms can have different sizes, you calculated that you need at least $$$sum_i$$$ sections in total in the $$$i$$$-th room. For each room calculate the minimum cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
while (n-- > 0) {
int c = in.nextInt(), sum = in.nextInt();
if (c == 1) {
System.out.println(sum * sum);
continue;
}
if (sum == 1) {
System.out.println(1);
continue;
}
int cost = 0;
cost += ((sum / c) + 1)*((sum / c) + 1) * (sum % c);
cost += (sum / c)*(sum / c) * (c - sum % c);
System.out.println(cost);
}
}
} | Java | ["4\n1 10000\n10000 1\n2 6\n4 6"] | 1 second | ["100000000\n1\n18\n10"] | NoteIn the first room, you can install only one radiator, so it's optimal to use the radiator with $$$sum_1$$$ sections. The cost of the radiator is equal to $$$(10^4)^2 = 10^8$$$.In the second room, you can install up to $$$10^4$$$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.In the third room, there $$$7$$$ variants to install radiators: $$$[6, 0]$$$, $$$[5, 1]$$$, $$$[4, 2]$$$, $$$[3, 3]$$$, $$$[2, 4]$$$, $$$[1, 5]$$$, $$$[0, 6]$$$. The optimal variant is $$$[3, 3]$$$ and it costs $$$3^2+ 3^2 = 18$$$. | Java 11 | standard input | [
"math"
] | 0ec973bf4ad209de9731818c75469541 | The first line contains single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of rooms. Each of the next $$$n$$$ lines contains the description of some room. The $$$i$$$-th line contains two integers $$$c_i$$$ and $$$sum_i$$$ ($$$1 \le c_i, sum_i \le 10^4$$$) — the maximum number of radiators and the minimum total number of sections in the $$$i$$$-th room, respectively. | 1,000 | For each room print one integer — the minimum possible cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | standard output | |
PASSED | 1d972ffcf6c06943e31d7bd8e3b3fd4a | train_003.jsonl | 1574862600 | Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.Your house has $$$n$$$ rooms. In the $$$i$$$-th room you can install at most $$$c_i$$$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $$$k$$$ sections is equal to $$$k^2$$$ burles.Since rooms can have different sizes, you calculated that you need at least $$$sum_i$$$ sections in total in the $$$i$$$-th room. For each room calculate the minimum cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | 256 megabytes | // practice with kaiboy
import java.io.*;
import java.util.*;
public class CF1260A extends PrintWriter {
CF1260A() { super(System.out); }
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1260A o = new CF1260A(); o.main(); o.flush();
}
void main() {
int n = sc.nextInt();
while (n-- > 0) {
int c = sc.nextInt();
int s = sc.nextInt();
int a = s / c;
int r = s % c;
println((c - r) * a * a + r * (a + 1) * (a + 1));
}
}
}
| Java | ["4\n1 10000\n10000 1\n2 6\n4 6"] | 1 second | ["100000000\n1\n18\n10"] | NoteIn the first room, you can install only one radiator, so it's optimal to use the radiator with $$$sum_1$$$ sections. The cost of the radiator is equal to $$$(10^4)^2 = 10^8$$$.In the second room, you can install up to $$$10^4$$$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.In the third room, there $$$7$$$ variants to install radiators: $$$[6, 0]$$$, $$$[5, 1]$$$, $$$[4, 2]$$$, $$$[3, 3]$$$, $$$[2, 4]$$$, $$$[1, 5]$$$, $$$[0, 6]$$$. The optimal variant is $$$[3, 3]$$$ and it costs $$$3^2+ 3^2 = 18$$$. | Java 11 | standard input | [
"math"
] | 0ec973bf4ad209de9731818c75469541 | The first line contains single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of rooms. Each of the next $$$n$$$ lines contains the description of some room. The $$$i$$$-th line contains two integers $$$c_i$$$ and $$$sum_i$$$ ($$$1 \le c_i, sum_i \le 10^4$$$) — the maximum number of radiators and the minimum total number of sections in the $$$i$$$-th room, respectively. | 1,000 | For each room print one integer — the minimum possible cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | standard output | |
PASSED | 6d0d524f288505e24563d04402602efd | train_003.jsonl | 1574862600 | Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.Your house has $$$n$$$ rooms. In the $$$i$$$-th room you can install at most $$$c_i$$$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $$$k$$$ sections is equal to $$$k^2$$$ burles.Since rooms can have different sizes, you calculated that you need at least $$$sum_i$$$ sections in total in the $$$i$$$-th room. For each room calculate the minimum cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | 256 megabytes |
import java.io.*;
import java.util.*;
public class A {
Random random = new Random(751454315315L + System.currentTimeMillis());
public void solve() throws IOException {
int n = nextInt();
for (int i = 0; i < n; i++) {
int c = nextInt();
int summ = nextInt();
long ans = 0;
for (int j = 0; j < c; j++) {
if (j >= summ % c) {
ans += (summ / c) * (summ / c);
} else {
ans += ((summ) / c + 1) * ((summ) / c + 1);
}
}
out.println(ans);
}
}
public void run() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
}
private void shuffle(int[] s) {
for (int i = 0; i < s.length; ++i) {
int j = random.nextInt(i + 1);
int t = s[i];
s[i] = s[j];
s[j] = t;
}
}
class Pair implements Comparable<Pair> {
int f;
int s;
public Pair(int f, int s) {
this.f = f;
this.s = s;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Pair pair = (Pair) o;
return f == pair.f &&
s == pair.s;
}
@Override
public int hashCode() {
return Objects.hash(f, s);
}
@Override
public int compareTo(Pair o) {
if (f == o.f) {
return s - o.s;
}
return f - o.f;
}
}
BufferedReader br;
StringTokenizer in;
PrintWriter out;
public String nextToken() throws IOException {
while (in == null || !in.hasMoreTokens()) {
in = new StringTokenizer(br.readLine());
}
return in.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
public double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
public long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
public int[] nextArr(int n) throws IOException {
int[] res = new int[n];
for (int i = 0; i < n; i++) {
res[i] = nextInt();
}
return res;
}
public static void main(String[] args) throws IOException {
Locale.setDefault(Locale.US);
new A().run();
}
} | Java | ["4\n1 10000\n10000 1\n2 6\n4 6"] | 1 second | ["100000000\n1\n18\n10"] | NoteIn the first room, you can install only one radiator, so it's optimal to use the radiator with $$$sum_1$$$ sections. The cost of the radiator is equal to $$$(10^4)^2 = 10^8$$$.In the second room, you can install up to $$$10^4$$$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.In the third room, there $$$7$$$ variants to install radiators: $$$[6, 0]$$$, $$$[5, 1]$$$, $$$[4, 2]$$$, $$$[3, 3]$$$, $$$[2, 4]$$$, $$$[1, 5]$$$, $$$[0, 6]$$$. The optimal variant is $$$[3, 3]$$$ and it costs $$$3^2+ 3^2 = 18$$$. | Java 11 | standard input | [
"math"
] | 0ec973bf4ad209de9731818c75469541 | The first line contains single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of rooms. Each of the next $$$n$$$ lines contains the description of some room. The $$$i$$$-th line contains two integers $$$c_i$$$ and $$$sum_i$$$ ($$$1 \le c_i, sum_i \le 10^4$$$) — the maximum number of radiators and the minimum total number of sections in the $$$i$$$-th room, respectively. | 1,000 | For each room print one integer — the minimum possible cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | standard output | |
PASSED | 1310fcad699e3d3210d2eab8d44b07ba | train_003.jsonl | 1574862600 | Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.Your house has $$$n$$$ rooms. In the $$$i$$$-th room you can install at most $$$c_i$$$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $$$k$$$ sections is equal to $$$k^2$$$ burles.Since rooms can have different sizes, you calculated that you need at least $$$sum_i$$$ sections in total in the $$$i$$$-th room. For each room calculate the minimum cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
public class A{
static String [] line;
public static void main (String[] args) throws java.lang.Exception{
InputStreamReader ir = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(ir);
OutputStreamWriter or = new OutputStreamWriter(System.out);
BufferedWriter out = new BufferedWriter(or);
int n = Integer.valueOf(in.readLine());
for (int i = 0; i < n; i++){
long c, s;
line = in.readLine().split(" ");
c = Long.valueOf(line[0]);
s = Long.valueOf(line[1]);
long k = s/c, r = s%c;
long ans = (c-r)*k*k + r*(k+1)*(k+1);
out.append(String.valueOf(ans) + '\n');
}
out.flush();
}
}
| Java | ["4\n1 10000\n10000 1\n2 6\n4 6"] | 1 second | ["100000000\n1\n18\n10"] | NoteIn the first room, you can install only one radiator, so it's optimal to use the radiator with $$$sum_1$$$ sections. The cost of the radiator is equal to $$$(10^4)^2 = 10^8$$$.In the second room, you can install up to $$$10^4$$$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.In the third room, there $$$7$$$ variants to install radiators: $$$[6, 0]$$$, $$$[5, 1]$$$, $$$[4, 2]$$$, $$$[3, 3]$$$, $$$[2, 4]$$$, $$$[1, 5]$$$, $$$[0, 6]$$$. The optimal variant is $$$[3, 3]$$$ and it costs $$$3^2+ 3^2 = 18$$$. | Java 11 | standard input | [
"math"
] | 0ec973bf4ad209de9731818c75469541 | The first line contains single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of rooms. Each of the next $$$n$$$ lines contains the description of some room. The $$$i$$$-th line contains two integers $$$c_i$$$ and $$$sum_i$$$ ($$$1 \le c_i, sum_i \le 10^4$$$) — the maximum number of radiators and the minimum total number of sections in the $$$i$$$-th room, respectively. | 1,000 | For each room print one integer — the minimum possible cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | standard output | |
PASSED | e578e40dff8f9cbddd99d6fa2ee67b92 | train_003.jsonl | 1574862600 | Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.Your house has $$$n$$$ rooms. In the $$$i$$$-th room you can install at most $$$c_i$$$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $$$k$$$ sections is equal to $$$k^2$$$ burles.Since rooms can have different sizes, you calculated that you need at least $$$sum_i$$$ sections in total in the $$$i$$$-th room. For each room calculate the minimum cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main{
public static void main(String[] args) throws Exception{
MScanner sc=new MScanner(System.in);
PrintWriter pw=new PrintWriter(System.out);
int t=sc.nextInt();
while(t-->0) {
int c=sc.nextInt(),s=sc.nextInt();
if(s<=c) {
pw.println(s);
}
else {
int x=s/c;
long ans=x*1l*x*(c-s%c);
x++;
ans+=x*1l*x*(s%c);
pw.println(ans);
}
}
pw.flush();
}
static class MScanner {
StringTokenizer st;
BufferedReader br;
public MScanner(InputStream system) {
br = new BufferedReader(new InputStreamReader(system));
}
public MScanner(String file) throws Exception {
br = new BufferedReader(new FileReader(file));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int[] takearr(int n) throws IOException {
int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
return in;
}
public long[] takearrl(int n) throws IOException {
long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
return in;
}
public Integer[] takearrobj(int n) throws IOException {
Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
return in;
}
public Long[] takearrlobj(int n) throws IOException {
Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
return in;
}
public String nextLine() throws IOException {
return br.readLine();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public char nextChar() throws IOException {
return next().charAt(0);
}
public Long nextLong() throws IOException {
return Long.parseLong(next());
}
public boolean ready() throws IOException {
return br.ready();
}
public void waitForInput() throws InterruptedException {
Thread.sleep(3000);
}
}
} | Java | ["4\n1 10000\n10000 1\n2 6\n4 6"] | 1 second | ["100000000\n1\n18\n10"] | NoteIn the first room, you can install only one radiator, so it's optimal to use the radiator with $$$sum_1$$$ sections. The cost of the radiator is equal to $$$(10^4)^2 = 10^8$$$.In the second room, you can install up to $$$10^4$$$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.In the third room, there $$$7$$$ variants to install radiators: $$$[6, 0]$$$, $$$[5, 1]$$$, $$$[4, 2]$$$, $$$[3, 3]$$$, $$$[2, 4]$$$, $$$[1, 5]$$$, $$$[0, 6]$$$. The optimal variant is $$$[3, 3]$$$ and it costs $$$3^2+ 3^2 = 18$$$. | Java 11 | standard input | [
"math"
] | 0ec973bf4ad209de9731818c75469541 | The first line contains single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of rooms. Each of the next $$$n$$$ lines contains the description of some room. The $$$i$$$-th line contains two integers $$$c_i$$$ and $$$sum_i$$$ ($$$1 \le c_i, sum_i \le 10^4$$$) — the maximum number of radiators and the minimum total number of sections in the $$$i$$$-th room, respectively. | 1,000 | For each room print one integer — the minimum possible cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | standard output | |
PASSED | 035a84fd7c807c12d610eba2668b25f3 | train_003.jsonl | 1574862600 | Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.Your house has $$$n$$$ rooms. In the $$$i$$$-th room you can install at most $$$c_i$$$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $$$k$$$ sections is equal to $$$k^2$$$ burles.Since rooms can have different sizes, you calculated that you need at least $$$sum_i$$$ sections in total in the $$$i$$$-th room. For each room calculate the minimum cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | 256 megabytes |
import java.util.*;
public class Main {
public static int slv(int n, int m) {
int x = m % n;
int y = n - x;
int z = m / n;
return x * (z + 1) * (z + 1) + y * z * z;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt();
while(T-- > 0) {
int n = scanner.nextInt();
int m = scanner.nextInt();
System.out.println(slv(n, m));
}
}
}
| Java | ["4\n1 10000\n10000 1\n2 6\n4 6"] | 1 second | ["100000000\n1\n18\n10"] | NoteIn the first room, you can install only one radiator, so it's optimal to use the radiator with $$$sum_1$$$ sections. The cost of the radiator is equal to $$$(10^4)^2 = 10^8$$$.In the second room, you can install up to $$$10^4$$$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.In the third room, there $$$7$$$ variants to install radiators: $$$[6, 0]$$$, $$$[5, 1]$$$, $$$[4, 2]$$$, $$$[3, 3]$$$, $$$[2, 4]$$$, $$$[1, 5]$$$, $$$[0, 6]$$$. The optimal variant is $$$[3, 3]$$$ and it costs $$$3^2+ 3^2 = 18$$$. | Java 11 | standard input | [
"math"
] | 0ec973bf4ad209de9731818c75469541 | The first line contains single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of rooms. Each of the next $$$n$$$ lines contains the description of some room. The $$$i$$$-th line contains two integers $$$c_i$$$ and $$$sum_i$$$ ($$$1 \le c_i, sum_i \le 10^4$$$) — the maximum number of radiators and the minimum total number of sections in the $$$i$$$-th room, respectively. | 1,000 | For each room print one integer — the minimum possible cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | standard output | |
PASSED | 98f469dabb44795b6e8678d985d17509 | train_003.jsonl | 1574862600 | Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.Your house has $$$n$$$ rooms. In the $$$i$$$-th room you can install at most $$$c_i$$$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $$$k$$$ sections is equal to $$$k^2$$$ burles.Since rooms can have different sizes, you calculated that you need at least $$$sum_i$$$ sections in total in the $$$i$$$-th room. For each room calculate the minimum cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
int n=in.nextInt();
for(int i=0;i<n;i++)
{
long x=in.nextLong();
long y=in.nextLong();
if(y%x==0)
{
System.out.println(y*y/x);
}
else
{
System.out.println((y/x+1)*(y/x+1)*(y%x)+(y/x)*(y/x)*(x-(y%x)));
}
}
}
}
| Java | ["4\n1 10000\n10000 1\n2 6\n4 6"] | 1 second | ["100000000\n1\n18\n10"] | NoteIn the first room, you can install only one radiator, so it's optimal to use the radiator with $$$sum_1$$$ sections. The cost of the radiator is equal to $$$(10^4)^2 = 10^8$$$.In the second room, you can install up to $$$10^4$$$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.In the third room, there $$$7$$$ variants to install radiators: $$$[6, 0]$$$, $$$[5, 1]$$$, $$$[4, 2]$$$, $$$[3, 3]$$$, $$$[2, 4]$$$, $$$[1, 5]$$$, $$$[0, 6]$$$. The optimal variant is $$$[3, 3]$$$ and it costs $$$3^2+ 3^2 = 18$$$. | Java 11 | standard input | [
"math"
] | 0ec973bf4ad209de9731818c75469541 | The first line contains single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of rooms. Each of the next $$$n$$$ lines contains the description of some room. The $$$i$$$-th line contains two integers $$$c_i$$$ and $$$sum_i$$$ ($$$1 \le c_i, sum_i \le 10^4$$$) — the maximum number of radiators and the minimum total number of sections in the $$$i$$$-th room, respectively. | 1,000 | For each room print one integer — the minimum possible cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | standard output | |
PASSED | a6a4781a94abdf97d6917e9d90b076d3 | train_003.jsonl | 1574862600 | Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.Your house has $$$n$$$ rooms. In the $$$i$$$-th room you can install at most $$$c_i$$$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $$$k$$$ sections is equal to $$$k^2$$$ burles.Since rooms can have different sizes, you calculated that you need at least $$$sum_i$$$ sections in total in the $$$i$$$-th room. For each room calculate the minimum cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | 256 megabytes | import java.util.*;
import java.io.*;
public class Q2
{
static Print print;
public static void main(String args[]) throws Exception
{
Scan scan = new Scan();
print = new Print();
int T=scan.scanInt();
while(T-->0)
{
long i=scan.scanInt();
long ans=0;
long req=scan.scanLong();
while(i!=0)
{
ans+=(req/i)*(req/i);
req-=req/i;
i--;
}
print.println(ans);
}
print.close();
}
public static class Print {
private final BufferedWriter bw;
public Print() {
this.bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
public void print(Object object) throws IOException {
bw.append("" + object);
}
public void println(Object object) throws IOException {
print(object);
bw.append("\n");
}
public void close() throws IOException {
bw.close();
}
}
static class Scan {
private byte[] buf = new byte[1024 * 1024 * 4];
private int index;
private InputStream in;
private int total;
public Scan() {
in = System.in;
}
public int scan() throws IOException {
if (total < 0)
throw new InputMismatchException();
if (index >= total) {
index = 0;
total = in.read(buf);
if (total <= 0)
return -1;
}
return buf[index++];
}
public int scanInt() throws IOException {
int integer = 0;
int n = scan();
while (isWhiteSpace(n))
n = scan();
int neg = 1;
if (n == '-') {
neg = -1;
n = scan();
}
while (!isWhiteSpace(n)) {
if (n >= '0' && n <= '9') {
integer *= 10;
integer += n - '0';
n = scan();
} else
throw new InputMismatchException();
}
return neg * integer;
}
public double scanDouble() throws IOException {
double doub = 0;
int n = scan();
while (isWhiteSpace(n))
n = scan();
int neg = 1;
if (n == '-') {
neg = -1;
n = scan();
}
while (!isWhiteSpace(n) && n != '.') {
if (n >= '0' && n <= '9') {
doub *= 10;
doub += n - '0';
n = scan();
} else
throw new InputMismatchException();
}
if (n == '.') {
n = scan();
double temp = 1;
while (!isWhiteSpace(n)) {
if (n >= '0' && n <= '9') {
temp /= 10;
doub += (n - '0') * temp;
n = scan();
} else
throw new InputMismatchException();
}
}
return doub * neg;
}
public long scanLong() throws IOException {
long ret = 0;
long c = scan();
while (c <= ' ') {
c = scan();
}
boolean neg = (c == '-');
if (neg) {
c = scan();
}
do {
ret = ret * 10 + c - '0';
} while ((c = scan()) >= '0' && c <= '9');
if (neg) {
return -ret;
}
return ret;
}
public String scanString() throws IOException {
StringBuilder sb = new StringBuilder();
int n = scan();
while (isWhiteSpace(n))
n = scan();
while (!isWhiteSpace(n) || n == ' ') {
sb.append((char) n);
n = scan();
}
return sb.toString();
}
private boolean isWhiteSpace(int n) {
if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
return true;
return false;
}
}
}
| Java | ["4\n1 10000\n10000 1\n2 6\n4 6"] | 1 second | ["100000000\n1\n18\n10"] | NoteIn the first room, you can install only one radiator, so it's optimal to use the radiator with $$$sum_1$$$ sections. The cost of the radiator is equal to $$$(10^4)^2 = 10^8$$$.In the second room, you can install up to $$$10^4$$$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.In the third room, there $$$7$$$ variants to install radiators: $$$[6, 0]$$$, $$$[5, 1]$$$, $$$[4, 2]$$$, $$$[3, 3]$$$, $$$[2, 4]$$$, $$$[1, 5]$$$, $$$[0, 6]$$$. The optimal variant is $$$[3, 3]$$$ and it costs $$$3^2+ 3^2 = 18$$$. | Java 11 | standard input | [
"math"
] | 0ec973bf4ad209de9731818c75469541 | The first line contains single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of rooms. Each of the next $$$n$$$ lines contains the description of some room. The $$$i$$$-th line contains two integers $$$c_i$$$ and $$$sum_i$$$ ($$$1 \le c_i, sum_i \le 10^4$$$) — the maximum number of radiators and the minimum total number of sections in the $$$i$$$-th room, respectively. | 1,000 | For each room print one integer — the minimum possible cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | standard output | |
PASSED | 5342ad427839035927666a5d57aa9173 | train_003.jsonl | 1574862600 | Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.Your house has $$$n$$$ rooms. In the $$$i$$$-th room you can install at most $$$c_i$$$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $$$k$$$ sections is equal to $$$k^2$$$ burles.Since rooms can have different sizes, you calculated that you need at least $$$sum_i$$$ sections in total in the $$$i$$$-th room. For each room calculate the minimum cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | 256 megabytes | import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.lang.*;
public class MAin{
static int mod = 1000000007;
static InputReader in = new InputReader(System.in);
static PrintWriter pw = new PrintWriter(System.out);
public static void main(String[] args) throws Exception {
int t=in.readInt();
while(t-->0){
int a=in.readInt();
int b=in.readInt();
if(a>=b) {
System.out.println(b);
}
else{
int n=b/a;
int r=b%a;
int ans=(a-r)*n*n;
ans+=r*(n+1)*(n+1);
System.out.println(ans);
}
}
}
static String conc(int n) {
String[] s=new String[n+1];
s[4]="aabb";
if(n==4)
return s[4];
if(s[n/2]==null) {
s[n/2]=conc(n/2);
}
return s[n/2]+s[n/2];
}
static String sort(String s1) {
String s2="";
int n1=s1.length();
int[] a=new int[n1];
for(int i=0;i<n1;i++){
a[i]=s1.charAt(i);
}
Arrays.sort(a);
for(int i=0;i<n1;i++) {
s2+=(char)a[i];
}
return s2;
}
static boolean isVowel(char c) {
if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
return true;
return false;
}
static String replaceChar(String s,int a,char b) {
return s.substring(0,a)+b+s.substring(a+1,s.length());
}
static int[] nextIntArray(int n){
int[] arr= new int[n];
int i=0;
while(i<n){
arr[i++]=in.readInt();
}
return arr;
}
static long[] nextLongArray(int n){
long[]arr= new long[n];
int i=0;
while(i<n){
arr[i++]=in.readLong();
}
return arr;
}
static int[] nextIntArray1(int n) {
int[] arr= new int[n+1];
int i=1;
while(i<=n){
arr[i++]=in.readInt();
}
return arr;
}
static long[] nextLongArray1(int n){
long[]arr= new long[n+1];
int i=1;
while(i<=n) {
arr[i++]=in.readLong();
}
return arr;
}
static long gcd(long x, long y) {
if (x % y == 0)
return y;
else
return gcd(y, x % y);
}
static long pow(long n, long m) {
if(m==0)
return 1;
else if(m==1)
return n;
else {
long r=pow(n,m/2);
if(m%2==0)
return r*r;
else
return r*r*n;
}
}
static long max(long a,long b,long c) {
return Math.max(Math.max(a, b),c);
}
static long min(long a,long b,long c) {
return Math.min(Math.min(a, b), c);
}
static class Pair implements Comparable<Pair> {
int a, b;
Pair(int a, int b) {
this.a = a;
this.b = b;
}
public int compareTo(Pair o) {
if (this.a != o.a)
return Integer.compare(this.a, o.a);
else
return Integer.compare(this.b, o.b);
// return 0;
}
public boolean equals(Object o) {
if (o instanceof Pair) {
Pair p = (Pair) o;
return p.a == a && p.b == b;
}
return false;
}
public int hashCode() {
return new Integer(a).hashCode() * 31 + new Integer(b).hashCode();
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public double readDouble() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, readInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E')
return res * Math.pow(10, readInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public long readLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
| Java | ["4\n1 10000\n10000 1\n2 6\n4 6"] | 1 second | ["100000000\n1\n18\n10"] | NoteIn the first room, you can install only one radiator, so it's optimal to use the radiator with $$$sum_1$$$ sections. The cost of the radiator is equal to $$$(10^4)^2 = 10^8$$$.In the second room, you can install up to $$$10^4$$$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.In the third room, there $$$7$$$ variants to install radiators: $$$[6, 0]$$$, $$$[5, 1]$$$, $$$[4, 2]$$$, $$$[3, 3]$$$, $$$[2, 4]$$$, $$$[1, 5]$$$, $$$[0, 6]$$$. The optimal variant is $$$[3, 3]$$$ and it costs $$$3^2+ 3^2 = 18$$$. | Java 11 | standard input | [
"math"
] | 0ec973bf4ad209de9731818c75469541 | The first line contains single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of rooms. Each of the next $$$n$$$ lines contains the description of some room. The $$$i$$$-th line contains two integers $$$c_i$$$ and $$$sum_i$$$ ($$$1 \le c_i, sum_i \le 10^4$$$) — the maximum number of radiators and the minimum total number of sections in the $$$i$$$-th room, respectively. | 1,000 | For each room print one integer — the minimum possible cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | standard output | |
PASSED | 518da388d9e80e9ed4e0812793756db2 | train_003.jsonl | 1574862600 | Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.Your house has $$$n$$$ rooms. In the $$$i$$$-th room you can install at most $$$c_i$$$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $$$k$$$ sections is equal to $$$k^2$$$ burles.Since rooms can have different sizes, you calculated that you need at least $$$sum_i$$$ sections in total in the $$$i$$$-th room. For each room calculate the minimum cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | 256 megabytes | import java.util.*;
import java.io.*;
/*
*/
public class Main{
public static OutputStream out=new BufferedOutputStream(System.out);
//nl-->neew line; //l-->line; //arp-->array print; //arpnl-->array print new line
public static void nl(Object o) throws IOException{out.write((o+"\n").getBytes());}
public static void l(Object o) throws IOException{out.write((o+"").getBytes());}
public static void arp(int[] o) throws IOException{for(int i=0;i<o.length;i++) out.write((o[i]+" ").getBytes());}
public static void arpnl(int[] o) throws IOException{for(int i=0;i<o.length;i++) out.write((o[i]+"\n").getBytes());}
//
static int MOD=(int)1e9+7;
static int[][] pascal_trgl=new int[4005][4005];
//
public static void main(String[] args) throws IOException{
// long sttm=System.currentTimeMillis();
FastReader sc=new FastReader();
int n=sc.nextInt();
while(n-->0){
int c=sc.nextInt(),sum=sc.nextInt();
int ans=0;
int q=sum/c,rem=sum%c;
ans=((q+1)*(q+1)*rem)+(q*q*(c-rem));
nl(ans);
}
out.flush();
}
public static int nCr(int n,int r){
return pascal_trgl[n][r]%MOD;
}
public static void intiTriangle(){
for (int i = 0; i <= 4004; i++) {
Arrays.fill(pascal_trgl[i], 0);
}
pascal_trgl[0][0] = 1;
for (int i = 1; i <= 4004; i++) {
pascal_trgl[i][0] = 1;
for (int j = 1; j <= i; j++) {
pascal_trgl[i][j] = (pascal_trgl[i - 1][j - 1] + pascal_trgl[i - 1][j]) % MOD;
}
}
}
public static String decToBin(long val){
StringBuilder binstr=new StringBuilder();
while(val>0){
Long rem=val%2;val/=2;
binstr.append(Long.toString(rem));
}
binstr.reverse();
return new String(binstr);
}
public static long binToDec(String binstr){
long ans=0;
long mul=1;int val=0;
int n=binstr.length();
for(int i=0;i<n;i++){
if(binstr.charAt(n-1-i)=='1') val=1;
ans+=(mul*val);
val=0;
mul*=2;
}
return ans;
}
public static StringBuilder OR(long val1,long val2){
StringBuilder s=new StringBuilder();
while(val1>0 || val2>0){
long rem1=0,rem2=0;
if(val1>0) rem1=val1%2;
if(val2>0) rem2=val2%2;
val1/=2;val2/=2;
s.append(Long.toString(Math.max(rem1,rem2)));
}
s.reverse();
return s;
}
public static boolean dfsCycle(ArrayList<Integer>[] arrl,int[] vis,int st,int pr){
vis[st]=1;
int cupr=st;
for(int elm:arrl[st]){
if(vis[elm]==1 && elm!=pr){
return true;
}
else if(vis[elm]==0 && dfsCycle(arrl, vis, elm, cupr)){
return true;
}
}
vis[st]=2;
return false;
}
public static long powMOD(long n,long k){ //n-pow(k)
if(k==1){
return n%MOD;
}
if(k==0){
return 1;
}
long val=pow(n,k/2)%MOD;
if(k%2==0)return ((val%MOD)*(val%MOD))%MOD;
else return (((val*val)%MOD)*n)%MOD;
}
public static long pow(long n,long k){ //n-pow(k)
if(k==1){
return n;
}
if(k==0){
return 1;
}
long val=pow(n,k/2);
if(k%2==0)return ((val)*(val));
else return (((val*val))*n);
}
public static HashMap<Integer,Integer> lcm(int num){
ArrayList<Integer> arrl=new ArrayList<Integer>();
HashMap<Integer,Integer> map=new HashMap<Integer,Integer>();
while(num%2==0){
if(!map.containsKey(2)){
arrl.add(2);
map.put(2, 1);
}
else{
map.put(2,map.get(2)+1);
}
num/=2;
}
for(int i=3;i*i<=num;i+=2){
while(num%i==0){
if(!map.containsKey(i)){
arrl.add(i);
map.put(i, 1);
}
else{
map.put(i,map.get(i)+1);
}
num/=i;
}
}
if(num>2){
if(!map.containsKey(num)){
arrl.add(num);
map.put(num, 1);
}
else{
map.put(num,map.get(num)+1);
}
}
return map;
}
static long m=998244353l;
static long modInverse(long a,long m)
{
long m0 = m;
long y = 0l, x = 1l;
if (m == 1)
return 0l;
while (a > 1)
{
long q = a / m;
long t = m;
m = a % m;
a = t;
t = y;
y = x - q * y;
x = t;
}
if (x < 0)
x += m0;
return x;
}
public static int num_fact(int num){
ArrayList<Integer> arr=new ArrayList<Integer>();
int cnt=0;
for(int i=1;i*i<=num;i++){
if(num%i==0){
if(i*i==num){
cnt+=1;
}
else{
cnt+=2;
}
}
}
return cnt;
}
public static void sort_inc(int[][] arr,int col){ //change dimention if req
Arrays.sort(arr, new Comparator<int[]>() {
public int compare(final int[] entry1,final int[] entry2) {
if (entry1[col] < entry2[col]) //this is for dec
return 1;
else if(entry1[col]==entry2[col])
return 0;
else
return -1;
}
});
}
public static boolean prime(int n){
for(int i=2;i*i<=n;i++){
if(n%i==0){
return false;
}
}
return true;
}
static long gcd(long a, long b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
public static long lcmOfTwo(int a,int b){
return a*b/gcd(a,b);
}
}
class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next(){
while (st == null || !st.hasMoreElements()){
try{
st = new StringTokenizer(br.readLine());
}
catch (IOException e){
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try{
str = br.readLine();
}
catch (IOException e){
e.printStackTrace();
}
return str;
}
}
//Pair Task in process
// class Pair<D1,D2> extends Comparable{
// D1 v1;
// D2 v2;
// Pair(D1 a,D2 b){
// v1=a;v2=b;
// }
// } | Java | ["4\n1 10000\n10000 1\n2 6\n4 6"] | 1 second | ["100000000\n1\n18\n10"] | NoteIn the first room, you can install only one radiator, so it's optimal to use the radiator with $$$sum_1$$$ sections. The cost of the radiator is equal to $$$(10^4)^2 = 10^8$$$.In the second room, you can install up to $$$10^4$$$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.In the third room, there $$$7$$$ variants to install radiators: $$$[6, 0]$$$, $$$[5, 1]$$$, $$$[4, 2]$$$, $$$[3, 3]$$$, $$$[2, 4]$$$, $$$[1, 5]$$$, $$$[0, 6]$$$. The optimal variant is $$$[3, 3]$$$ and it costs $$$3^2+ 3^2 = 18$$$. | Java 11 | standard input | [
"math"
] | 0ec973bf4ad209de9731818c75469541 | The first line contains single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of rooms. Each of the next $$$n$$$ lines contains the description of some room. The $$$i$$$-th line contains two integers $$$c_i$$$ and $$$sum_i$$$ ($$$1 \le c_i, sum_i \le 10^4$$$) — the maximum number of radiators and the minimum total number of sections in the $$$i$$$-th room, respectively. | 1,000 | For each room print one integer — the minimum possible cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | standard output | |
PASSED | bf5048ad177e04b18e562e03c2c2a9b5 | train_003.jsonl | 1574862600 | Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.Your house has $$$n$$$ rooms. In the $$$i$$$-th room you can install at most $$$c_i$$$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $$$k$$$ sections is equal to $$$k^2$$$ burles.Since rooms can have different sizes, you calculated that you need at least $$$sum_i$$$ sections in total in the $$$i$$$-th room. For each room calculate the minimum cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | 256 megabytes | import java.math.BigInteger;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t > 0) {
int c = sc.nextInt();int sum = sc.nextInt();
int ans = 0;
if(c>=sum){
ans = sum;
}else{
for(int i=c;i>0;i--){
int num = sum/i;
sum-=num;
ans+=(num*num);
}
}
System.out.println(ans);
t--;
}
}
}
| Java | ["4\n1 10000\n10000 1\n2 6\n4 6"] | 1 second | ["100000000\n1\n18\n10"] | NoteIn the first room, you can install only one radiator, so it's optimal to use the radiator with $$$sum_1$$$ sections. The cost of the radiator is equal to $$$(10^4)^2 = 10^8$$$.In the second room, you can install up to $$$10^4$$$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.In the third room, there $$$7$$$ variants to install radiators: $$$[6, 0]$$$, $$$[5, 1]$$$, $$$[4, 2]$$$, $$$[3, 3]$$$, $$$[2, 4]$$$, $$$[1, 5]$$$, $$$[0, 6]$$$. The optimal variant is $$$[3, 3]$$$ and it costs $$$3^2+ 3^2 = 18$$$. | Java 11 | standard input | [
"math"
] | 0ec973bf4ad209de9731818c75469541 | The first line contains single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of rooms. Each of the next $$$n$$$ lines contains the description of some room. The $$$i$$$-th line contains two integers $$$c_i$$$ and $$$sum_i$$$ ($$$1 \le c_i, sum_i \le 10^4$$$) — the maximum number of radiators and the minimum total number of sections in the $$$i$$$-th room, respectively. | 1,000 | For each room print one integer — the minimum possible cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | standard output | |
PASSED | cabde290faa40ab30ae61e11751a6d68 | train_003.jsonl | 1574862600 | Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.Your house has $$$n$$$ rooms. In the $$$i$$$-th room you can install at most $$$c_i$$$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $$$k$$$ sections is equal to $$$k^2$$$ burles.Since rooms can have different sizes, you calculated that you need at least $$$sum_i$$$ sections in total in the $$$i$$$-th room. For each room calculate the minimum cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author ky112233
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
int testCount = Integer.parseInt(in.next());
for (int i = 1; i <= testCount; i++)
solver.solve(i, in, out);
out.close();
}
static class TaskA {
public void solve(int testNumber, Scanner in, PrintWriter out) {
int c = in.nextInt();
int sum = in.nextInt();
int temp = sum / c;
if (sum % c == 0) {
long num = (long) Math.pow(temp, 2) * c;
out.println(num);
} else {
int temp2 = sum % c;
long num = (long) Math.pow(temp, 2) * (c - temp2) + (long) Math.pow(temp + 1, 2) * temp2;
out.println(num);
}
}
}
}
| Java | ["4\n1 10000\n10000 1\n2 6\n4 6"] | 1 second | ["100000000\n1\n18\n10"] | NoteIn the first room, you can install only one radiator, so it's optimal to use the radiator with $$$sum_1$$$ sections. The cost of the radiator is equal to $$$(10^4)^2 = 10^8$$$.In the second room, you can install up to $$$10^4$$$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.In the third room, there $$$7$$$ variants to install radiators: $$$[6, 0]$$$, $$$[5, 1]$$$, $$$[4, 2]$$$, $$$[3, 3]$$$, $$$[2, 4]$$$, $$$[1, 5]$$$, $$$[0, 6]$$$. The optimal variant is $$$[3, 3]$$$ and it costs $$$3^2+ 3^2 = 18$$$. | Java 11 | standard input | [
"math"
] | 0ec973bf4ad209de9731818c75469541 | The first line contains single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of rooms. Each of the next $$$n$$$ lines contains the description of some room. The $$$i$$$-th line contains two integers $$$c_i$$$ and $$$sum_i$$$ ($$$1 \le c_i, sum_i \le 10^4$$$) — the maximum number of radiators and the minimum total number of sections in the $$$i$$$-th room, respectively. | 1,000 | For each room print one integer — the minimum possible cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | standard output | |
PASSED | bbbf4da97aa92fc59c0a77be0bb89e57 | train_003.jsonl | 1574862600 | Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.Your house has $$$n$$$ rooms. In the $$$i$$$-th room you can install at most $$$c_i$$$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $$$k$$$ sections is equal to $$$k^2$$$ burles.Since rooms can have different sizes, you calculated that you need at least $$$sum_i$$$ sections in total in the $$$i$$$-th room. For each room calculate the minimum cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int T = input.nextInt();
for (int i = 0; i < T; i++){
int c = input.nextInt();
int sum = input.nextInt();
long ans = 0;
int n = sum/c;
int more = sum%c;
for (int j = 0; j < c-more; j++)
ans+=(n*n);
for (int j = 0; j < more; j++)
ans+=((n+1)*(1+n));
System.out.println(ans);
}
}
}
| Java | ["4\n1 10000\n10000 1\n2 6\n4 6"] | 1 second | ["100000000\n1\n18\n10"] | NoteIn the first room, you can install only one radiator, so it's optimal to use the radiator with $$$sum_1$$$ sections. The cost of the radiator is equal to $$$(10^4)^2 = 10^8$$$.In the second room, you can install up to $$$10^4$$$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.In the third room, there $$$7$$$ variants to install radiators: $$$[6, 0]$$$, $$$[5, 1]$$$, $$$[4, 2]$$$, $$$[3, 3]$$$, $$$[2, 4]$$$, $$$[1, 5]$$$, $$$[0, 6]$$$. The optimal variant is $$$[3, 3]$$$ and it costs $$$3^2+ 3^2 = 18$$$. | Java 11 | standard input | [
"math"
] | 0ec973bf4ad209de9731818c75469541 | The first line contains single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of rooms. Each of the next $$$n$$$ lines contains the description of some room. The $$$i$$$-th line contains two integers $$$c_i$$$ and $$$sum_i$$$ ($$$1 \le c_i, sum_i \le 10^4$$$) — the maximum number of radiators and the minimum total number of sections in the $$$i$$$-th room, respectively. | 1,000 | For each room print one integer — the minimum possible cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | standard output | |
PASSED | 110c5b3ed96cf33094f09c6beb600107 | train_003.jsonl | 1574862600 | Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.Your house has $$$n$$$ rooms. In the $$$i$$$-th room you can install at most $$$c_i$$$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $$$k$$$ sections is equal to $$$k^2$$$ burles.Since rooms can have different sizes, you calculated that you need at least $$$sum_i$$$ sections in total in the $$$i$$$-th room. For each room calculate the minimum cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | 256 megabytes | import java.util.*;
public class a
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
int j;
for(int i=0;i<t;i++)
{
int c=sc.nextInt();
int s=sc.nextInt();
//special cases
if(c==1)
System.out.println(s*s);
else if(s<c)
System.out.println(s);
//when perfectlt divisible
else if(s%c==0)
{
int p=s/c;
System.out.println(p*p*c);
}
else if(s%c!=0)
{
int p1=s/c;
int m=s-p1*c;
int n=c-m;
int tot=p1*p1*n + (p1+1)*(p1+1)*m;
System.out.println(tot);
}
}
}
}
| Java | ["4\n1 10000\n10000 1\n2 6\n4 6"] | 1 second | ["100000000\n1\n18\n10"] | NoteIn the first room, you can install only one radiator, so it's optimal to use the radiator with $$$sum_1$$$ sections. The cost of the radiator is equal to $$$(10^4)^2 = 10^8$$$.In the second room, you can install up to $$$10^4$$$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.In the third room, there $$$7$$$ variants to install radiators: $$$[6, 0]$$$, $$$[5, 1]$$$, $$$[4, 2]$$$, $$$[3, 3]$$$, $$$[2, 4]$$$, $$$[1, 5]$$$, $$$[0, 6]$$$. The optimal variant is $$$[3, 3]$$$ and it costs $$$3^2+ 3^2 = 18$$$. | Java 11 | standard input | [
"math"
] | 0ec973bf4ad209de9731818c75469541 | The first line contains single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of rooms. Each of the next $$$n$$$ lines contains the description of some room. The $$$i$$$-th line contains two integers $$$c_i$$$ and $$$sum_i$$$ ($$$1 \le c_i, sum_i \le 10^4$$$) — the maximum number of radiators and the minimum total number of sections in the $$$i$$$-th room, respectively. | 1,000 | For each room print one integer — the minimum possible cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | standard output | |
PASSED | b5b65e86ee364735231cf854f64f4e0a | train_003.jsonl | 1574862600 | Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.Your house has $$$n$$$ rooms. In the $$$i$$$-th room you can install at most $$$c_i$$$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $$$k$$$ sections is equal to $$$k^2$$$ burles.Since rooms can have different sizes, you calculated that you need at least $$$sum_i$$$ sections in total in the $$$i$$$-th room. For each room calculate the minimum cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | 256 megabytes | import java.util.*;
import java.math.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int tt = 0; tt < t; tt++) {
long c = in.nextLong();
long s = in.nextLong();
long rem = s % c;
long div = s / c;
long ans = rem * ((div + 1) * (div + 1));
ans += (c - rem) * (div * div);
System.out.println(ans);
}
}
} | Java | ["4\n1 10000\n10000 1\n2 6\n4 6"] | 1 second | ["100000000\n1\n18\n10"] | NoteIn the first room, you can install only one radiator, so it's optimal to use the radiator with $$$sum_1$$$ sections. The cost of the radiator is equal to $$$(10^4)^2 = 10^8$$$.In the second room, you can install up to $$$10^4$$$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.In the third room, there $$$7$$$ variants to install radiators: $$$[6, 0]$$$, $$$[5, 1]$$$, $$$[4, 2]$$$, $$$[3, 3]$$$, $$$[2, 4]$$$, $$$[1, 5]$$$, $$$[0, 6]$$$. The optimal variant is $$$[3, 3]$$$ and it costs $$$3^2+ 3^2 = 18$$$. | Java 11 | standard input | [
"math"
] | 0ec973bf4ad209de9731818c75469541 | The first line contains single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of rooms. Each of the next $$$n$$$ lines contains the description of some room. The $$$i$$$-th line contains two integers $$$c_i$$$ and $$$sum_i$$$ ($$$1 \le c_i, sum_i \le 10^4$$$) — the maximum number of radiators and the minimum total number of sections in the $$$i$$$-th room, respectively. | 1,000 | For each room print one integer — the minimum possible cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | standard output | |
PASSED | 9aa2ac170d35acdee9f7fbcab72f608d | train_003.jsonl | 1574862600 | Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.Your house has $$$n$$$ rooms. In the $$$i$$$-th room you can install at most $$$c_i$$$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $$$k$$$ sections is equal to $$$k^2$$$ burles.Since rooms can have different sizes, you calculated that you need at least $$$sum_i$$$ sections in total in the $$$i$$$-th room. For each room calculate the minimum cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | 256 megabytes | import java.util.Scanner;
public class A
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
while(n!=0)
{
int c = sc.nextInt();
int s = sc.nextInt();
int a = s/c;
int b = s%c;
System.out.println(a*a*(c-b)+b*(a+1)*(a+1));
n--;
}
}
} | Java | ["4\n1 10000\n10000 1\n2 6\n4 6"] | 1 second | ["100000000\n1\n18\n10"] | NoteIn the first room, you can install only one radiator, so it's optimal to use the radiator with $$$sum_1$$$ sections. The cost of the radiator is equal to $$$(10^4)^2 = 10^8$$$.In the second room, you can install up to $$$10^4$$$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.In the third room, there $$$7$$$ variants to install radiators: $$$[6, 0]$$$, $$$[5, 1]$$$, $$$[4, 2]$$$, $$$[3, 3]$$$, $$$[2, 4]$$$, $$$[1, 5]$$$, $$$[0, 6]$$$. The optimal variant is $$$[3, 3]$$$ and it costs $$$3^2+ 3^2 = 18$$$. | Java 11 | standard input | [
"math"
] | 0ec973bf4ad209de9731818c75469541 | The first line contains single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of rooms. Each of the next $$$n$$$ lines contains the description of some room. The $$$i$$$-th line contains two integers $$$c_i$$$ and $$$sum_i$$$ ($$$1 \le c_i, sum_i \le 10^4$$$) — the maximum number of radiators and the minimum total number of sections in the $$$i$$$-th room, respectively. | 1,000 | For each room print one integer — the minimum possible cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | standard output | |
PASSED | 58a1424aff63796d15145b2225762139 | train_003.jsonl | 1574862600 | Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.Your house has $$$n$$$ rooms. In the $$$i$$$-th room you can install at most $$$c_i$$$ heating radiators. Each radiator can have several sections, but the cost of the radiator with $$$k$$$ sections is equal to $$$k^2$$$ burles.Since rooms can have different sizes, you calculated that you need at least $$$sum_i$$$ sections in total in the $$$i$$$-th room. For each room calculate the minimum cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String args[])
{
int n;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
for(int i=0;i<n;i++)
{
int c,sum,d,k=1;
c = sc.nextInt();
sum = sc.nextInt();
if(c>sum)
{
System.out.println(sum);
}
else if(c==sum)
{
System.out.println(sum);
}
else
{
Vector arr = new Vector();
Enumeration x;
int l = c;
for(int j=0;j<l;j++)
{
d = sum/c;
arr.add(d);
sum = sum - d;
c = c - 1;
}
x = arr.elements();
long sums = 0;
while(x.hasMoreElements())
{
int m =(int) x.nextElement();
sums = sums + m*m;
//System.out.println(m);
}
System.out.println(sums);
}
}
}
} | Java | ["4\n1 10000\n10000 1\n2 6\n4 6"] | 1 second | ["100000000\n1\n18\n10"] | NoteIn the first room, you can install only one radiator, so it's optimal to use the radiator with $$$sum_1$$$ sections. The cost of the radiator is equal to $$$(10^4)^2 = 10^8$$$.In the second room, you can install up to $$$10^4$$$ radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.In the third room, there $$$7$$$ variants to install radiators: $$$[6, 0]$$$, $$$[5, 1]$$$, $$$[4, 2]$$$, $$$[3, 3]$$$, $$$[2, 4]$$$, $$$[1, 5]$$$, $$$[0, 6]$$$. The optimal variant is $$$[3, 3]$$$ and it costs $$$3^2+ 3^2 = 18$$$. | Java 11 | standard input | [
"math"
] | 0ec973bf4ad209de9731818c75469541 | The first line contains single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of rooms. Each of the next $$$n$$$ lines contains the description of some room. The $$$i$$$-th line contains two integers $$$c_i$$$ and $$$sum_i$$$ ($$$1 \le c_i, sum_i \le 10^4$$$) — the maximum number of radiators and the minimum total number of sections in the $$$i$$$-th room, respectively. | 1,000 | For each room print one integer — the minimum possible cost to install at most $$$c_i$$$ radiators with total number of sections not less than $$$sum_i$$$. | standard output | |
PASSED | e626f614a5776186cf7b6a4413893898 | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes | import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int m =sc.nextInt() ,n =sc.nextInt();
int a [] = new int[m];
for(int i=0;i<m;i++){
a[i] = sc.nextInt();
}
Arrays.sort(a);
int sum = 0;
for(int i=0;i<n;i++){
if(a[i]<=0)
sum+= Math.abs(a[i]);
}
System.out.println(sum);
}
} | Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | 7cd27d3b003d82ebe43d8c5cab26b39d | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes |
import java.util.Arrays;
import java.util.Scanner;
/**
*
* @author Ameera
* Codeforces: 34 B
*/
public class sale {
public static void main(String[] args){
Scanner in = new Scanner (System.in);
int n = in.nextInt();
int m = in.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i]=in.nextInt();
// System.out.print(a[i] + " ");
}
// System.out.println();
Arrays.sort(a);
int sum = 0;
int[] b = new int[m];
for (int i = 0 , j = 0; i < m; i++ , j++) {
sum+=a[i];
b[j]=sum;
//System.out.print(b[j]+" ");
}
// System.out.println();
// find max
int min = b[0];
for (int i = 1; i < m; i++) {
if(b[i]<min){
min = b[i];
}
}
if(min*-1<0){
System.out.println(0);
}
else{
System.out.println(min*-1);
}
}
}
| Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | 049367d9d0ea7ce3114bd5de5d59446e | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes | import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt(),earn=0,count=0;
int[] a = new int[n];
for(int i=0;i<n;i++)
a[i] = sc.nextInt();
Arrays.sort(a);
for(int i=0;i<n;i++){
if (count==m){
break;
}
if(a[i]<0){
earn += Math.abs(a[i]);
count++;
}
}
System.out.println(earn);
}
}
| Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | dd6ff61871de04d3f87f3aa0f8b89c07 | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes | import java.io.*;
import java.util.*;
public class Mohammad {
//---------------------------------------------Main-----------------------------------------------//
public static void Mohammad_AboHasan() throws IOException{
FastReader fr = new FastReader();
int n = fr.nextInt(), m = fr.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = fr.nextInt();
Arrays.sort(a);
int c = 0, s = 0;
while(c < n && a[c] < 0 && m-->0){
s += a[c++];}
System.out.println(Math.abs(s));
}
public static void main(String[] args) throws IOException{
Mohammad_AboHasan();
}
//---------------------------------------------FAST I/O-----------------------------------------------//
static class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() throws IOException{
while (st == null || !st.hasMoreElements()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
int nextInt() throws IOException{
return Integer.parseInt(next());
}
long nextLong() throws IOException{
return Long.parseLong(next());
}
double nextDouble() throws IOException{
return Double.parseDouble(next());
}
String nextLine() throws IOException{
String s = br.readLine();
return s;
}
}
} | Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | c088254ae6e7d24ed91029d8108bc754 | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes | import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.*;
import java.math.*;
import java.io.*;
import java.text.*;
public class Main
{
//Life's a bitch
public static boolean[] sieve(long n)
{
boolean[] prime = new boolean[(int)n+1];
Arrays.fill(prime,true);
prime[0] = false;
prime[1] = false;
long m = (long)Math.sqrt(n);
for(int i=2;i<=m;i++)
{
if(prime[i])
{
for(int k=i*i;k<=n;k+=i)
{
prime[k] = false;
}
}
}
return prime;
}
static long GCD(long a,long b)
{
if(a==0 || b==0)
{
return 0;
}
if(a==b)
{
return a;
}
if(a>b)
{
return GCD(a-b,b);
}
return GCD(a,b-a);
}
static long CountCoPrimes(long n)
{
long res = n;
for(int i=2;i*i<=n;i++)
{
if(n%i==0)
{
while(n%i==0)
{
n/=i;
}
res-=res/i;
}
}
if(n>1)
{
res-=res/n;
}
return res;
}
//fastest way to find x**n
static long modularExponentiation(long x,long n)
{
long res = 1;
while(n>0)
{
if(n%2==1)
{
res = (res*x);
}
x =(x*x);
n/=2;
}
return res;
}
static long lcm(long a,long b)
{
return (a*b)/GCD(a,b);
}
static boolean prime(int n)
{
for(int i=2;i*i<=n;i++)
{
if(i%2==0 ||i%3==0)
{
return false;
}
}
return true;
}
public static void main(String[] args) throws IOException
{
new Main().run();
}
static void reverse(long[] a,long n)
{
int start=0;
int end = (int)n;
while(start!=end)
{
long temp = a[start];
a[start] = a[end];
a[end] = temp;
start++;
end--;
}
}
static long findGCD(ArrayList<Long> arr, long n)
{
long result = arr.get(0);
for (int i = 1; i < n; i++)
result = GCD(arr.get(i), result);
return result;
}
static Scanner in = new Scanner(System.in);
static void run() throws IOException
{
int n = ni();
int m = ni();
int[] a = new int[n];
for(int i=0;i<n;i++)
{
a[i] = ni();
}
int ans =0;
Arrays.sort(a);
for(int i=0;i<m;i++){
if(a[i]<0){
ans+=a[i];
}
}
printL(Math.abs(ans));
}
//xor range query
static long xor(long n)
{
if(n%4==0)
{
return n;
}
if(n%4==1)
{
return 1;
}
if(n%4==2)
{
return n+1;
}
return 0;
}
static long xor(long a,long b)
{
return xor(b)^xor(a-1);
}
static void printL(long a)
{
System.out.println(a);
}
static void printS(String s)
{
System.out.println(s);
}
static void printD(Double d)
{
System.out.println(d);
}
static void swap(char c,char p)
{
char t = c;
c = p;
p = t;
}
static long max(long n,long m)
{
return Math.max(n,m);
}
static long min(long n,long m)
{
return Math.min(n,m);
}
static double nd() throws IOException
{
return Double.parseDouble(in.next());
}
static int ni() throws IOException
{
return Integer.parseInt(in.next());
}
static long nl() throws IOException
{
return Long.parseLong(in.next());
}
static String si() throws IOException
{
return in.next();
}
static int abs(int n)
{
return Math.abs(n);
}
static class Scanner
{
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));}
public String next() throws IOException
{
while (st == null || !st.hasMoreTokens())
{
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
public int nextInt() throws IOException {return Integer.parseInt(next());}
public long nextLong() throws IOException {return Long.parseLong(next());}
public String nextLine() throws IOException {return br.readLine();}
public boolean ready() throws IOException {return br.ready();}
}
}
class Pair implements Comparable<Pair>
{
int x;
int y;
public Pair(int x,int y)
{
this.x = x;
this.y = y;
}
public int compareTo(Pair o)
{
return this.x-o.x;
}
} | Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | 524b64ee487d03ff5e9b02d8de1c749a | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes | import java.util.Scanner;
import java.util.Arrays;
public class Main{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int minsum=0;
int array[]=new int[100];
for(int i=0;i<n;i++) {
array[i]=sc.nextInt();
}
for(int i=0;i<n-1;i++) {
for(int j=0;j<n-1-i;j++) {
if(array[j]>array[j+1]) {
int temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
}
}
}
if(m<=n) {
for(int i=0; array[i]<0 && i<m ;i++) {
if(array[i]<0) {
minsum=minsum+array[i];
}
}
}
System.out.println((-1)*minsum);
}
}
| Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | adbe7de8ac68170a8c029aa19a243141 | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes | import java.util.Scanner;
import java.util.Arrays;
public class Main{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int minsum=0;
int array[]=new int[100];
for(int i=0;i<n;i++) {
array[i]=sc.nextInt();
}
Arrays.sort(array);
if(m<=n) {
for(int i=0; array[i]<0 && i<m ;i++) {
if(array[i]<0) {
minsum=minsum+array[i];
}
}
}
System.out.println((-1)*minsum);
}
}
| Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | 529a2980c0cf44d0bf86cf85b29c3078 | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes | import java.util.*;
/**
* Created by phil on 2/15/2018.
*/
public class B34_Sale {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int nTVForSale = sc.nextInt();
int nCanCarry = sc.nextInt();
int numTVsBought = 0;
int moneyEarned = 0;
List<Integer> prices = new LinkedList<>();
for (int i=0; i<nTVForSale; i++) {
int a = sc.nextInt();
if (a < 0) {
prices.add(a);
}
}
Collections.sort(prices);
for (int p: prices) {
if (numTVsBought < nCanCarry) {
moneyEarned += (-1) * p;
numTVsBought++;
}
}
System.out.println(moneyEarned);
}
}
| Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | 6caf444e76233e0fe1892a4020a8883d | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes | 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.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
public class Main {
static PrintWriter pr = new PrintWriter(System.out);
public static void main(String args[]) throws IOException{
//FileReader in = new FileReader("C:/test.txt");
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int a[] = new int[n];
for(int i=0; i<n; i++)
a[i] = sc.nextInt();
Arrays.sort(a);
int ans=0;
for(int i=0; i<n; i++){
if(m==0 || a[i]>=0)
break;
ans+=Math.abs(a[i]);
m--;
}
pr.println(ans);
pr.close();
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(String f) throws FileNotFoundException {
br = new BufferedReader(new FileReader(f));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public boolean ready() throws IOException {
return br.ready();
}
public int[] nextIntArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public int[] nextIntArray1(int n) throws IOException {
int[] a = new int[n + 1];
for (int i = 1; i <= n; i++)
a[i] = nextInt();
return a;
}
public int[] shuffle(int[] a, int n) {
int[] b = new int[n];
for (int i = 0; i < n; i++)
b[i] = a[i];
Random r = new Random();
for (int i = 0; i < n; i++) {
int j = i + r.nextInt(n - i);
int t = b[i];
b[i] = b[j];
b[j] = t;
}
return b;
}
public int[] nextIntArraySorted(int n) throws IOException {
int[] a = nextIntArray(n);
a = shuffle(a, n);
Arrays.sort(a);
return a;
}
public long[] nextLongArray(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public long[] nextLongArray1(int n) throws IOException {
long[] a = new long[n + 1];
for (int i = 1; i <= n; i++)
a[i] = nextLong();
return a;
}
public long[] nextLongArraySorted(int n) throws IOException {
long[] a = nextLongArray(n);
Random r = new Random();
for (int i = 0; i < n; i++) {
int j = i + r.nextInt(n - i);
long t = a[i];
a[i] = a[j];
a[j] = t;
}
Arrays.sort(a);
return a;
}
}
//
} | Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | 059e70c70a9072e7dff58a0df316aa29 | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes | import java.util.*;
public class CodeForce{
public static void main(String [] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int sum=0;
ArrayList<Integer> arr=new ArrayList<Integer>(1);
while(n-->0){
int a=sc.nextInt();
if(a<0){arr.add(Math.abs(a));}
}
int b[]=new int[arr.size()];
for(int i=0;i<arr.size();i++){
b[i]=arr.get(i);
}
Arrays.sort(b);
for(int i=0;i<b.length&&m-->0;i++)sum=sum+b[b.length-1-i];
System.out.println(sum);
}
}
| Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | 304237e579ab9ceeb6de1c36e4ce7a91 | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.StringTokenizer;
import javafx.util.converter.BigIntegerStringConverter;
import java.util.*;
/**
*
* @author Ahmad
*/
public class JavaApplication1 {
public static void main (String[] args) throws IOException, Exception {
FastReader console = new FastReader();
int n = console.nextInt() ;
int m = console.nextInt() ;
int x[] = new int [n] ;
long min = Integer.MAX_VALUE ;
int count = 0 ;
for (int i=0 ; i<x.length ; i++){
x[i]=console.nextInt() ;
if (x[i]<0){
count ++ ;
}
}
Sorting.bucketSort(x, n) ;
if (count==0){
System.out.println("0");
}
else {
for (int i=0 ; i<x.length-(m-1) ; i++){
long sum = 0 ;
for (int j=i ; j<m ; j++){
sum+=x[j] ;
if (sum<min){
min=sum ;
}
}
}
System.out.println(Math.abs(min));
}
}
}
class Sorting{
public static int[] bucketSort(int[] array, int bucketCount) {
if (bucketCount <= 0) throw new IllegalArgumentException("Invalid bucket count");
if (array.length <= 1) return array; //trivially sorted
int high = array[0];
int low = array[0];
for (int i = 1; i < array.length; i++) { //find the range of input elements
if (array[i] > high) high = array[i];
if (array[i] < low) low = array[i];
}
double interval = ((double)(high - low + 1))/bucketCount; //range of one bucket
ArrayList<Integer> buckets[] = new ArrayList[bucketCount];
for (int i = 0; i < bucketCount; i++) { //initialize buckets
buckets[i] = new ArrayList();
}
for (int i = 0; i < array.length; i++) { //partition the input array
buckets[(int)((array[i] - low)/interval)].add(array[i]);
}
int pointer = 0;
for (int i = 0; i < buckets.length; i++) {
Collections.sort(buckets[i]); //mergeSort
for (int j = 0; j < buckets[i].size(); j++) { //merge the buckets
array[pointer] = buckets[i].get(j);
pointer++;
}
}
return array;
}
}
class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
| Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | 576d98c6b775a0490ee4ed9bde3ae07a | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes | import java.util.* ;
public class codeforces {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int m=in.nextInt();
int[] sets=new int[n];
for(int i=0;i<n;i++) {
sets[i]=in.nextInt();
}
Arrays.sort(sets);
int money=0;
for(int i=0;i<m;i++) {
if(sets[i]>0)break;
money+=sets[i];
}
System.out.println(money*(-1));
}
} | Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | 9321ca7f13e78216af0441d4d1b752a1 | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Sale {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String line = reader.readLine();
String[] values = line.split(" ");
int n = Integer.parseInt(values[0]);
int m = Integer.parseInt(values[1]);
String lineWithElementArrayB = reader.readLine();
int[] arrayPrice = Arrays.stream(lineWithElementArrayB.split(" "))
.mapToInt(Integer::parseInt)
.toArray();
Arrays.sort(arrayPrice);
int earn = 0;
for (int i = 0; i < m; i++) {
if (arrayPrice[i] < 0) {
earn = earn + Math.abs(arrayPrice[i]);
}
}
System.out.println(earn);
}
} | Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | f5643230cb3fb5da3a2109742cd0675c | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int NoInput=sc.nextInt();
int Total=sc.nextInt();
sc.nextLine();
int[] a=new int[NoInput];
for(int i=0;i<NoInput;i++)
{
a[i]=sc.nextInt();
}
for(int i=0;i<NoInput;i++)
{
for(int j=i+1;j<NoInput;j++)
{
if(a[j]<a[i])
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
int sum=0;
for(int i=0;i<Total;i++)
{
if(a[i]<0)
sum=sum+a[i];
}
System.out.println((-1)*sum);
}
}
| Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | 599f10b5d61626e5e14eac1cc9bc7965 | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes |
import java.util.Arrays;
import java.util.Scanner;
public class Sale {
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int ar[]=new int[n];
for(int i=0;i<n;i++)
{
ar[i]=sc.nextInt();
}
Arrays.sort(ar);
int x=0;
for(int i=0;i<m;i++)
{
if(ar[i]<=0)
x=x+ar[i];
}
System.out.println(-x);
}
}
| Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | 3a9355c14926c16558a8396c1356e359 | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes | import java.io.*;
import java.util.*;
public class sale{
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int a[]=new int[n];
int b[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
int s=0;
int k=0;
for(int i=0;i<n;i++)
{
if(a[i]<0)
{
b[k]=(-a[i]);
k++;
}
}
int c[]=new int[k];
for(int i=0;i<k;i++)
{
c[i]=b[i];
}
Arrays.sort(c);
int l=0;
for(int i=k-1;i>=0;i--)
{
if(l<m)
{
s=s+c[i];
l++;
}
}
/*for(int i=0;i<n;i++)
{
if(a[i]<0 && k<m)
{
s=s+(-a[i]);
k++;
}
}*/
System.out.println(s);
}
} | Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | fe051e414afa8d2db7219dacd2b5f926 | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes | import java.util.*;
import java.io.*;
import javafx.util.Pair;
public class Param
{
public static void main( String[]args)
{
Scanner param=new Scanner(System.in);
int n=param.nextInt();
int k=param.nextInt();
int arr[]=new int[n];
for(int i=0;i<n;i++){
arr[i]=param.nextInt();
}
Arrays.sort(arr);
int sum=0;
int count=0;
for(int i=0;i<n;i++){
if(arr[i]>=0||count>k-1){
break;
}
else{
sum+=arr[i];
count++;
}
}
System.out.println(Math.abs(sum));
}
} | Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | 1eca1b94739a286a5410efc1286af005 | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes |
import java.util.*;
import java.lang.*;
import java.io.*;
public class sale
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int count=0,sum=0;
//int[] arr = new arr[n];
List<Integer> li = new ArrayList<>();
for(int i=0;i<n;i++){
int x = sc.nextInt();
li.add(x);
}
Collections.sort(li);
for(int i=0;i<m;i++){
if(li.get(i)<0){
sum = sum + Math.abs(li.get(i));
}
}
System.out.println(sum);
}
}
| Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | c413919e5299d32d3fa3a2f814bb24d2 | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Collections;
import java.util.ArrayList;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Vishal Burman
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
BSale solver = new BSale();
solver.solve(1, in, out);
out.close();
}
static class BSale {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
int m = in.nextInt();
int a[] = new int[n];
ArrayList<Integer> list = new ArrayList<>();
for (int i = -0; i < n; i++) {
a[i] = in.nextInt();
if (a[i] < 0)
list.add(Math.abs(a[i]));
}
Collections.sort(list);
Collections.reverse(list);
int sum = 0;
for (int i = 0; i < list.size(); i++) {
if (i + 1 <= m)
sum += list.get(i);
}
out.println(sum);
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
| Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | 8b7fbfe1723204b0689294a948f6c72e | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes |
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class Sale {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int m = s.nextInt();
int[] arr = new int[n];
int c = 0, indx = 0;
;
ArrayList<Integer> ll = new ArrayList<>();
for (int i = 0; i < n; i++) {
arr[i] = s.nextInt();
if(arr[i]<0) {
ll.add((arr[i]));
}
}
Collections.sort(ll);
for(int i=0;i<Math.min(ll.size(), m);i++) {
c+=Math.abs(ll.get(i));
}
System.out.println(c);
}
}
| Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | 7a4bcc024109358cb9ae40fe0d59ac96 | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes |
import java.io.PrintWriter;
import java.util.*;
import java.util.Arrays ;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
public class Test{
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
static int find(String s){
for (int i = 0; i < s.length(); i++) {
if(s.charAt(i)=='^'){
return i ;
}
}
return -1 ;
}
static String ch(long[]x,long b){
for (int i = 0; i < x.length; i++) {
if(x[i]==b)return "YES" ;
}
return "NO" ;
}
public static void main(String[] args) throws IOException {
PrintWriter pw = new PrintWriter(System.out);
// Reader in =new Reader ();
Scanner in =new Scanner (System.in);
int n = in.nextInt() ;
int m =in.nextInt() ;
int x[]=new int[n] ;
for (int i = 0; i < n; i++) {
x[i] =in.nextInt() ;
}
Arrays.sort(x);
long sum =0 ;
for (int i = 0; i < m; i++) {
if(x[i]<0){
sum+=x[i] ;
}else break ;
}
System.out.println((sum)*-1);
pw.close();
}} | Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | dcd3a2ce094f9cc0f82055dcb5401749 | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes | import java.util.Scanner;
public class B34 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int []a=new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
for(int i=0;i<n;i++){
for(int ii=0;ii<n-1;ii++){
if(a[ii]>a[ii+1]){
int d=a[ii];
a[ii]=a[ii+1];
a[ii+1]=d;
}
}
}
int c=0;
for(int i=0;i<m;i++){
if(a[i]<=0){
c=c+a[i];}
}
System.out.println(-c);
}
}
| Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 6 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | 4409c31ee79bf2084576d3ea51986422 | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.StreamTokenizer;
import java.io.Writer;
import java.util.Arrays;
import java.util.Hashtable;
public class Main {
static class MJ{
static class ArrEl{
public static int i, v;
ArrEl(){}
ArrEl(int index, int value){
i = index; v = value;
}
@SuppressWarnings("static-access")
public static ArrEl getMax(int a[]){
ArrEl m = new ArrEl(Integer.MIN_VALUE,Integer.MIN_VALUE);
for(int i=0; i<a.length; i++)
if(a[i]>m.v){m.v=a[i];m.i=i;}
return m;
}
@SuppressWarnings("static-access")
public static ArrEl getMin(int a[]){
ArrEl m = new ArrEl(Integer.MAX_VALUE,Integer.MAX_VALUE);
for(int i=0; i<a.length; i++)
if(a[i]<m.v){m.v=a[i];m.i=i;}
return m;
}
}
}
public static void main(String[] args) throws IOException {
new Main().run();
}
StreamTokenizer in; PrintWriter out; boolean oj; BufferedReader br;
void init() throws IOException {
oj = System.getProperty("ONLINE_JUDGE") != null;
Reader reader = oj ? new InputStreamReader(System.in) : new FileReader("input.txt");
Writer writer = oj ? new OutputStreamWriter(System.out) : new FileWriter("output.txt");
br = new BufferedReader(reader);
in = new StreamTokenizer(br);
out = new PrintWriter(writer);
}
void run() throws IOException {
long beginTime = System.currentTimeMillis();
init();
solve();
if(!oj){
long endTime = System.currentTimeMillis();
if (!oj) {
System.out.println("Memory used = " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));
System.out.println("Running time = " + (endTime - beginTime));
}
}
out.flush();
}
void solve() throws IOException{
int n = nextInt(), m=nextInt(), a[] = new int[n], k=0, r=0;
for(int i=0; i<n; i++)if((a[k++]=nextInt())<0)/*a[k] = nextInt()*/;else k--;
Arrays.sort(a);
for(int i=0; (i<k)&(i<m); i++)r-=a[i];
out.println(r);
}
int nextInt() throws IOException {
in.nextToken();
return (int) in.nval;
}
long nextLong() throws IOException {
in.nextToken();
return (long) in.nval;
}
String nextString() throws IOException {
in.nextToken();
return in.sval;
}
double nextDouble() throws IOException {
in.nextToken();
return in.nval;
}
} | Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 6 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | af22bad6b6287ca5061c3ec89427fc9a | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
int N = in.nextInt();
int M = in.nextInt();
int[] tv = new int[N];
for (int i = 0; i < N; ++i)
tv[i] = in.nextInt();
Arrays.sort(tv);
int sum = 0;
for (int i = 0; i < M; ++i)
if (tv[i] < 0)
sum += -tv[i];
System.out.println(sum);
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String next() {
try {
while (tokenizer == null || !tokenizer.hasMoreTokens())
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
return tokenizer.nextToken();
}
public String nextLine() {
String line = null;
try {
tokenizer = null;
line = reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
return line;
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
}
| Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 6 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | 0f965d27dc6f91b0c577bbdbd2457165 | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = in.nextInt();
Arrays.sort(a);
int sum = 0;
for (int i = 0; i < k; i++)
if (a[i] >= 0)
break;
else
sum += a[i];
System.out.println(-sum);
}
} | Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 6 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | 5fb1ca9682f01b406bdf031c680048dc | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes |
import java.util.*;
public class main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String[] s = in.nextLine().split(" ");
int n = Integer.valueOf(s[0]);
int m = Integer.valueOf(s[1]);
String[] str = in.nextLine().split(" ");
int[] mas = new int[str.length];
for (int i = 0; i < mas.length; ++i) {
mas[i] = Integer.valueOf(str[i]);
}
int[] Norm = new int[mas.length];
int index = 0;
for (int i = 0; i < mas.length; ++i) {
if (mas[i] < 0) {
Norm[index++] = mas[i];
}
}
bubblesort(Norm);
int sum = 0;
try {
for (int i = 0; i < m; ++i) {
sum += Norm[i];
}
} catch (Exception e) {
}
System.out.println(-sum);
}
public static void swap(int[] arr, int i, int j) {
int t = arr[i];
arr[i] = arr[j];
arr[j] = t;
}
public static void bubblesort(int[] arr) {
for (int i = arr.length - 1; i >= 0; i--) {
for (int j = 0; j < i; j++) {
if (arr[j] > arr[j + 1]) {
swap(arr, j, j + 1);
}
}
}
}
}
| Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 6 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | 6da4bdf3ff912782f12067f3df9f5fb3 | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes | import java.util.Scanner;
import java.util.Arrays;
public class Main {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt()-1;
int sum = 0,x = 0;
int[] f = new int[n];
for (int i=0;i<n;i++) {
f[i] = in.nextInt();
}
Arrays.sort(f);
while (m>=0) {
if (f[m]<0) {
sum-= f[m];
}
m--;
}
System.out.println(sum);
}
} | Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 6 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | 48447629f700e64dd679eba4ad45a540 | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes |
import java.util.Arrays;
import java.util.Scanner;
public class Sale {
public static void main(String [] args){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
int [] a = new int[n];
for (int i =0; i < n; i++)
a[i] = in.nextInt();
Arrays.sort(a);
int sum = 0;
for (int i = 0; i < m; i++)
if(a[i]<0) sum-=a[i];
System.out.println(sum);
}
}
| Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 6 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | 91a055ab2401bf218376f548f5706608 | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
/**
* Sale
*
* Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV
* set with index i costs ai bellars. Some TV sets have a negative price — their
* owners are ready to pay Bob if he buys their useless apparatus. Bob can buy
* any TV sets he wants. Though he's very strong, Bob can carry at most m TV
* sets, and he has no desire to go to the sale for the second time. Please,
* help Bob find out the maximum sum of money that he can earn.
*
* Input
* The first line contains two space-separated integers n and m (1 <= m <= n <=
* 100) — amount of TV sets at the sale, and amount of TV sets that Bob can
* carry. The following line contains n space-separated integers ai (-1000 <=
* ai <= 1000) — prices of the TV sets.
*
* Output
* Output the only number — the maximum sum of money that Bob can earn, given
* that he can carry at most m TV sets.
*
* Sample test(s)
* Input
* 5 3
* -6 0 35 -2 4
* Output
* 8
*
* Input
* 4 2
* 7 0 0 -7
* Output
* 7
*
* @author Europa
*/
public class Sale {
private static int earn(int M, int[] price) {
Arrays.sort(price);
int earn = 0;
for (int i = 0; i < M && price[i] < 0; i++) {
earn += price[i];
}
return -earn;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int M = scanner.nextInt();
int[] price = new int[N];
for (int i = 0; i < N; i++) {
price[i] = scanner.nextInt();
}
System.out.println(Sale.earn(M, price));
}
}
| Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 6 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | c96ec3cb04f564bb8ebb8f3341524a04 | train_003.jsonl | 1286802000 | Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Sale implements Runnable
{
private void solve() throws Exception
{
int n = nextInt();
int m = nextInt();
int[] tv = new int[n];
for(int i = 0; i < n; ++i)
tv[i] = nextInt();
Arrays.sort(tv);
int res = 0;
for(int i = 0; i < m; ++i)
if(tv[i] < 0)
res += Math.abs(tv[i]);
else
break;
writer.println(res);
}
BufferedReader reader;
StringTokenizer tokenizer;
PrintWriter writer;
public static void main(String[] args)
{
new Sale().run();
}
public void run()
{
try
{
reader = new BufferedReader(new InputStreamReader(System.in));
//reader = new BufferedReader(new FileReader("template.in"));
tokenizer = null;
writer = new PrintWriter(System.out);
//writer = new PrintWriter("template.out");
solve();
reader.close();
writer.close();
}
catch (Exception ex)
{
ex.printStackTrace();
System.exit(1);
}
}
private int nextInt() throws IOException
{
return Integer.parseInt(nextToken());
}
private long nextLong() throws IOException
{
return Long.parseLong(nextToken());
}
private double nextDouble() throws IOException
{
return Double.parseDouble(nextToken());
}
private String nextToken() throws IOException
{
while(tokenizer == null || !tokenizer.hasMoreTokens())
tokenizer = new StringTokenizer(reader.readLine());
return tokenizer.nextToken();
}
}
| Java | ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"] | 2 seconds | ["8", "7"] | null | Java 6 | standard input | [
"sortings",
"greedy"
] | 9a56288d8bd4e4e7ef3329e102f745a5 | The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets. | 900 | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets. | standard output | |
PASSED | e4156baa885debd5bfaa07868f049d13 | train_003.jsonl | 1366644600 | Ksusha the Squirrel is standing at the beginning of a straight road, divided into n sectors. The sectors are numbered 1 to n, from left to right. Initially, Ksusha stands in sector 1. Ksusha wants to walk to the end of the road, that is, get to sector n. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks.Ksusha the squirrel keeps fit. She can jump from sector i to any of the sectors i + 1, i + 2, ..., i + k. Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)? | 256 megabytes | import java.util.Scanner;
public class kts {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
String s = in.next();
in.close();
char[] input = s.toCharArray();
int c = 0;
int j = k, temp = 0;
while (c < n - 1) {
j = k;
temp = c;
while (j > 0) {
if (c + j < n && input[c + j] == '.') {
c = c + j;
break;
}
c--;
}
if (c == temp)
break;
}
if (c == n - 1)
System.out.println("YES");
else
System.out.println("NO");
}
} | Java | ["2 1\n..", "5 2\n.#.#.", "7 3\n.#.###."] | 1 second | ["YES", "YES", "NO"] | null | Java 11 | standard input | [
"implementation",
"brute force"
] | d504d894b2f6a830c4d3b4edc54395be | The first line contains two integers n and k (2 ≤ n ≤ 3·105, 1 ≤ k ≤ 3·105). The next line contains n characters — the description of the road: the i-th character equals ".", if the i-th sector contains no rocks. Otherwise, it equals "#". It is guaranteed that the first and the last characters equal ".". | 900 | Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes). | standard output | |
PASSED | 4c9df6186cae97f14947d5e8d5ed5d27 | train_003.jsonl | 1366644600 | Ksusha the Squirrel is standing at the beginning of a straight road, divided into n sectors. The sectors are numbered 1 to n, from left to right. Initially, Ksusha stands in sector 1. Ksusha wants to walk to the end of the road, that is, get to sector n. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks.Ksusha the squirrel keeps fit. She can jump from sector i to any of the sectors i + 1, i + 2, ..., i + k. Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)? | 256 megabytes | // Working program with FastReader
import java.io.*;
import java.util.*;
public class codeforces_299B
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args)
{
FastReader ob=new FastReader();
int n=ob.nextInt(),k=ob.nextInt();
String s=ob.next();
int max=0;
int count=0;
for (int i = 0; i <n ; i++) {
if(s.charAt(i)=='#'){
count++;
}
else {
max=Math.max(count,max);
count=0;
}
}
max=Math.max(count,max);
if(max>=k){
System.out.println("NO");
return;
}
System.out.println("YES");
}
}
| Java | ["2 1\n..", "5 2\n.#.#.", "7 3\n.#.###."] | 1 second | ["YES", "YES", "NO"] | null | Java 11 | standard input | [
"implementation",
"brute force"
] | d504d894b2f6a830c4d3b4edc54395be | The first line contains two integers n and k (2 ≤ n ≤ 3·105, 1 ≤ k ≤ 3·105). The next line contains n characters — the description of the road: the i-th character equals ".", if the i-th sector contains no rocks. Otherwise, it equals "#". It is guaranteed that the first and the last characters equal ".". | 900 | Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes). | standard output | |
PASSED | be7d57c42fbc97c29abc7846a8a84ef2 | train_003.jsonl | 1366644600 | Ksusha the Squirrel is standing at the beginning of a straight road, divided into n sectors. The sectors are numbered 1 to n, from left to right. Initially, Ksusha stands in sector 1. Ksusha wants to walk to the end of the road, that is, get to sector n. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks.Ksusha the squirrel keeps fit. She can jump from sector i to any of the sectors i + 1, i + 2, ..., i + k. Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)? | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.InputStreamReader;
import java.io.BufferedOutputStream;
import java.util.StringTokenizer;
import java.io.Closeable;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.Flushable;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
static class TaskAdapter implements Runnable {
@Override
public void run() {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Input in = new Input(inputStream);
Output out = new Output(outputStream);
BKsushaTheSquirrel solver = new BKsushaTheSquirrel();
solver.solve(1, in, out);
out.close();
}
}
public static void main(String[] args) throws Exception {
Thread thread = new Thread(null, new TaskAdapter(), "", 1<<29);
thread.start();
thread.join();
}
static class BKsushaTheSquirrel {
public BKsushaTheSquirrel() {
}
public void solve(int kase, Input in, Output pw) {
int n = in.nextInt(), k = in.nextInt();
String s = in.next();
int prev = 0;
for(int i = 0; i<n; i++) {
boolean b = s.charAt(i)=='#';
if(b&&i-prev>=k) {
pw.println("NO");
return;
}else if(!b) {
prev = i;
}
}
pw.println("YES");
}
}
static class Input {
BufferedReader br;
StringTokenizer st;
public Input(InputStream is) {
this(is, 1<<20);
}
public Input(InputStream is, int bs) {
br = new BufferedReader(new InputStreamReader(is), bs);
st = null;
}
public boolean hasNext() {
try {
while(st==null||!st.hasMoreTokens()) {
String s = br.readLine();
if(s==null) {
return false;
}
st = new StringTokenizer(s);
}
return true;
}catch(Exception e) {
return false;
}
}
public String next() {
if(!hasNext()) {
throw new InputMismatchException();
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
static class Output implements Closeable, Flushable {
public StringBuilder sb;
public OutputStream os;
public int BUFFER_SIZE;
public boolean autoFlush;
public String LineSeparator;
public Output(OutputStream os) {
this(os, 1<<16);
}
public Output(OutputStream os, int bs) {
BUFFER_SIZE = bs;
sb = new StringBuilder(BUFFER_SIZE);
this.os = new BufferedOutputStream(os, 1<<17);
autoFlush = false;
LineSeparator = System.lineSeparator();
}
public void println(String s) {
sb.append(s);
println();
if(autoFlush) {
flush();
}else if(sb.length()>BUFFER_SIZE >> 1) {
flushToBuffer();
}
}
public void println() {
sb.append(LineSeparator);
}
private void flushToBuffer() {
try {
os.write(sb.toString().getBytes());
}catch(IOException e) {
e.printStackTrace();
}
sb = new StringBuilder(BUFFER_SIZE);
}
public void flush() {
try {
flushToBuffer();
os.flush();
}catch(IOException e) {
e.printStackTrace();
}
}
public void close() {
flush();
try {
os.close();
}catch(IOException e) {
e.printStackTrace();
}
}
}
}
| Java | ["2 1\n..", "5 2\n.#.#.", "7 3\n.#.###."] | 1 second | ["YES", "YES", "NO"] | null | Java 11 | standard input | [
"implementation",
"brute force"
] | d504d894b2f6a830c4d3b4edc54395be | The first line contains two integers n and k (2 ≤ n ≤ 3·105, 1 ≤ k ≤ 3·105). The next line contains n characters — the description of the road: the i-th character equals ".", if the i-th sector contains no rocks. Otherwise, it equals "#". It is guaranteed that the first and the last characters equal ".". | 900 | Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes). | standard output | |
PASSED | 8380e03757d7507a651942182b70c49c | train_003.jsonl | 1366644600 | Ksusha the Squirrel is standing at the beginning of a straight road, divided into n sectors. The sectors are numbered 1 to n, from left to right. Initially, Ksusha stands in sector 1. Ksusha wants to walk to the end of the road, that is, get to sector n. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks.Ksusha the squirrel keeps fit. She can jump from sector i to any of the sectors i + 1, i + 2, ..., i + k. Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)? | 256 megabytes | import java.util.*;
import java.math.*;
import java.io.*;
import java.text.*;
public class practice {
public static void merge(int arr[], int l, int m, int r) {
int n1 = m - l + 1;
int n2 = r - m;
int L[] = new int[n1];
int R[] = new int[n2];
for (int i = 0; i < n1; ++i)
L[i] = arr[l + i];
for (int j = 0; j < n2; ++j)
R[j] = arr[m + 1 + j];
int i = 0, j = 0;
int k = l;
while (i < n1 && j < n2) {
if (L[i] <= R[j]) {
arr[k] = L[i];
i++;
} else {
arr[k] = R[j];
j++;
}
k++;
}
while (i < n1) {
arr[k] = L[i];
i++;
k++;
}
while (j < n2) {
arr[k] = R[j];
j++;
k++;
}
}
public static void sort(int arr[], int l, int r) {
if (l < r) {
int m = (l + r) / 2;
sort(arr, l, m);
sort(arr, m + 1, r);
merge(arr, l, m, r);
}
}
public static long gcd(long a, long b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
public static long lcm(long a, long b) {
long product = a * b;
long gcd = gcd(a, b);
long lcm = product / gcd;
return (lcm);
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
String s = br.readLine();
int min = 0;
int count = 0;
for(int i=0;i<n;i++){
if(s.charAt(i) == '#'){
count++;
}
else{
min = Math.max(min,count);
count = 0;
}
}
if(min>=k){
System.out.println("NO");
}
else{
System.out.println("YES");
}
}
} | Java | ["2 1\n..", "5 2\n.#.#.", "7 3\n.#.###."] | 1 second | ["YES", "YES", "NO"] | null | Java 11 | standard input | [
"implementation",
"brute force"
] | d504d894b2f6a830c4d3b4edc54395be | The first line contains two integers n and k (2 ≤ n ≤ 3·105, 1 ≤ k ≤ 3·105). The next line contains n characters — the description of the road: the i-th character equals ".", if the i-th sector contains no rocks. Otherwise, it equals "#". It is guaranteed that the first and the last characters equal ".". | 900 | Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes). | standard output | |
PASSED | 72af603d96878ceb249760f0e0ce32b9 | train_003.jsonl | 1366644600 | Ksusha the Squirrel is standing at the beginning of a straight road, divided into n sectors. The sectors are numbered 1 to n, from left to right. Initially, Ksusha stands in sector 1. Ksusha wants to walk to the end of the road, that is, get to sector n. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks.Ksusha the squirrel keeps fit. She can jump from sector i to any of the sectors i + 1, i + 2, ..., i + k. Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)? | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class B299_KsushaTheSquirrel {
public static void main(String[] args) {
PrintWriter pw = new PrintWriter(System.out);
int n = nextInt();
int k = nextInt();
String line = nextLine();
int p = 0;
boolean flag = false;
for (int i = 0; i < n; i++) {
if (p == k) {
flag = true;
break;
}
if (line.charAt(i) == '#') p++;
else p = 0;
}
pw.println(flag ? "NO" : "YES");
pw.close();
}
private static final long MOD = (long) (Math.pow(10, 9) + 7);
private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private static StringTokenizer st;
private static String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
private static String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
private static int nextInt() {
return Integer.parseInt(next());
}
private static long nextLong() {
return Long.parseLong(next());
}
private static double nextDouble() {
return Double.parseDouble(next());
}
} | Java | ["2 1\n..", "5 2\n.#.#.", "7 3\n.#.###."] | 1 second | ["YES", "YES", "NO"] | null | Java 11 | standard input | [
"implementation",
"brute force"
] | d504d894b2f6a830c4d3b4edc54395be | The first line contains two integers n and k (2 ≤ n ≤ 3·105, 1 ≤ k ≤ 3·105). The next line contains n characters — the description of the road: the i-th character equals ".", if the i-th sector contains no rocks. Otherwise, it equals "#". It is guaranteed that the first and the last characters equal ".". | 900 | Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes). | standard output | |
PASSED | 5b71b91d144fde19fe5f26ae4dd02a24 | train_003.jsonl | 1366644600 | Ksusha the Squirrel is standing at the beginning of a straight road, divided into n sectors. The sectors are numbered 1 to n, from left to right. Initially, Ksusha stands in sector 1. Ksusha wants to walk to the end of the road, that is, get to sector n. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks.Ksusha the squirrel keeps fit. She can jump from sector i to any of the sectors i + 1, i + 2, ..., i + k. Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)? | 256 megabytes | import java.util.Scanner;
public class ksushaTheSquirrel
{
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
int k=scan.nextInt();
char[] road=new char[n];
road=scan.next().toCharArray();
if(isItPossible(road,k))
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}
scan.close();
}
static boolean isItPossible(char[] road,int k)
{
if(k==0)
{
return false;
}
int flag=0;
for(int i=0;i<road.length;)
{
if((i+k)>=road.length-1)
{
flag=1;
break;
//return true;
}
if(road[i+k]=='.')
{
i=i+k;
}
else
{
int temp=k-1;
while(road[i+temp]!='.')
{
if(temp==0)
{
flag=0;
break;
//return false;
}
temp--;
}
if(road[i+temp]=='.'&&temp!=0)
{
i=i+temp;
}
else
{
flag=0;
break;
}
}
}
if(flag==0)
{
return false;
}
else
{
return true;
}
}
} | Java | ["2 1\n..", "5 2\n.#.#.", "7 3\n.#.###."] | 1 second | ["YES", "YES", "NO"] | null | Java 11 | standard input | [
"implementation",
"brute force"
] | d504d894b2f6a830c4d3b4edc54395be | The first line contains two integers n and k (2 ≤ n ≤ 3·105, 1 ≤ k ≤ 3·105). The next line contains n characters — the description of the road: the i-th character equals ".", if the i-th sector contains no rocks. Otherwise, it equals "#". It is guaranteed that the first and the last characters equal ".". | 900 | Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes). | standard output | |
PASSED | d5bd3544862e900cf5d3695340b3fd8a | train_003.jsonl | 1366644600 | Ksusha the Squirrel is standing at the beginning of a straight road, divided into n sectors. The sectors are numbered 1 to n, from left to right. Initially, Ksusha stands in sector 1. Ksusha wants to walk to the end of the road, that is, get to sector n. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks.Ksusha the squirrel keeps fit. She can jump from sector i to any of the sectors i + 1, i + 2, ..., i + k. Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)? | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int k=sc.nextInt();
String s=sc.next();
int a[]=new int[n];
boolean reach=true;
for(int i=0;i<n;i++){
if(s.charAt(i)=='#'){
int j=i,cnt=1;
while(j+1<n && s.charAt(j)==s.charAt(j+1)){
j++;cnt++;
}
if(cnt>=k)reach=false;
i=j;
}
}
if(reach)System.out.println("YES");
else System.out.println("NO");
}
}
| Java | ["2 1\n..", "5 2\n.#.#.", "7 3\n.#.###."] | 1 second | ["YES", "YES", "NO"] | null | Java 11 | standard input | [
"implementation",
"brute force"
] | d504d894b2f6a830c4d3b4edc54395be | The first line contains two integers n and k (2 ≤ n ≤ 3·105, 1 ≤ k ≤ 3·105). The next line contains n characters — the description of the road: the i-th character equals ".", if the i-th sector contains no rocks. Otherwise, it equals "#". It is guaranteed that the first and the last characters equal ".". | 900 | Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes). | standard output | |
PASSED | 28703df08ceb14f7610dbb614da6af34 | train_003.jsonl | 1366644600 | Ksusha the Squirrel is standing at the beginning of a straight road, divided into n sectors. The sectors are numbered 1 to n, from left to right. Initially, Ksusha stands in sector 1. Ksusha wants to walk to the end of the road, that is, get to sector n. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks.Ksusha the squirrel keeps fit. She can jump from sector i to any of the sectors i + 1, i + 2, ..., i + k. Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)? | 256 megabytes | import java.util.Scanner;
public class Squirrel_Mohamed {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int k = scanner.nextInt();
String road = scanner.next();
int current = 0;
int steps = 0;
while (steps < k) {
if (road.charAt(current) == '.') {
steps = 0;
} else {
steps++;
}
current++;
if(current == road.length()){
System.out.println("YES");
return;
}
}
System.out.println("NO");
}
} | Java | ["2 1\n..", "5 2\n.#.#.", "7 3\n.#.###."] | 1 second | ["YES", "YES", "NO"] | null | Java 11 | standard input | [
"implementation",
"brute force"
] | d504d894b2f6a830c4d3b4edc54395be | The first line contains two integers n and k (2 ≤ n ≤ 3·105, 1 ≤ k ≤ 3·105). The next line contains n characters — the description of the road: the i-th character equals ".", if the i-th sector contains no rocks. Otherwise, it equals "#". It is guaranteed that the first and the last characters equal ".". | 900 | Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes). | standard output | |
PASSED | 77cf3136a3830b7b4ba24611b431f2f1 | train_003.jsonl | 1366644600 | Ksusha the Squirrel is standing at the beginning of a straight road, divided into n sectors. The sectors are numbered 1 to n, from left to right. Initially, Ksusha stands in sector 1. Ksusha wants to walk to the end of the road, that is, get to sector n. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks.Ksusha the squirrel keeps fit. She can jump from sector i to any of the sectors i + 1, i + 2, ..., i + k. Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)? | 256 megabytes | import java.util.*;
public class Solve299b{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int k=sc.nextInt();
String s=sc.next();
int sum=0; int m=0;
for(int i=0;i<n;i++){
if(s.charAt(i)=='#'){
sum++;
}
else{
sum=0;
}
m=Math.max(sum,m);
}
if(m>=k){
System.out.println("NO");
}
else{
System.out.println("YES");
}
}
}
| Java | ["2 1\n..", "5 2\n.#.#.", "7 3\n.#.###."] | 1 second | ["YES", "YES", "NO"] | null | Java 11 | standard input | [
"implementation",
"brute force"
] | d504d894b2f6a830c4d3b4edc54395be | The first line contains two integers n and k (2 ≤ n ≤ 3·105, 1 ≤ k ≤ 3·105). The next line contains n characters — the description of the road: the i-th character equals ".", if the i-th sector contains no rocks. Otherwise, it equals "#". It is guaranteed that the first and the last characters equal ".". | 900 | Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes). | standard output | |
PASSED | 4a367474ab06bd4c61dde71c38cb2f25 | train_003.jsonl | 1366644600 | Ksusha the Squirrel is standing at the beginning of a straight road, divided into n sectors. The sectors are numbered 1 to n, from left to right. Initially, Ksusha stands in sector 1. Ksusha wants to walk to the end of the road, that is, get to sector n. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks.Ksusha the squirrel keeps fit. She can jump from sector i to any of the sectors i + 1, i + 2, ..., i + k. Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)? | 256 megabytes | //problem: https://codeforces.com/problemset/problem/299/B
import java.util.Scanner;
public class SqrlJmp{
public static void main(String[] args){
Scanner sObj = new Scanner(System.in);
int sectors = sObj.nextInt();
int jmp = sObj.nextInt();
int maxBlock = 0;
sObj.nextLine();
for(char ch: sObj.nextLine().toCharArray()){
if(ch == '#'){
maxBlock++;
if(maxBlock >= jmp){
System.out.println("NO");
return;
}
}
else{
maxBlock=0;
}
}
System.out.println("YES");
}
} | Java | ["2 1\n..", "5 2\n.#.#.", "7 3\n.#.###."] | 1 second | ["YES", "YES", "NO"] | null | Java 11 | standard input | [
"implementation",
"brute force"
] | d504d894b2f6a830c4d3b4edc54395be | The first line contains two integers n and k (2 ≤ n ≤ 3·105, 1 ≤ k ≤ 3·105). The next line contains n characters — the description of the road: the i-th character equals ".", if the i-th sector contains no rocks. Otherwise, it equals "#". It is guaranteed that the first and the last characters equal ".". | 900 | Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes). | standard output | |
PASSED | 22108a484b63eec736adff8213297ba9 | train_003.jsonl | 1366644600 | Ksusha the Squirrel is standing at the beginning of a straight road, divided into n sectors. The sectors are numbered 1 to n, from left to right. Initially, Ksusha stands in sector 1. Ksusha wants to walk to the end of the road, that is, get to sector n. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks.Ksusha the squirrel keeps fit. She can jump from sector i to any of the sectors i + 1, i + 2, ..., i + k. Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)? | 256 megabytes | import java.util.Scanner;
public class main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
String roadDesc = in.next();
for(int i=1; i<300000; i++) {
for(int j=i; j<i+k; j++) {
if(roadDesc.charAt(j)!='#') {
i=j;
break;
}else if(j==i+k-1) {
System.out.println("NO");
System.exit(0);
}
}if(i>=n-1) {
System.out.println("YES");
System.exit(0);
}
}
in.close();
}
}
| Java | ["2 1\n..", "5 2\n.#.#.", "7 3\n.#.###."] | 1 second | ["YES", "YES", "NO"] | null | Java 11 | standard input | [
"implementation",
"brute force"
] | d504d894b2f6a830c4d3b4edc54395be | The first line contains two integers n and k (2 ≤ n ≤ 3·105, 1 ≤ k ≤ 3·105). The next line contains n characters — the description of the road: the i-th character equals ".", if the i-th sector contains no rocks. Otherwise, it equals "#". It is guaranteed that the first and the last characters equal ".". | 900 | Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes). | standard output | |
PASSED | dab846a2cdb11b58689b2dbeadbc1bc2 | train_003.jsonl | 1398169140 | Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not. | 256 megabytes | //package main;
import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class Main {
FastScanner scan;
PrintWriter out;
BufferedReader in;
boolean isPal(String s)
{
int l = 0;
int r = s.length()-1;
while(l<=r)
{
if(s.charAt(l)!=s.charAt(r))
{
return false;
}
l++;
r--;
}
return true;
}
boolean contains(String s)
{
String word ="AIHMOTUVWXY";
int counter =0;
for (int j=0; j<s.length(); j++) {
for (int i=0; i<word.length(); i++)
{
if(s.charAt(j)==word.charAt(i))
{
counter++;
}
}
}
if(counter==s.length())
{
return true;
}
else
return false;
}
public void solve() throws Exception {
String s = scan.next();
if(!contains(s))
{
out.println("NO");
}
else if(isPal(s) && contains(s))
{
out.println("YES");
}
else
{
out.println("NO");
}
}
static Throwable uncaught;
public void run() {
try {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
scan = new FastScanner(in);
solve();
} catch (Throwable uncaught) {
Main.uncaught = uncaught;
}
finally
{
out.close();
}
}
class FastScanner {
BufferedReader in;
StringTokenizer st;
FastScanner(BufferedReader in) {
this.in = in;
}
String next() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(in.readLine());
}
return st.nextToken();
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public double nextDouble() throws Exception {
return Double.parseDouble(next());
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
BigInteger nextBig() throws IOException
{
return new BigInteger(next());
}
}
public static void main(String[] arg) {
new Main().run();
}
} | Java | ["AHA", "Z", "XO"] | 1 second | ["YES", "NO", "NO"] | null | Java 7 | standard input | [
"implementation"
] | 8135173b23c6b48df11b1d2609b08080 | The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font: | 1,000 | Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes). | standard output | |
PASSED | c79ac8a3b740ea93320875a02758495a | train_003.jsonl | 1398169140 | Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
public class StartUp {
private static final int[] REFLECTION = new int[] { 0, 7, 8, 12, 14, 19,
20, 21, 22, 23, 24 };
public static void main(String[] args) {
InputStream inputStream = System.in;
InputReader reader = new InputReader(inputStream);
int[] label = new int[26];
for (int i = 0; i < REFLECTION.length; i++) {
label[REFLECTION[i]] = 1;
}
char[] letters = reader.next().toCharArray();
int first = 0;
int last = letters.length - 1;
while (last >= 0) {
if (letters[last] == letters[first]
&& label[-65 + (int) letters[last]] == 1) {
last--;
first++;
} else {
System.out.println("NO");
return;
}
}
System.out.println("YES");
}
private static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
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());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
}
| Java | ["AHA", "Z", "XO"] | 1 second | ["YES", "NO", "NO"] | null | Java 7 | standard input | [
"implementation"
] | 8135173b23c6b48df11b1d2609b08080 | The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font: | 1,000 | Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes). | standard output | |
PASSED | 55da1b0dcc0a3afe63a20f4ace95399d | train_003.jsonl | 1398169140 | Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class B {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
final char[] e = {'A', 'H', 'I', 'M', 'O', 'T', 'U', 'V', 'W', 'X', 'Y'};
char[] s = in.nextLine().toCharArray();
int n = s.length;
int h = n / 2;
for (int i = 0; i <= h; i++) {
int d = Arrays.binarySearch(e, s[i]);
if (d < 0 || s[i] != s[n - i - 1]) {
System.out.println("NO");
return;
}
}
System.out.println("YES");
}
}
| Java | ["AHA", "Z", "XO"] | 1 second | ["YES", "NO", "NO"] | null | Java 7 | standard input | [
"implementation"
] | 8135173b23c6b48df11b1d2609b08080 | The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font: | 1,000 | Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes). | standard output | |
PASSED | bfad119dc930e990e7e2ce83416126f5 | train_003.jsonl | 1398169140 | Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not. | 256 megabytes |
import java.awt.Point;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
public class A {
private static BufferedReader in;
private static StringTokenizer st;
private static PrintWriter out;
public static void main(String[] args) throws NumberFormatException,
IOException {
in = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer("");
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
System.out)));
String s= next();
StringBuffer p = new StringBuffer(s);
String d="AHIMOTUYVWX"; boolean f = false;
if(p.reverse().toString().endsWith(s)){
for (int i = 0; i < s.length(); i++) {
if(!d.contains(s.charAt(i)+""))
f=true;
}
if(f)
System.out.println("NO");
else
System.out.println("YES");
}else
System.out.println("NO");
out.close();
}
static String next() throws IOException {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(in.readLine());
}
return st.nextToken();
}
static int nextInt() throws NumberFormatException, IOException {
return Integer.parseInt(next());
}
static long nextLong() throws NumberFormatException, IOException {
return Long.parseLong(next());
}
static double nextDouble() throws NumberFormatException, IOException {
return Double.parseDouble(next());
}
} | Java | ["AHA", "Z", "XO"] | 1 second | ["YES", "NO", "NO"] | null | Java 7 | standard input | [
"implementation"
] | 8135173b23c6b48df11b1d2609b08080 | The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font: | 1,000 | Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes). | standard output | |
PASSED | e895e81bf53a20a25dfa980de6981ecd | train_003.jsonl | 1398169140 | Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
public class B {
static StringTokenizer st;
static BufferedReader bf;
static PrintWriter out;
public static void main(String[] args) throws IOException, Exception {
begin();
solve();
end();
}
private static void end() {
out.close();
}
private static void solve() throws IOException, Exception {
char []a = next().toCharArray();
int len = a.length;
for (int i = 0; i < len/2; i++) {
if (a[i] != a[len-i-1]){
out.print("NO");
return;
}
}
String s = "YVMAWOXHITU";
Set<Character> set = new HashSet<>();
for (int i = 0; i < s.length(); i++) {
set.add(s.charAt(i));
}
for (int i = 0; i < a.length; i++) {
if (!set.contains(a[i])){
System.out.println("NO");
return;
}
}
out.print("YES");
}
static int nextInt() throws Exception, IOException{
return Integer.parseInt(next());
}
private static String next() throws IOException {
while (!st.hasMoreElements())
st = new StringTokenizer(bf.readLine());
return st.nextToken();
}
private static void begin() {
bf = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer("");
out = new PrintWriter(new OutputStreamWriter(System.out));
}
}
| Java | ["AHA", "Z", "XO"] | 1 second | ["YES", "NO", "NO"] | null | Java 7 | standard input | [
"implementation"
] | 8135173b23c6b48df11b1d2609b08080 | The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font: | 1,000 | Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes). | standard output | |
PASSED | 209f5a28ce83c0d84fc62da5388fcc29 | train_003.jsonl | 1398169140 | Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not. | 256 megabytes | import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;
public class Main {
static boolean LOCAL = System.getSecurityManager() == null;
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
void run() {
while (in.hasNext())
solve();
}
private void solve() {
Set<Character> mir = new HashSet<Character>();
mir.add('A'); mir.add('H'); mir.add('I'); mir.add('M');
mir.add('O'); mir.add('T'); mir.add('U'); mir.add('V');
mir.add('W'); mir.add('X'); mir.add('Y');
char[] cs = in.next().toCharArray();
for (char c : cs) {
if (!mir.contains(c)) {
out.println("NO");
return ;
}
}
int n = cs.length;
for (int i = 0; i < n; i++) {
if (cs[i] != cs[n - i - 1]) {
out.println("NO");
return ;
}
}
out.println("YES");
}
void debug(Object... os) {
System.err.println(deepToString(os));
}
public static void main(String[] args) {
long start = System.nanoTime();
if (LOCAL) {
try {
System.setIn(new FileInputStream("./../in"));
// System.setOut(new PrintStream("./../in"));
} catch (IOException e) {
LOCAL = false;
}
}
Main main = new Main();
main.run();
main.out.close();
if (LOCAL)
System.err.printf("[Time %.6fs]%n",
(System.nanoTime() - start) * 1e-9);
}
}
class Scanner {
BufferedReader br;
StringTokenizer st;
Scanner(InputStream in) {
br = new BufferedReader(new InputStreamReader(in));
eat("");
}
private void eat(String string) {
st = new StringTokenizer(string);
}
String nextLine() {
try {
return br.readLine();
} catch (IOException e) {
return null;
}
}
boolean hasNext() {
while (!st.hasMoreTokens()) {
String s = nextLine();
if (s == null)
return false;
eat(s);
}
return true;
}
String next() {
hasNext();
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
} | Java | ["AHA", "Z", "XO"] | 1 second | ["YES", "NO", "NO"] | null | Java 7 | standard input | [
"implementation"
] | 8135173b23c6b48df11b1d2609b08080 | The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font: | 1,000 | Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes). | standard output | |
PASSED | 8338959ed366ee61285ca8118617bff4 | train_003.jsonl | 1398169140 | Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not. | 256 megabytes | import java.util.Scanner;
public class StartUp {
private static Scanner readers = new Scanner(System.in);
public static void main(String[] args) {
int[] words = new int[] { 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1,
0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0 };
;
String input;
input = readers.nextLine();
if (input.length() == 1)
{
int index = (int) (input.charAt(0) - 'A');
if (words[index] == 0)
System.out.print("NO");
else System.out.print("YES");
}
else {
int i = 0, j = input.length() - 1;
boolean isFalse = false;
while (i <= j) {
if (input.charAt(i) != input.charAt(j)) {
System.out.print("NO");
break;
} else {
int index = (int) (input.charAt(i) - 'A');
if (words[index] == 0) {
System.out.print("NO");
break;
}
}
i++;
j--;
}
if (i > j)
System.out.print("YES");
}
}
}
| Java | ["AHA", "Z", "XO"] | 1 second | ["YES", "NO", "NO"] | null | Java 7 | standard input | [
"implementation"
] | 8135173b23c6b48df11b1d2609b08080 | The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font: | 1,000 | Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes). | standard output | |
PASSED | 119f3f395a66c06692abe84c2362355c | train_003.jsonl | 1398169140 | Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not. | 256 megabytes | import java.util.*;
public class StartUp {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
String strInput= input.nextLine();
char[] a=strInput.toCharArray();
int n=a.length;
int []check={1,0,0,0,0,0,0,1,1,0,0,0,1,0,1,0,0,0,0,1,1,1,1,1,1,0};
int i=0;
int j=n-1;
int tmp=0;
while(i<=j)
{
if(a[i]==a[j])
{
int index=(int)a[i]-(int)'A';
if(check[index]==0)
{
tmp=1;
i=n;
System.out.println("NO");
}
}
else
{
tmp=1;
i=n;
System.out.println("NO");
}
i++;
j--;
}
if(tmp==0)
System.out.println("YES");
}
}
| Java | ["AHA", "Z", "XO"] | 1 second | ["YES", "NO", "NO"] | null | Java 7 | standard input | [
"implementation"
] | 8135173b23c6b48df11b1d2609b08080 | The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font: | 1,000 | Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes). | standard output | |
PASSED | e7302ac7ec6a8ab7014bfac24aec4739 | train_003.jsonl | 1398169140 | Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Mirror {
public static void main(String ...args) throws IOException {
BufferedReader in = new BufferedReader( new InputStreamReader(System.in));
String input = in.readLine();
if(input.contains("B") ||input.contains("C") || input.contains("D") || input.contains("E") || input.contains("F") || input.contains("G") ||
input.contains("J") || input.contains("K") || input.contains("L") || input.contains("N") || input.contains("P") || input.contains("Q") || input.contains("R") || input.contains("S") ||
input.contains("Z")){
System.out.println("NO");
}else{
for(int i = 0; i<input.length();i++){
if(input.charAt(i)!=input.charAt(input.length()-i-1)){
System.out.println("NO");
break;
}
if(i==input.length()-1){
System.out.println("YES");
}
}
}
}
}
| Java | ["AHA", "Z", "XO"] | 1 second | ["YES", "NO", "NO"] | null | Java 7 | standard input | [
"implementation"
] | 8135173b23c6b48df11b1d2609b08080 | The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font: | 1,000 | Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes). | standard output | |
PASSED | 4473f080b34f8a566680d463377ec87c | train_003.jsonl | 1398169140 | Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not. | 256 megabytes |
import java.util.Scanner;
public class B {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String input = sc.next();
char[] inputs = input.toCharArray();
if (!check(inputs)) {
System.out.println("NO");
return;
} else {
if(ishuiwen(inputs)){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}
public static boolean ishuiwen(char[] str) {
for(int i = 0 ; i < str.length/2;i++){
if(str[i]!=str[str.length-1-i]) return false;
}
return true;
}
public static boolean check(char[] str) {
for (int i = 0; i < str.length; i++) {
if (!(str[i] == 'A' || str[i] == 'H' || str[i] == 'I'
|| str[i] == 'M' || str[i] == 'O' || str[i] == 'T'
|| str[i] == 'U' || str[i] == 'V' || str[i] == 'W'
|| str[i] == 'X' || str[i] == 'Y')) {
return false;
}
}
return true;
}
}
| Java | ["AHA", "Z", "XO"] | 1 second | ["YES", "NO", "NO"] | null | Java 7 | standard input | [
"implementation"
] | 8135173b23c6b48df11b1d2609b08080 | The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font: | 1,000 | Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes). | standard output | |
PASSED | ad4061d3444b5c324e78a9bbfbeccf32 | train_003.jsonl | 1398169140 | Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not. | 256 megabytes | import java.awt.Point;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import static java.lang.Math.*;
public class _Solution implements Runnable {
final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
BufferedReader in;
PrintWriter out;
StringTokenizer tok = new StringTokenizer("");
void init() throws FileNotFoundException{
if (ONLINE_JUDGE){
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}else{
in = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
}
}
String readString() throws IOException{
while(!tok.hasMoreTokens()){
try{
tok = new StringTokenizer(in.readLine());
}catch (Exception e){
return null;
}
}
return tok.nextToken();
}
int readInt() throws IOException{
return Integer.parseInt(readString());
}
long readLong() throws IOException{
return Long.parseLong(readString());
}
double readDouble() throws IOException{
return Double.parseDouble(readString());
}
public static void main(String[] args){
new Thread(null, new _Solution(), "", 256 * (1L << 20)).start();
}
long timeBegin, timeEnd;
void time(){
timeEnd = System.currentTimeMillis();
System.err.println("Time = " + (timeEnd - timeBegin));
}
public void run(){
try{
timeBegin = System.currentTimeMillis();
init();
solve();
out.close();
time();
}catch (Exception e){
e.printStackTrace(System.err);
System.exit(-1);
}
}
void solve() throws IOException{
String str = readString();
ArrayList<Character> al = new ArrayList();
al.add('A');
al.add('H');
al.add('I');
al.add('M');
al.add('O');
al.add('T');
al.add('U');
al.add('V');
al.add('W');
al.add('X');
al.add('Y');
boolean flg = true;
for(int i = 0; (i <= str.length()/2)&&(flg); i++){
if((str.charAt(i) != str.charAt(str.length()-i-1))||(!al.contains(str.charAt(i)))){
flg = false;
}
}
if(flg){
out.print("YES");
}
else{
out.print("NO");
}
}
}
| Java | ["AHA", "Z", "XO"] | 1 second | ["YES", "NO", "NO"] | null | Java 7 | standard input | [
"implementation"
] | 8135173b23c6b48df11b1d2609b08080 | The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font: | 1,000 | Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes). | standard output | |
PASSED | 60054e8fd2e31e6459ea5bb423501fc3 | train_003.jsonl | 1398169140 | Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not. | 256 megabytes | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
//spackage finalA;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
*
* @author tino chagua
*/
public class B {
public static void main(String[] args) throws IOException {
int[] letter = new int[26];
letter[0] = 1;
letter[7] = 1;
letter[8] = 1;
letter[12] = 1;
letter[14] = 1;
letter[19] = 1;
letter[20] = 1;
letter[21] = 1;
letter[22] = 1;
letter[23] = 1;
letter[24] = 1;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String cad = br.readLine();
StringBuffer rcad = new StringBuffer(cad);
String newcad = rcad.reverse().toString();
boolean key = false;
if (cad.compareTo(newcad)==0) {
char[] x = cad.toCharArray();
for (int i = 0; i < x.length; i++) {
if (letter[x[i] - 'A'] == 0) {
key = true;
break;
}
}
if (key) {
System.out.println("NO");
} else {
System.out.println("YES");
}
} else {
System.out.println("NO");
}
}
}
| Java | ["AHA", "Z", "XO"] | 1 second | ["YES", "NO", "NO"] | null | Java 7 | standard input | [
"implementation"
] | 8135173b23c6b48df11b1d2609b08080 | The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font: | 1,000 | Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes). | standard output | |
PASSED | 20443f87e09d8cb6e354601dd3c90838 | train_003.jsonl | 1559745300 | You are given an integer $$$n$$$ and an integer $$$k$$$.In one step you can do one of the following moves: decrease $$$n$$$ by $$$1$$$; divide $$$n$$$ by $$$k$$$ if $$$n$$$ is divisible by $$$k$$$. For example, if $$$n = 27$$$ and $$$k = 3$$$ you can do the following steps: $$$27 \rightarrow 26 \rightarrow 25 \rightarrow 24 \rightarrow 8 \rightarrow 7 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.You are asked to calculate the minimum number of steps to reach $$$0$$$ from $$$n$$$. | 256 megabytes | import java.util.*;
public class FromHeroToZero {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int T= s.nextInt();
for(int t=0;t<T;t++){
long n=s.nextLong();
long k=s.nextLong();
long count=0;
while(n>0){
count+=(n%k)+1;
// System.out.println(count);
n=n/k;
}
System.out.println(count-1);
}
}
} | Java | ["2\n59 3\n1000000000000000000 10"] | 1 second | ["8\n19"] | NoteSteps for the first test case are: $$$59 \rightarrow 58 \rightarrow 57 \rightarrow 19 \rightarrow 18 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.In the second test case you have to divide $$$n$$$ by $$$k$$$ $$$18$$$ times and then decrease $$$n$$$ by $$$1$$$. | Java 8 | standard input | [
"implementation",
"math"
] | 00b1e45e9395d23e850ce1a0751b8378 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The only line of each query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^{18}$$$, $$$2 \le k \le 10^{18}$$$). | 900 | For each query print the minimum number of steps to reach $$$0$$$ from $$$n$$$ in single line. | standard output | |
PASSED | 3f0c85dc8a46bc4e3bcb0c25ca8aae7a | train_003.jsonl | 1559745300 | You are given an integer $$$n$$$ and an integer $$$k$$$.In one step you can do one of the following moves: decrease $$$n$$$ by $$$1$$$; divide $$$n$$$ by $$$k$$$ if $$$n$$$ is divisible by $$$k$$$. For example, if $$$n = 27$$$ and $$$k = 3$$$ you can do the following steps: $$$27 \rightarrow 26 \rightarrow 25 \rightarrow 24 \rightarrow 8 \rightarrow 7 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.You are asked to calculate the minimum number of steps to reach $$$0$$$ from $$$n$$$. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
//@Manan Parmar
public class p11 implements Runnable {
public void run() {
InputReader sc = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
int t=sc.nextInt();
while(t--!=0)
{
long n=sc.nextLong();
long k=sc.nextLong();
long sum=0;
while(n!=0)
{
if(n%k==0)
{
n=n/k;
sum=sum+1;
}
else
{
long x=n%k;
sum=sum+x;
n=n-x;
/*double x1=Math.floor(n/k);
long x=(long)x1;
long y=x*k;
long y2=n-y;
sum=sum+y2;
n=n-y2;*/
}
}
out.println(sum);
}
out.close();
}
//========================================================================
static int count(String s, char c)
{
int res = 0;
for (int i=0; i<s.length(); i++)
{
// checking character in string
if (s.charAt(i) == c)
res++;
}
return res;
}
static String addZeros(String str, int n)
{
for (int i = 0; i < n; i++)
{
str = "0" + str;
}
return str;
}
// Function to return the XOR
// of the given strings
static String getXOR(String a, String b)
{
// Lengths of the given strings
int aLen = a.length();
int bLen = b.length();
// Make both the strings of equal lengths
// by inserting 0s in the beginning
if (aLen > bLen)
{
a = addZeros(b, aLen - bLen);
}
else if (bLen > aLen)
{
a = addZeros(a, bLen - aLen);
}
// Updated length
int len = Math.max(aLen, bLen);
// To store the resultant XOR
String res = "";
for (int i = 0; i < len; i++)
{
if (a.charAt(i) == b.charAt(i))
res += "0";
else
res += "1";
}
return res;
}
static class Pair
{
int a,b;
Pair(int aa,int bb)
{
a=aa;
b=bb;
}
}
static void sa(int a[],InputReader sc)
{
for(int i=0;i<a.length;i++)
{
a[i]=sc.nextInt();
}
Arrays.sort(a);
}
static class PairSort implements Comparator<Pair>
{
public int compare(Pair a,Pair b)
{
return b.b-a.b;
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars==-1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
}
catch (IOException e) {
throw new InputMismatchException();
}
if(numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
public int nextInt() {
int c = read();
while(isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if(c<'0'||c>'9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
public static void main(String args[]) throws Exception {
new Thread(null, new p11(),"Main",1<<27).start();
}
} | Java | ["2\n59 3\n1000000000000000000 10"] | 1 second | ["8\n19"] | NoteSteps for the first test case are: $$$59 \rightarrow 58 \rightarrow 57 \rightarrow 19 \rightarrow 18 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.In the second test case you have to divide $$$n$$$ by $$$k$$$ $$$18$$$ times and then decrease $$$n$$$ by $$$1$$$. | Java 8 | standard input | [
"implementation",
"math"
] | 00b1e45e9395d23e850ce1a0751b8378 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The only line of each query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^{18}$$$, $$$2 \le k \le 10^{18}$$$). | 900 | For each query print the minimum number of steps to reach $$$0$$$ from $$$n$$$ in single line. | standard output | |
PASSED | 36ef351e09504b2916cf27fff1a10982 | train_003.jsonl | 1559745300 | You are given an integer $$$n$$$ and an integer $$$k$$$.In one step you can do one of the following moves: decrease $$$n$$$ by $$$1$$$; divide $$$n$$$ by $$$k$$$ if $$$n$$$ is divisible by $$$k$$$. For example, if $$$n = 27$$$ and $$$k = 3$$$ you can do the following steps: $$$27 \rightarrow 26 \rightarrow 25 \rightarrow 24 \rightarrow 8 \rightarrow 7 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.You are asked to calculate the minimum number of steps to reach $$$0$$$ from $$$n$$$. | 256 megabytes | import java.util.Scanner;
public class Codeforce_A_FromHerotoZero {
private static final Scanner SCANNER = new Scanner(System.in);
public static void main(String args[]) {
int queries = SCANNER.nextInt();
for (int k = 0; k < queries; k++) {
long integer_input = SCANNER.nextLong();
long divisor = SCANNER.nextLong();
long step = 0;
long input = integer_input / divisor;
if(integer_input < divisor){
step = integer_input;
}
else{
step = Calculate(integer_input, divisor, step);
}
System.out.printf("%d\n",step);
}
SCANNER.close();
}
public static long Calculate(long integer_input, long divisor, long step) {
long remainder =(long) Math.floor(integer_input % divisor);
integer_input -= remainder;
step += remainder;
if (integer_input == 0) {
return step;
}
integer_input = (long) integer_input / divisor;
step += 1;
return Calculate(integer_input, divisor, step);
}
}
// do a thing once for all not to separate ; recursive faster than for at the cost of memory | Java | ["2\n59 3\n1000000000000000000 10"] | 1 second | ["8\n19"] | NoteSteps for the first test case are: $$$59 \rightarrow 58 \rightarrow 57 \rightarrow 19 \rightarrow 18 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.In the second test case you have to divide $$$n$$$ by $$$k$$$ $$$18$$$ times and then decrease $$$n$$$ by $$$1$$$. | Java 8 | standard input | [
"implementation",
"math"
] | 00b1e45e9395d23e850ce1a0751b8378 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The only line of each query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^{18}$$$, $$$2 \le k \le 10^{18}$$$). | 900 | For each query print the minimum number of steps to reach $$$0$$$ from $$$n$$$ in single line. | standard output | |
PASSED | 8f682d5627a1ed1e89382591d3e0ab97 | train_003.jsonl | 1559745300 | You are given an integer $$$n$$$ and an integer $$$k$$$.In one step you can do one of the following moves: decrease $$$n$$$ by $$$1$$$; divide $$$n$$$ by $$$k$$$ if $$$n$$$ is divisible by $$$k$$$. For example, if $$$n = 27$$$ and $$$k = 3$$$ you can do the following steps: $$$27 \rightarrow 26 \rightarrow 25 \rightarrow 24 \rightarrow 8 \rightarrow 7 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.You are asked to calculate the minimum number of steps to reach $$$0$$$ from $$$n$$$. | 256 megabytes |
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
StringBuffer st=new StringBuffer();
int q=Integer.parseInt(bf.readLine());
while(q-->0){
String aa[]=bf.readLine().split(" ");
long a=Long.parseLong(aa[0]);
long b=Long.parseLong(aa[1]);
long count=0;
if(b==1||a<b){st.append(a);}
else{
while(a>0){
if(a%b==0){a/=b;count++;}
else{count+=(a%b);a-=(a%b);}
}st.append(count);
}
if(q>0){st.append("\n");}
}
System.out.println(st);
}
}
| Java | ["2\n59 3\n1000000000000000000 10"] | 1 second | ["8\n19"] | NoteSteps for the first test case are: $$$59 \rightarrow 58 \rightarrow 57 \rightarrow 19 \rightarrow 18 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.In the second test case you have to divide $$$n$$$ by $$$k$$$ $$$18$$$ times and then decrease $$$n$$$ by $$$1$$$. | Java 8 | standard input | [
"implementation",
"math"
] | 00b1e45e9395d23e850ce1a0751b8378 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The only line of each query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^{18}$$$, $$$2 \le k \le 10^{18}$$$). | 900 | For each query print the minimum number of steps to reach $$$0$$$ from $$$n$$$ in single line. | standard output | |
PASSED | 79df70ec51650eb2d99a063584e0d9a8 | train_003.jsonl | 1559745300 | You are given an integer $$$n$$$ and an integer $$$k$$$.In one step you can do one of the following moves: decrease $$$n$$$ by $$$1$$$; divide $$$n$$$ by $$$k$$$ if $$$n$$$ is divisible by $$$k$$$. For example, if $$$n = 27$$$ and $$$k = 3$$$ you can do the following steps: $$$27 \rightarrow 26 \rightarrow 25 \rightarrow 24 \rightarrow 8 \rightarrow 7 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.You are asked to calculate the minimum number of steps to reach $$$0$$$ from $$$n$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class test2 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
for(int i=0;i<t;i++){
StringTokenizer st = new StringTokenizer(br.readLine());
Long n = Long.parseUnsignedLong(st.nextToken());
Long k = Long.parseUnsignedLong(st.nextToken());
long count=0;
while(n!=0){
if(n%k!=0){
count+=n%k;
n-=n%k;
}
while(n!=0 && n%k==0){
count++;
n=n/k;
}
}
System.out.println(count);
}
}
}
| Java | ["2\n59 3\n1000000000000000000 10"] | 1 second | ["8\n19"] | NoteSteps for the first test case are: $$$59 \rightarrow 58 \rightarrow 57 \rightarrow 19 \rightarrow 18 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.In the second test case you have to divide $$$n$$$ by $$$k$$$ $$$18$$$ times and then decrease $$$n$$$ by $$$1$$$. | Java 8 | standard input | [
"implementation",
"math"
] | 00b1e45e9395d23e850ce1a0751b8378 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The only line of each query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^{18}$$$, $$$2 \le k \le 10^{18}$$$). | 900 | For each query print the minimum number of steps to reach $$$0$$$ from $$$n$$$ in single line. | standard output | |
PASSED | 1ff5f009d2169d1cfc9b0f5e23145475 | train_003.jsonl | 1559745300 | You are given an integer $$$n$$$ and an integer $$$k$$$.In one step you can do one of the following moves: decrease $$$n$$$ by $$$1$$$; divide $$$n$$$ by $$$k$$$ if $$$n$$$ is divisible by $$$k$$$. For example, if $$$n = 27$$$ and $$$k = 3$$$ you can do the following steps: $$$27 \rightarrow 26 \rightarrow 25 \rightarrow 24 \rightarrow 8 \rightarrow 7 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.You are asked to calculate the minimum number of steps to reach $$$0$$$ from $$$n$$$. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for (int i = 0; i <t ; i++) {
long n=sc.nextLong();
long k=sc.nextLong();
long cnt=0;
while(n!=0){
if(n%k==0){
n/=k;
cnt++;
}
else{
cnt+=(n%k);
n-=(n%k);
}
}
System.out.println(cnt);
}
}
} | Java | ["2\n59 3\n1000000000000000000 10"] | 1 second | ["8\n19"] | NoteSteps for the first test case are: $$$59 \rightarrow 58 \rightarrow 57 \rightarrow 19 \rightarrow 18 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.In the second test case you have to divide $$$n$$$ by $$$k$$$ $$$18$$$ times and then decrease $$$n$$$ by $$$1$$$. | Java 8 | standard input | [
"implementation",
"math"
] | 00b1e45e9395d23e850ce1a0751b8378 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The only line of each query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^{18}$$$, $$$2 \le k \le 10^{18}$$$). | 900 | For each query print the minimum number of steps to reach $$$0$$$ from $$$n$$$ in single line. | standard output | |
PASSED | ca50a843038c5e1a18d92c08452b0e93 | train_003.jsonl | 1559745300 | You are given an integer $$$n$$$ and an integer $$$k$$$.In one step you can do one of the following moves: decrease $$$n$$$ by $$$1$$$; divide $$$n$$$ by $$$k$$$ if $$$n$$$ is divisible by $$$k$$$. For example, if $$$n = 27$$$ and $$$k = 3$$$ you can do the following steps: $$$27 \rightarrow 26 \rightarrow 25 \rightarrow 24 \rightarrow 8 \rightarrow 7 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.You are asked to calculate the minimum number of steps to reach $$$0$$$ from $$$n$$$. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
public class temp
{
static FastReader s;;
static class pair
{
int a,b;
pair(int x, int y)
{
a=x;
b=y;
}
}
public static void main(String[] args) throws IOException
{
s = new FastReader();
int t = s.ni();
while(t-->0)
{
long n=s.nl();
long k=s.nl();
long count = 0;
while (n > 0)
{
if (n < k)
{
count += n;
break;
}
if (n % k == 0)
{
count++;
n = n / k;
}
else
{
count += (n % k);
n = n - (n % k);
}
}
println(count);
}
}
/*
********if input in hashmap*********
for (int i = 0; i < n; i++)
{
int x = s.nextInt();
if (!hm.containsKey(x))
hm.put(x, 1);
else
hm.put(x, hm.get(x) + 1);
}
*/
/*
********if input in 2darray*********
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
arr[i][j] = s.nextInt();
}
}
*/
/*
*********GCD**********
private static int gcdThing(int a, int b)
{
return BigInteger.valueOf(a).gcd(BigInteger.valueOf(b)).intValue();
}
*/
/*
***********nCr**********
static int nCr(int n, int k)
{
int ans = 1;
if ( k > n - k )
k = n - k;
for (int i = 0; i < k; ++i)
{
ans *= (n - i);
ans /= (i + 1);
}
return res;
}
*/
/*
******Method to check if x is power of 2********
static boolean isPowerOfTwo (int x)
{
return x!=0 && ((x&(x-1)) == 0);
}
*/
/*
*******generate all primes*******
void sieveOfEratosthenes(int n)
{
// Create a boolean array "prime[0..n]" and initialize
// all entries it as true. A value in prime[i] will
// finally be false if i is Not a prime, else true.
boolean prime[] = new boolean[n+1];
for(int i=0;i<n;i++)
prime[i] = true;
for(int p = 2; p*p <=n; p++)
{
// If prime[p] is not changed, then it is a prime
if(prime[p] == true)
{
// Update all multiples of p
for(int i = p*2; i <= n; i += p)
prime[i] = false;
}
}
// Print all prime numbers
for(int i = 2; i <= n; i++)
{
if(prime[i] == true)
System.out.print(i + " ");
}
}
*/
/*
*********permutaion program********
static boolean shouldSwap(StringBuilder str, int start, int curr)
{
for (int i = start; i < curr; i++)
{
if (str.charAt(i) == str.charAt(curr))
{
return false;
}
}
return true;
}
static void findPermutations(StringBuilder str, int index, int n, HashSet<Integer> hs)
{
if (index >= n)
{
int number = Integer.parseInt(str.toString(), 2);
hs.add(number);
return;
}
for (int i = index; i < n; i++)
{
boolean check = shouldSwap(str, index, i);
if (check)
{
char temp = str.charAt(index);
str.setCharAt(index, str.charAt(i));
str.setCharAt(i, temp);
findPermutations(str, index + 1, n, hs);
temp = str.charAt(index);
str.setCharAt(index, str.charAt(i));
str.setCharAt(i, temp);
}
}
}
*/
/*
********** island program********
public static int findisland(int[][]a,int n,int m)
{
int count = 0;
int [][]visited = new int[n][m];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (visited[i][j] == 0 && a[i][j] == 1)
{
count++;
island(a, n, m, i, j, visited);
}
}
}
return count;
}
static void island(int [][]a, int n, int m,int i, int j, int[][] visited)
{
if (i >= 0 && i < n && j >= 0 && j < m && visited[i][j] == 0 && a[i][j] == 1)
{
visited[i][j] = 1;
for (int k = -1; k <= 1; k++)
{
for (int l = -1; l <= 1; l++)
{
if (i+k >= 0 && i+k < n && j+l >= 0 && j+l < m )
island(a, n, m, i+k, j+l, visited);
}
}
}
else
return;
}
*/
static void println(Object line)
{
System.out.println(line);
}
static void print(Object line)
{
System.out.print(line);
}
static Integer[] iarr(int n)
{
Integer arr[]=new Integer[n];
for(int i = 0; i < n;i++)
arr[i]=s.ni();
return arr;
}
static Long[] larr(int n)
{
Long arr[]=new Long[n];
for(int i = 0; i < n;i++)
arr[i]=s.nl();
return arr;
}
static Integer[][] i2arr(int n, int m)
{
Integer arr[][]=new Integer[n][m];
for(int i = 0; i < n;i++)
for(int j = 0; j < m;j++)
arr[i][j]=s.ni();
return arr;
}
static Long[][] l2arr(int n, int m)
{
Long arr[][]=new Long[n][m];
for(int i = 0; i < n;i++)
for(int j = 0; j < m;j++)
arr[i][j]=s.nl();
return arr;
}
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
{
break;
}
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int ni() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
{
c = read();
}
boolean neg = (c == '-');
if (neg)
{
c = read();
}
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
{
return -ret;
}
return ret;
}
public long nl() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
{
c = read();
}
boolean neg = (c == '-');
if (neg)
{
c = read();
}
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
{
return -ret;
}
return ret;
}
public double nd() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
{
c = read();
}
boolean neg = (c == '-');
if (neg)
{
c = read();
}
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
{
return -ret;
}
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
{
buffer[0] = -1;
}
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
{
fillBuffer();
}
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
{
return;
}
din.close();
}
}
/*recommended*/
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String file_name) throws IOException
{
br = new BufferedReader(new FileReader(file_name));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
} catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int ni()
{
return Integer.parseInt(next());
}
long nl()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
} catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}
| Java | ["2\n59 3\n1000000000000000000 10"] | 1 second | ["8\n19"] | NoteSteps for the first test case are: $$$59 \rightarrow 58 \rightarrow 57 \rightarrow 19 \rightarrow 18 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.In the second test case you have to divide $$$n$$$ by $$$k$$$ $$$18$$$ times and then decrease $$$n$$$ by $$$1$$$. | Java 8 | standard input | [
"implementation",
"math"
] | 00b1e45e9395d23e850ce1a0751b8378 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The only line of each query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^{18}$$$, $$$2 \le k \le 10^{18}$$$). | 900 | For each query print the minimum number of steps to reach $$$0$$$ from $$$n$$$ in single line. | standard output | |
PASSED | e5ed9b72d616eef65edf3d13d712f42b | train_003.jsonl | 1559745300 | You are given an integer $$$n$$$ and an integer $$$k$$$.In one step you can do one of the following moves: decrease $$$n$$$ by $$$1$$$; divide $$$n$$$ by $$$k$$$ if $$$n$$$ is divisible by $$$k$$$. For example, if $$$n = 27$$$ and $$$k = 3$$$ you can do the following steps: $$$27 \rightarrow 26 \rightarrow 25 \rightarrow 24 \rightarrow 8 \rightarrow 7 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.You are asked to calculate the minimum number of steps to reach $$$0$$$ from $$$n$$$. | 256 megabytes |
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
public class q28
{
public static void main (String[] args) throws java.lang.Exception
{
FastReader scan=new FastReader();
int t=scan.nextInt();
while(t-->0){
long n=scan.nextLong();
long k=scan.nextLong();
long count=0;
while(n>0){
while(n%k==0){
n=n/k;
count++;
}
count=count+n%k;
n=n-n%k;
}
System.out.println(count);
}
}
static class FastReader{
BufferedReader in;
StringTokenizer st;
public FastReader(){
in=new BufferedReader(new InputStreamReader(System.in));
}
String next(){
while(st==null || !st.hasMoreElements()){
try{
st=new StringTokenizer(in.readLine());
}
catch(IOException e){
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
String nextLine(){
String str19 = "";
try{
str19 = in.readLine();
}
catch (IOException e){
e.printStackTrace();
}
return str19;
}
}
}
| Java | ["2\n59 3\n1000000000000000000 10"] | 1 second | ["8\n19"] | NoteSteps for the first test case are: $$$59 \rightarrow 58 \rightarrow 57 \rightarrow 19 \rightarrow 18 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.In the second test case you have to divide $$$n$$$ by $$$k$$$ $$$18$$$ times and then decrease $$$n$$$ by $$$1$$$. | Java 8 | standard input | [
"implementation",
"math"
] | 00b1e45e9395d23e850ce1a0751b8378 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The only line of each query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^{18}$$$, $$$2 \le k \le 10^{18}$$$). | 900 | For each query print the minimum number of steps to reach $$$0$$$ from $$$n$$$ in single line. | standard output | |
PASSED | 53bd7dac2998d564eebc1a474703c153 | train_003.jsonl | 1559745300 | You are given an integer $$$n$$$ and an integer $$$k$$$.In one step you can do one of the following moves: decrease $$$n$$$ by $$$1$$$; divide $$$n$$$ by $$$k$$$ if $$$n$$$ is divisible by $$$k$$$. For example, if $$$n = 27$$$ and $$$k = 3$$$ you can do the following steps: $$$27 \rightarrow 26 \rightarrow 25 \rightarrow 24 \rightarrow 8 \rightarrow 7 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.You are asked to calculate the minimum number of steps to reach $$$0$$$ from $$$n$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class GoodWork {
static FastReader in =new FastReader();
static long n,m,k;
static int a[],x,c;
static String S;
public static void main(String[] args) {
int t=in.nextInt();
while(t>0){
n=in.nextLong();k=in.nextLong();
while(n>0){
if(n%k==0){n/=k;m++;}
else {m+=(n%k);n-=(n%k);}
}
System.out.println(m);
m=0;t--;
}}
}
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
class Sorting{
public static int[] bucketSort(int[] array, int bucketCount) {
if (bucketCount <= 0) throw new IllegalArgumentException("Invalid bucket count");
if (array.length <= 1) return array; //trivially sorted
int high = array[0];
int low = array[0];
for (int i = 1; i < array.length; i++) { //find the range of input elements
if (array[i] > high) high = array[i];
if (array[i] < low) low = array[i];
}
double interval = ((double)(high - low + 1))/bucketCount; //range of one bucket
ArrayList<Integer> buckets[] = new ArrayList[bucketCount];
for (int i = 0; i < bucketCount; i++) { //initialize buckets
buckets[i] = new ArrayList();
}
for (int i = 0; i < array.length; i++) { //partition the input array
buckets[(int)((array[i] - low)/interval)].add(array[i]);
}
int pointer = 0;
for (int i = 0; i < buckets.length; i++) {
Collections.sort(buckets[i]); //mergeSort
for (int j = 0; j < buckets[i].size(); j++) { //merge the buckets
array[pointer] = buckets[i].get(j);
pointer++;
}
}
return array;
}
} | Java | ["2\n59 3\n1000000000000000000 10"] | 1 second | ["8\n19"] | NoteSteps for the first test case are: $$$59 \rightarrow 58 \rightarrow 57 \rightarrow 19 \rightarrow 18 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.In the second test case you have to divide $$$n$$$ by $$$k$$$ $$$18$$$ times and then decrease $$$n$$$ by $$$1$$$. | Java 8 | standard input | [
"implementation",
"math"
] | 00b1e45e9395d23e850ce1a0751b8378 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The only line of each query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^{18}$$$, $$$2 \le k \le 10^{18}$$$). | 900 | For each query print the minimum number of steps to reach $$$0$$$ from $$$n$$$ in single line. | standard output | |
PASSED | 4ec30c1676070bc88c76656c4987e836 | train_003.jsonl | 1559745300 | You are given an integer $$$n$$$ and an integer $$$k$$$.In one step you can do one of the following moves: decrease $$$n$$$ by $$$1$$$; divide $$$n$$$ by $$$k$$$ if $$$n$$$ is divisible by $$$k$$$. For example, if $$$n = 27$$$ and $$$k = 3$$$ you can do the following steps: $$$27 \rightarrow 26 \rightarrow 25 \rightarrow 24 \rightarrow 8 \rightarrow 7 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.You are asked to calculate the minimum number of steps to reach $$$0$$$ from $$$n$$$. | 256 megabytes |
import java.util.*;
import java.io.*;
public class Mamo {
static long mod=1000000007;
static Reader in=new Reader();
static List<Integer >G[];
static long a[],p[],xp[],xv[];
static StringBuilder Sd=new StringBuilder(),Sl=new StringBuilder();
public static void main(String [] args) {
//Dir by MohammedElkady
int t=in.nextInt();
while(t-->0) {
long ans=0L;
long n=in.l(),k=in.l();
while(n>0) {
if(n%k>0)
ans+=(n%k);
if(n>=k)
ans++;
n/=k;
}
out.append(ans+" \n");
}
out.close();
}
static long ans=0L;
static boolean v[];
static ArrayList<Integer>res;
static Queue <Integer> pop;
static Stack <Integer>rem;
public static void Dfs(int o) {
v[o]=true;
for(int i:G[o]) {
Dfs(i);
if(a[i]>0) {
res.add(i+1);
a[o]+=a[i];}
else {
rem.add(i+1);
}
}
ans+=a[o];
}
public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
static long gcd(long g,long x){if(x<1)return g;else return gcd(x,g%x);}
static class Reader
{
private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public Reader() { this(System.in); }public Reader(InputStream is) { mIs = is;}
public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];}
public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;}
public String s(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;}
public int nextInt(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;}
public double d() throws IOException {return Double.parseDouble(s()) ;}
public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; }
public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; }
public int[] arr(int n){int[] ret = new int[n];for (int i = 0; i < n; i++) {ret[i] = nextInt();}return ret;}
}
}
class node implements Comparable<node>{
int a, b;
node(int tt,int ll){
a=tt;b=ll;
}
@Override
public int compareTo(node o) {
return b-o.b;
}
}
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
class Sorting{
public static int[] bucketSort(int[] array, int bucketCount) {
if (bucketCount <= 0) throw new IllegalArgumentException("Invalid bucket count");
if (array.length <= 1) return array; //trivially sorted
int high = array[0];
int low = array[0];
for (int i = 1; i < array.length; i++) { //find the range of input elements
if (array[i] > high) high = array[i];
if (array[i] < low) low = array[i];
}
double interval = ((double)(high - low + 1))/bucketCount; //range of one bucket
ArrayList<Integer> buckets[] = new ArrayList[bucketCount];
for (int i = 0; i < bucketCount; i++) { //initialize buckets
buckets[i] = new ArrayList();
}
for (int i = 0; i < array.length; i++) { //partition the input array
buckets[(int)((array[i] - low)/interval)].add(array[i]);
}
int pointer = 0;
for (int i = 0; i < buckets.length; i++) {
Collections.sort(buckets[i]); //mergeSort
for (int j = 0; j < buckets[i].size(); j++) { //merge the buckets
array[pointer] = buckets[i].get(j);
pointer++;
}
}
return array;
}
} | Java | ["2\n59 3\n1000000000000000000 10"] | 1 second | ["8\n19"] | NoteSteps for the first test case are: $$$59 \rightarrow 58 \rightarrow 57 \rightarrow 19 \rightarrow 18 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.In the second test case you have to divide $$$n$$$ by $$$k$$$ $$$18$$$ times and then decrease $$$n$$$ by $$$1$$$. | Java 8 | standard input | [
"implementation",
"math"
] | 00b1e45e9395d23e850ce1a0751b8378 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The only line of each query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^{18}$$$, $$$2 \le k \le 10^{18}$$$). | 900 | For each query print the minimum number of steps to reach $$$0$$$ from $$$n$$$ in single line. | standard output | |
PASSED | 9f66856939736d22755463314c92040f | train_003.jsonl | 1559745300 | You are given an integer $$$n$$$ and an integer $$$k$$$.In one step you can do one of the following moves: decrease $$$n$$$ by $$$1$$$; divide $$$n$$$ by $$$k$$$ if $$$n$$$ is divisible by $$$k$$$. For example, if $$$n = 27$$$ and $$$k = 3$$$ you can do the following steps: $$$27 \rightarrow 26 \rightarrow 25 \rightarrow 24 \rightarrow 8 \rightarrow 7 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.You are asked to calculate the minimum number of steps to reach $$$0$$$ from $$$n$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class test
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static FastReader sc=new FastReader();
public static void process()
{
long n=sc.nextLong();
long k=sc.nextLong();
long step=0;
while(n>0)
{
if(n%k==0)
{
n/=k;
step++;
}
else
{
long temp=n%k;
n=n-temp;
step+=temp;
}
}
System.out.println(step);
}
public static void main(String[] args)
{
int T=sc.nextInt();
while(T-- > 0)
process();
}
} | Java | ["2\n59 3\n1000000000000000000 10"] | 1 second | ["8\n19"] | NoteSteps for the first test case are: $$$59 \rightarrow 58 \rightarrow 57 \rightarrow 19 \rightarrow 18 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.In the second test case you have to divide $$$n$$$ by $$$k$$$ $$$18$$$ times and then decrease $$$n$$$ by $$$1$$$. | Java 8 | standard input | [
"implementation",
"math"
] | 00b1e45e9395d23e850ce1a0751b8378 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The only line of each query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^{18}$$$, $$$2 \le k \le 10^{18}$$$). | 900 | For each query print the minimum number of steps to reach $$$0$$$ from $$$n$$$ in single line. | standard output | |
PASSED | d286bb7f267bd1219bcacfdf3c6afaef | train_003.jsonl | 1559745300 | You are given an integer $$$n$$$ and an integer $$$k$$$.In one step you can do one of the following moves: decrease $$$n$$$ by $$$1$$$; divide $$$n$$$ by $$$k$$$ if $$$n$$$ is divisible by $$$k$$$. For example, if $$$n = 27$$$ and $$$k = 3$$$ you can do the following steps: $$$27 \rightarrow 26 \rightarrow 25 \rightarrow 24 \rightarrow 8 \rightarrow 7 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.You are asked to calculate the minimum number of steps to reach $$$0$$$ from $$$n$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class FromHeroToZero {
public static void main(String[] args) throws NumberFormatException, IOException {
// TODO Auto-generated method stub
BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
//BufferedReader entrada = new BufferedReader(new FileReader("pruebas.txt"));
String res="";
long ren=0,n,k;
StringTokenizer linea;
int casos = Integer.parseInt(entrada.readLine());
for (int i = 0; i < casos; i++) {
linea = new StringTokenizer(entrada.readLine());
n=Long.parseLong(linea.nextToken());
k=Long.parseLong(linea.nextToken());
while(n!=0) {
if (n%k==0) { n/=k;ren++;}
else {ren+=(n%k);n=n-(n%k);}
//System.out.println(n);
}
System.out.println(ren);
ren=0;
}
}
}
| Java | ["2\n59 3\n1000000000000000000 10"] | 1 second | ["8\n19"] | NoteSteps for the first test case are: $$$59 \rightarrow 58 \rightarrow 57 \rightarrow 19 \rightarrow 18 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.In the second test case you have to divide $$$n$$$ by $$$k$$$ $$$18$$$ times and then decrease $$$n$$$ by $$$1$$$. | Java 8 | standard input | [
"implementation",
"math"
] | 00b1e45e9395d23e850ce1a0751b8378 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The only line of each query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^{18}$$$, $$$2 \le k \le 10^{18}$$$). | 900 | For each query print the minimum number of steps to reach $$$0$$$ from $$$n$$$ in single line. | standard output | |
PASSED | 1e9b0fc6a257fa467b65c9febc4813ee | train_003.jsonl | 1559745300 | You are given an integer $$$n$$$ and an integer $$$k$$$.In one step you can do one of the following moves: decrease $$$n$$$ by $$$1$$$; divide $$$n$$$ by $$$k$$$ if $$$n$$$ is divisible by $$$k$$$. For example, if $$$n = 27$$$ and $$$k = 3$$$ you can do the following steps: $$$27 \rightarrow 26 \rightarrow 25 \rightarrow 24 \rightarrow 8 \rightarrow 7 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.You are asked to calculate the minimum number of steps to reach $$$0$$$ from $$$n$$$. | 256 megabytes |
// From hero to zero
//
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t > 0) {
BigInteger n = sc.nextBigInteger();
BigInteger k = sc.nextBigInteger();
BigInteger steps = BigInteger.ZERO;
while (n.compareTo(BigInteger.ZERO) != 0) {
if (n.compareTo(k) < 0) {
steps = steps.add(n);
break;
}
if (isMod(n, k)) {
n = n.divide(k);
steps = steps.add(BigInteger.ONE);
} else {
BigInteger m = n.divide(k);
if (m.compareTo(BigInteger.ZERO) > 0) {
steps = steps.add(n.mod(k)).add(BigInteger.ONE);
n = m;
} else {
n = n.subtract(BigInteger.ONE);
steps = steps.add(BigInteger.ONE);
}
}
}
System.out.println(steps);
t--;
}
}
static boolean isMod(BigInteger n, BigInteger m) {
return n.mod(m).compareTo(BigInteger.ZERO) == 0;
}
} | Java | ["2\n59 3\n1000000000000000000 10"] | 1 second | ["8\n19"] | NoteSteps for the first test case are: $$$59 \rightarrow 58 \rightarrow 57 \rightarrow 19 \rightarrow 18 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.In the second test case you have to divide $$$n$$$ by $$$k$$$ $$$18$$$ times and then decrease $$$n$$$ by $$$1$$$. | Java 8 | standard input | [
"implementation",
"math"
] | 00b1e45e9395d23e850ce1a0751b8378 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The only line of each query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^{18}$$$, $$$2 \le k \le 10^{18}$$$). | 900 | For each query print the minimum number of steps to reach $$$0$$$ from $$$n$$$ in single line. | standard output | |
PASSED | 0895215252594e054d05b132c0cc5665 | train_003.jsonl | 1559745300 | You are given an integer $$$n$$$ and an integer $$$k$$$.In one step you can do one of the following moves: decrease $$$n$$$ by $$$1$$$; divide $$$n$$$ by $$$k$$$ if $$$n$$$ is divisible by $$$k$$$. For example, if $$$n = 27$$$ and $$$k = 3$$$ you can do the following steps: $$$27 \rightarrow 26 \rightarrow 25 \rightarrow 24 \rightarrow 8 \rightarrow 7 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.You are asked to calculate the minimum number of steps to reach $$$0$$$ from $$$n$$$. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.math.*;
import java.util.regex.*;
import java.io.*;
public class HeroToZero {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
long x = in.nextLong();
for(int i = 0; i < x; i++) {
long n = in.nextLong();
long k = in.nextLong();
long ct = 0;
while(n > 0) {
//System.out.println(n + " " + ct);
if(n % k == 0) {
n = n/k;
ct++;
}else {
ct += n % k;
n -= n % k;
}
}
System.out.println(ct);
}
}
}
| Java | ["2\n59 3\n1000000000000000000 10"] | 1 second | ["8\n19"] | NoteSteps for the first test case are: $$$59 \rightarrow 58 \rightarrow 57 \rightarrow 19 \rightarrow 18 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.In the second test case you have to divide $$$n$$$ by $$$k$$$ $$$18$$$ times and then decrease $$$n$$$ by $$$1$$$. | Java 8 | standard input | [
"implementation",
"math"
] | 00b1e45e9395d23e850ce1a0751b8378 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The only line of each query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^{18}$$$, $$$2 \le k \le 10^{18}$$$). | 900 | For each query print the minimum number of steps to reach $$$0$$$ from $$$n$$$ in single line. | standard output | |
PASSED | a206e98443eeb4b8a442771aec2aee0d | train_003.jsonl | 1559745300 | You are given an integer $$$n$$$ and an integer $$$k$$$.In one step you can do one of the following moves: decrease $$$n$$$ by $$$1$$$; divide $$$n$$$ by $$$k$$$ if $$$n$$$ is divisible by $$$k$$$. For example, if $$$n = 27$$$ and $$$k = 3$$$ you can do the following steps: $$$27 \rightarrow 26 \rightarrow 25 \rightarrow 24 \rightarrow 8 \rightarrow 7 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.You are asked to calculate the minimum number of steps to reach $$$0$$$ from $$$n$$$. | 256 megabytes | //author mo7amad
import java.util.Scanner;
public class P35 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long z = sc.nextLong(), n, a, count;
for (int i = 0; i < z; i++) {
count = 0;
n = sc.nextLong();
a = sc.nextLong();
while (n > 0) {
if (n % a == 0) {
n /= a;
count++;
}else if(n==1){
n--;
count++;
break;
}else{
count+=(n % a);
n-=(n % a);
}
}
System.out.println(count);
}
}
}
| Java | ["2\n59 3\n1000000000000000000 10"] | 1 second | ["8\n19"] | NoteSteps for the first test case are: $$$59 \rightarrow 58 \rightarrow 57 \rightarrow 19 \rightarrow 18 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.In the second test case you have to divide $$$n$$$ by $$$k$$$ $$$18$$$ times and then decrease $$$n$$$ by $$$1$$$. | Java 8 | standard input | [
"implementation",
"math"
] | 00b1e45e9395d23e850ce1a0751b8378 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The only line of each query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^{18}$$$, $$$2 \le k \le 10^{18}$$$). | 900 | For each query print the minimum number of steps to reach $$$0$$$ from $$$n$$$ in single line. | standard output | |
PASSED | 8ef11da835740cde6b2b798a9910b59f | train_003.jsonl | 1559745300 | You are given an integer $$$n$$$ and an integer $$$k$$$.In one step you can do one of the following moves: decrease $$$n$$$ by $$$1$$$; divide $$$n$$$ by $$$k$$$ if $$$n$$$ is divisible by $$$k$$$. For example, if $$$n = 27$$$ and $$$k = 3$$$ you can do the following steps: $$$27 \rightarrow 26 \rightarrow 25 \rightarrow 24 \rightarrow 8 \rightarrow 7 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.You are asked to calculate the minimum number of steps to reach $$$0$$$ from $$$n$$$. | 256 megabytes |
//author mo7amad
import java.util.Scanner;
public class P35 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long z = sc.nextLong(), n, a, count;
for (int i = 0; i < z; i++) {
count = 0;
n = sc.nextLong();
a = sc.nextLong();
while (n > 0) {
if (n % a == 0) {
n /= a;
count++;
}else{
count+=(n % a);
n-=(n % a);
}
}
System.out.println(count);
}
}
}
| Java | ["2\n59 3\n1000000000000000000 10"] | 1 second | ["8\n19"] | NoteSteps for the first test case are: $$$59 \rightarrow 58 \rightarrow 57 \rightarrow 19 \rightarrow 18 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.In the second test case you have to divide $$$n$$$ by $$$k$$$ $$$18$$$ times and then decrease $$$n$$$ by $$$1$$$. | Java 8 | standard input | [
"implementation",
"math"
] | 00b1e45e9395d23e850ce1a0751b8378 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The only line of each query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^{18}$$$, $$$2 \le k \le 10^{18}$$$). | 900 | For each query print the minimum number of steps to reach $$$0$$$ from $$$n$$$ in single line. | standard output | |
PASSED | 75b3933d60a3669f9871c79a43cce8bd | train_003.jsonl | 1559745300 | You are given an integer $$$n$$$ and an integer $$$k$$$.In one step you can do one of the following moves: decrease $$$n$$$ by $$$1$$$; divide $$$n$$$ by $$$k$$$ if $$$n$$$ is divisible by $$$k$$$. For example, if $$$n = 27$$$ and $$$k = 3$$$ you can do the following steps: $$$27 \rightarrow 26 \rightarrow 25 \rightarrow 24 \rightarrow 8 \rightarrow 7 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.You are asked to calculate the minimum number of steps to reach $$$0$$$ from $$$n$$$. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String args[]) {
// System.out.println("Hello World!");
Scanner scn = new Scanner(System.in);
int t = scn.nextInt();
for(int i=0;i<t;++i){
long n = scn.nextLong();
long k = scn.nextLong();
System.out.println(minimum(n,k));
}
}
public static long minimum(long n, long k){
if(n<k){
return n;
}
long temp = (long)(n/k);
temp = temp * k;
long dummy = n-temp;
return (minimum((temp)/k,k)+dummy)+1;
}
} | Java | ["2\n59 3\n1000000000000000000 10"] | 1 second | ["8\n19"] | NoteSteps for the first test case are: $$$59 \rightarrow 58 \rightarrow 57 \rightarrow 19 \rightarrow 18 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.In the second test case you have to divide $$$n$$$ by $$$k$$$ $$$18$$$ times and then decrease $$$n$$$ by $$$1$$$. | Java 8 | standard input | [
"implementation",
"math"
] | 00b1e45e9395d23e850ce1a0751b8378 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The only line of each query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^{18}$$$, $$$2 \le k \le 10^{18}$$$). | 900 | For each query print the minimum number of steps to reach $$$0$$$ from $$$n$$$ in single line. | standard output | |
PASSED | 36a3df7a148de3bd04b8428eff03559e | train_003.jsonl | 1559745300 | You are given an integer $$$n$$$ and an integer $$$k$$$.In one step you can do one of the following moves: decrease $$$n$$$ by $$$1$$$; divide $$$n$$$ by $$$k$$$ if $$$n$$$ is divisible by $$$k$$$. For example, if $$$n = 27$$$ and $$$k = 3$$$ you can do the following steps: $$$27 \rightarrow 26 \rightarrow 25 \rightarrow 24 \rightarrow 8 \rightarrow 7 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.You are asked to calculate the minimum number of steps to reach $$$0$$$ from $$$n$$$. | 256 megabytes |
/*
9 2
1 1 1 1 1 0 0 0 0
1 2
1 5
5 6
5 7
2 3
2 4
3 8
3 9
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
public class Question{
static LinkedList<Integer> adj[] ;
static boolean[] visited;
static boolean[] visited_;
static int[] ans;
static int count_ = 0;
static final int MAX_SIZE = 1000001;
static Vector<Boolean>isprime = new Vector<>(MAX_SIZE);
static Vector<Integer>prime = new Vector<>();
static Vector<Integer>SPF = new Vector<>(MAX_SIZE);
public static void main(String[] args) throws IOException {
Reader.init(System.in);
int q = Reader.nextInt();
while (q-->0){
long n = Reader.nextLong();
long k = Reader.nextLong();
long cnt = 0;
while (n!=0){
if (n%k==0){
n = n/k;
cnt++;
}
else{
cnt+=(n%k);
n = n-(n%k);
}
//System.out.println(n + " " + cnt);
}
System.out.println(cnt);
}
}
static void manipulated_seive(int N)
{
// 0 and 1 are not prime
isprime.set(0, false);
isprime.set(1, false);
// Fill rest of the entries
for (int i=2; i<N ; i++)
{
// If isPrime[i] == True then i is
// prime number
if (isprime.get(i))
{
// put i into prime[] vector
prime.add(i);
// A prime number is its own smallest
// prime factor
SPF.set(i,i);
}
// Remove all multiples of i*prime[j] which are
// not prime by making isPrime[i*prime[j]] = false
// and put smallest prime factor of i*Prime[j] as prime[j]
// [for exp :let i = 5, j = 0, prime[j] = 2 [ i*prime[j] = 10]
// so smallest prime factor of '10' is '2' that is prime[j] ]
// this loop run only one time for number which are not prime
for (int j=0;
j < prime.size() &&
i*prime.get(j) < N && prime.get(j) <= SPF.get(i);
j++)
{
isprime.set(i*prime.get(j),false);
// put smallest prime factor of i*prime[j]
SPF.set(i*prime.get(j),prime.get(j)) ;
}
}
}
static int countGreater(long arr[], int n, long k)
{
int l = 0;
int r = n - 1;
// Stores the index of the left most element
// from the array which is greater than k
int leftGreater = n;
// Finds number of elements greater than k
while (l <= r) {
int m = l + (r - l) / 2;
// If mid element is greater than
// k update leftGreater and r
if (arr[m] > k) {
leftGreater = m;
r = m - 1;
}
// If mid element is less than
// or equal to k update l
else
l = m + 1;
}
// Return the count of elements greater than k
return (n - leftGreater);
}
static void sortbyColumn(int arr[][], int col)
{
// Using built-in sort function Arrays.sort
Arrays.sort(arr, new Comparator<int[]>() {
@Override
// Compare values according to columns
public int compare(final int[] entry1,
final int[] entry2) {
// To sort in descending order revert
// the '>' Operator
if (entry1[col] > entry2[col])
return 1;
else
return -1;
}
}); // End of function call sort().
}
static int binarySearchCount(long arr[], int n, long key,int left)
{
int right = n;
int mid = 0;
while (left < right) {
mid = (right + left) >> 1;
// Check if key is present in array
if (arr[mid] == key) {
// If duplicates are present it returns
// the position of last element
while (mid+1<n && arr[mid + 1] == key)
mid++;
break;
}
// If key is smaller, ignore right half
else if (arr[mid] > key)
right = mid;
// If key is greater, ignore left half
else
left = mid + 1;
}
// If key is not found in array then it will be
// before mid
while (mid > - 1 && arr[mid] > key)
mid--;
// Return mid + 1 because of 0-based indexing
// of array
return mid + 1;
}
static long gcd(long a, long b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
// method to return LCM of two numbers
static long lcm(long a, long b)
{
return (a*b)/gcd(a, b);
}
static long fun(long n){
long max = -1;
for (int i = 0 ; i < n ; i++){
String x = Integer.toString(i);
long product = 1;
for (int j = 0 ; j < x.length() ; j++){
product = product * Long.parseLong(Character.toString(x.charAt(j)));
}
max = Math.max(product,max);
}
return max;
}
public static void print2D(int mat[][])
{
// Loop through all rows
for (int[] row : mat)
// converting each row as string
// and then printing in a separate line
System.out.println(Arrays.toString(row));
}
}
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input) );
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine() );
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static long nextLong() throws IOException {
return Long.parseLong( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
}
class MergeSort {
// Merges two subarrays of arr[].
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
void merge(int arr[], int l, int m, int r) {
// Find sizes of two subarrays to be merged
int n1 = m - l + 1;
int n2 = r - m;
/* Create temp arrays */
int L[] = new int[n1];
int R[] = new int[n2];
/*Copy data to temp arrays*/
for (int i = 0; i < n1; ++i)
L[i] = arr[l + i];
for (int j = 0; j < n2; ++j)
R[j] = arr[m + 1 + j];
/* Merge the temp arrays */
// Initial indexes of first and second subarrays
int i = 0, j = 0;
// Initial index of merged subarry array
int k = l;
while (i < n1 && j < n2) {
if (L[i] <= R[j]) {
arr[k] = L[i];
i++;
} else {
arr[k] = R[j];
j++;
}
k++;
}
/* Copy remaining elements of L[] if any */
while (i < n1) {
arr[k] = L[i];
i++;
k++;
}
/* Copy remaining elements of R[] if any */
while (j < n2) {
arr[k] = R[j];
j++;
k++;
}
}
// Main function that sorts arr[l..r] using
// merge()
void sort(int arr[], int l, int r) {
if (l < r) {
// Find the middle point
int m = (l + r) / 2;
// Sort first and second halves
sort(arr, l, m);
sort(arr, m + 1, r);
// Merge the sorted halves
merge(arr, l, m, r);
}
}
/* A utility function to print array of size n */
static void printArray(int arr[]) {
int n = arr.length;
for (int i = 0; i < n; ++i)
System.out.print(arr[i] + " ");
System.out.println();
}
static long phi(long n,long R)
{
long result = R;
for (long p = 2; p * p <= n; ++p)
{
if (n % p == 0)
{
while (n % p == 0)
n =n/p;
result =result - ( result / p);
}
}
//System.out.println("n" + n);
if (n > 1)
result -= result / n;
return result;
}
}
class person{
int index;
int money;
public person(int index, int money) {
this.index = index;
this.money = money;
}
public void setIndex(int index) {
this.index = index;
}
public void setMoney(int money) {
this.money = money;
}
public int getIndex() {
return index;
}
public int getMoney() {
return money;
}
}
class StudentComparator implements Comparator<person>{
// Overriding compare()method of Comparator
// for descending order of cgpa
public int compare(person s1, person s2) {
if (s1.money > s2.money)
return 1;
else if (s1.money < s2.money) {
return -1;
}
else{
if (s1.index >s2.index){
return 1;
}
else{
return -1;
}
}
}
}
| Java | ["2\n59 3\n1000000000000000000 10"] | 1 second | ["8\n19"] | NoteSteps for the first test case are: $$$59 \rightarrow 58 \rightarrow 57 \rightarrow 19 \rightarrow 18 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.In the second test case you have to divide $$$n$$$ by $$$k$$$ $$$18$$$ times and then decrease $$$n$$$ by $$$1$$$. | Java 8 | standard input | [
"implementation",
"math"
] | 00b1e45e9395d23e850ce1a0751b8378 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The only line of each query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^{18}$$$, $$$2 \le k \le 10^{18}$$$). | 900 | For each query print the minimum number of steps to reach $$$0$$$ from $$$n$$$ in single line. | standard output | |
PASSED | f68c22cf12500d44d7a1e248aa0bdd82 | train_003.jsonl | 1559745300 | You are given an integer $$$n$$$ and an integer $$$k$$$.In one step you can do one of the following moves: decrease $$$n$$$ by $$$1$$$; divide $$$n$$$ by $$$k$$$ if $$$n$$$ is divisible by $$$k$$$. For example, if $$$n = 27$$$ and $$$k = 3$$$ you can do the following steps: $$$27 \rightarrow 26 \rightarrow 25 \rightarrow 24 \rightarrow 8 \rightarrow 7 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.You are asked to calculate the minimum number of steps to reach $$$0$$$ from $$$n$$$. | 256 megabytes | /* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
public static void main (String[] args) throws IOException
{
// your code goes here
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int t=Integer.parseInt(br.readLine());
while(t--!=0)
{
String s1[]=br.readLine().split("\\s+");
long num =Long.parseLong(s1[0]);
long k=Long.parseLong(s1[1]);
long count=0;
//num=num-1;
while(num>0){
if(num%k!=0){
long n=num%k;
num=num-n;
count=count+n;
//System.out.print(num+" ");
}
else{
num=num/k;
count++;
}
/* if(num>0)
{
int n=0;
if(num%k!=0)
n=num%k;
count=count+n;
num=num-n;
}*/
}
bw.write(count+"\n");
}
bw.flush();
}
} | Java | ["2\n59 3\n1000000000000000000 10"] | 1 second | ["8\n19"] | NoteSteps for the first test case are: $$$59 \rightarrow 58 \rightarrow 57 \rightarrow 19 \rightarrow 18 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.In the second test case you have to divide $$$n$$$ by $$$k$$$ $$$18$$$ times and then decrease $$$n$$$ by $$$1$$$. | Java 8 | standard input | [
"implementation",
"math"
] | 00b1e45e9395d23e850ce1a0751b8378 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The only line of each query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^{18}$$$, $$$2 \le k \le 10^{18}$$$). | 900 | For each query print the minimum number of steps to reach $$$0$$$ from $$$n$$$ in single line. | standard output | |
PASSED | e4b29fe0eeeff2f1322e4d574d96d630 | train_003.jsonl | 1559745300 | You are given an integer $$$n$$$ and an integer $$$k$$$.In one step you can do one of the following moves: decrease $$$n$$$ by $$$1$$$; divide $$$n$$$ by $$$k$$$ if $$$n$$$ is divisible by $$$k$$$. For example, if $$$n = 27$$$ and $$$k = 3$$$ you can do the following steps: $$$27 \rightarrow 26 \rightarrow 25 \rightarrow 24 \rightarrow 8 \rightarrow 7 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.You are asked to calculate the minimum number of steps to reach $$$0$$$ from $$$n$$$. | 256 megabytes | import java.util.Scanner;
public class Codeforces1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int a = input.nextInt();
for (int i = 0; i < a; i++) {
long n = input.nextLong();
long k = input.nextLong();
long c = 0;
while (n > 0) {
c += n % k;
n /= k;
if (n != 0) {
c++;
}
}
System.out.println(c);
}
}
} | Java | ["2\n59 3\n1000000000000000000 10"] | 1 second | ["8\n19"] | NoteSteps for the first test case are: $$$59 \rightarrow 58 \rightarrow 57 \rightarrow 19 \rightarrow 18 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.In the second test case you have to divide $$$n$$$ by $$$k$$$ $$$18$$$ times and then decrease $$$n$$$ by $$$1$$$. | Java 8 | standard input | [
"implementation",
"math"
] | 00b1e45e9395d23e850ce1a0751b8378 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The only line of each query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^{18}$$$, $$$2 \le k \le 10^{18}$$$). | 900 | For each query print the minimum number of steps to reach $$$0$$$ from $$$n$$$ in single line. | standard output | |
PASSED | 3ad78d97f6f9f1fdff913e3a480d7e72 | train_003.jsonl | 1559745300 | You are given an integer $$$n$$$ and an integer $$$k$$$.In one step you can do one of the following moves: decrease $$$n$$$ by $$$1$$$; divide $$$n$$$ by $$$k$$$ if $$$n$$$ is divisible by $$$k$$$. For example, if $$$n = 27$$$ and $$$k = 3$$$ you can do the following steps: $$$27 \rightarrow 26 \rightarrow 25 \rightarrow 24 \rightarrow 8 \rightarrow 7 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.You are asked to calculate the minimum number of steps to reach $$$0$$$ from $$$n$$$. | 256 megabytes | //@author Haya
import java.util.Scanner;
public class FromHeroToZero {
public static void main(String[] args) {
Scanner sc= new Scanner (System.in);
int t= sc.nextInt();
long n, k, count=0;
for (int i = 0; i < t; i++){
count=0;
n= sc.nextLong();
k= sc.nextLong();
while(n>0){
if (n%k==0){
n/=k;
count++;}
else{
count+=(n % k);
n-=(n % k);}}
System.out.println(count);}
}
} | Java | ["2\n59 3\n1000000000000000000 10"] | 1 second | ["8\n19"] | NoteSteps for the first test case are: $$$59 \rightarrow 58 \rightarrow 57 \rightarrow 19 \rightarrow 18 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.In the second test case you have to divide $$$n$$$ by $$$k$$$ $$$18$$$ times and then decrease $$$n$$$ by $$$1$$$. | Java 8 | standard input | [
"implementation",
"math"
] | 00b1e45e9395d23e850ce1a0751b8378 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The only line of each query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^{18}$$$, $$$2 \le k \le 10^{18}$$$). | 900 | For each query print the minimum number of steps to reach $$$0$$$ from $$$n$$$ in single line. | standard output | |
PASSED | ef09676a4cade412561dffdf8b48fd50 | train_003.jsonl | 1559745300 | You are given an integer $$$n$$$ and an integer $$$k$$$.In one step you can do one of the following moves: decrease $$$n$$$ by $$$1$$$; divide $$$n$$$ by $$$k$$$ if $$$n$$$ is divisible by $$$k$$$. For example, if $$$n = 27$$$ and $$$k = 3$$$ you can do the following steps: $$$27 \rightarrow 26 \rightarrow 25 \rightarrow 24 \rightarrow 8 \rightarrow 7 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.You are asked to calculate the minimum number of steps to reach $$$0$$$ from $$$n$$$. | 256 megabytes |
import java.util.*;
//import java.util.ArrayList;
//import java.util.Scanner;
public class Javacodeforce {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
long n=sc.nextLong();
long k=sc.nextLong();
long count=0;
while(n>0){
if(n%k==0){
n=n/k;
count++;
}
else{long x=n%k;count+=x;n=n-x;}
}
System.out.println(count);
}
}
}
| Java | ["2\n59 3\n1000000000000000000 10"] | 1 second | ["8\n19"] | NoteSteps for the first test case are: $$$59 \rightarrow 58 \rightarrow 57 \rightarrow 19 \rightarrow 18 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.In the second test case you have to divide $$$n$$$ by $$$k$$$ $$$18$$$ times and then decrease $$$n$$$ by $$$1$$$. | Java 8 | standard input | [
"implementation",
"math"
] | 00b1e45e9395d23e850ce1a0751b8378 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The only line of each query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^{18}$$$, $$$2 \le k \le 10^{18}$$$). | 900 | For each query print the minimum number of steps to reach $$$0$$$ from $$$n$$$ in single line. | standard output | |
PASSED | b6ae625778ca5ec15b83eb26d565336e | train_003.jsonl | 1559745300 | You are given an integer $$$n$$$ and an integer $$$k$$$.In one step you can do one of the following moves: decrease $$$n$$$ by $$$1$$$; divide $$$n$$$ by $$$k$$$ if $$$n$$$ is divisible by $$$k$$$. For example, if $$$n = 27$$$ and $$$k = 3$$$ you can do the following steps: $$$27 \rightarrow 26 \rightarrow 25 \rightarrow 24 \rightarrow 8 \rightarrow 7 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.You are asked to calculate the minimum number of steps to reach $$$0$$$ from $$$n$$$. | 256 megabytes | import java.util.*;
import java.io.*;
public class Abc
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static long ten=(long)Math.pow(10,18);
static PrintWriter pw=new PrintWriter(System.out);
public static void main(String[] args) {
FastReader in=new FastReader();
int t=in.nextInt();
assertion(t,1,100);
for(int g=0;g<t;g++)
{
long n,k;
n=in.nextLong();
k=in.nextLong();
//System.out.println(n+" "+k);
assertion(n,1,ten);
assertion(k,2,ten);
BFS(n,k);
}
pw.close();
}
public static void BFS(long n,long k)
{
Queue<Long> q=new LinkedList<>();
HashMap<Long,Long> map=new HashMap<>();
q.add(n);
map.put(n,0l);
while(!q.isEmpty())
{
long u=q.poll();
//System.out.println("Pulled out "+u);
long a,b;
a=u-(u%k);
b=u/k;
if(u!=a&&map.get(a)==null)
{
map.put(a,map.get(u)+(u%k));
q.add(a);
if(a==0l)
break;
//System.out.println("Put : "+a+" "+map.get(a));
}
if(u%k==0&&(map.get(b)==null))
{
map.put(b,map.get(u)+1);
q.add(b);
if(b==0l)
break;
//System.out.println("Put : "+b+" "+map.get(b));
}
}
pw.println(map.get(0l));
}
public static void assertion(long a,long b,long c)
{
if(a<b||a>c)
System.exit(0);
}
} | Java | ["2\n59 3\n1000000000000000000 10"] | 1 second | ["8\n19"] | NoteSteps for the first test case are: $$$59 \rightarrow 58 \rightarrow 57 \rightarrow 19 \rightarrow 18 \rightarrow 6 \rightarrow 2 \rightarrow 1 \rightarrow 0$$$.In the second test case you have to divide $$$n$$$ by $$$k$$$ $$$18$$$ times and then decrease $$$n$$$ by $$$1$$$. | Java 8 | standard input | [
"implementation",
"math"
] | 00b1e45e9395d23e850ce1a0751b8378 | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The only line of each query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^{18}$$$, $$$2 \le k \le 10^{18}$$$). | 900 | For each query print the minimum number of steps to reach $$$0$$$ from $$$n$$$ in single line. | standard output | |
PASSED | ba6d244d6b64213d0b9ad4f558cd3b72 | train_003.jsonl | 1311346800 | In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup to another. Now Gerasim wants to check his hypothesis. The good thing is that chef Gerasim always pour the same number of milliliters of juice to all cups in the royal kitchen. Having thoroughly measured the juice in each cup, Gerasim asked you to write a program that will determine from which cup juice was poured to which one; otherwise, the program should determine that this time the pages set the table diligently.To simplify your task we shall consider the cups to be bottomless so that the juice never overfills a cup and pours out, however much it can be. Besides, by some strange reason in a far away kingdom one can only pour to a cup or from one cup to another an integer number of milliliters of juice. | 256 megabytes | import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author nasko
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
}
class TaskB {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
int[] arr = new int[n];
for(int i = 0; i < n; ++i) {
arr[i] = in.nextInt();
}
int[] temp = arr.clone();
Arrays.sort(temp);
int[] r = new int[10001];
Arrays.fill(r,0);
for(int i : arr) r[i]++;
if(temp[0] == temp[temp.length-1]) {
out.println("Exemplary pages.");
}
else if(n == 1) out.println("Exemplary pages.");
else if(n == 3) {
int l = 0;
for(int i : arr) if(r[i]==1) ++l;
if(l != 3) {
out.println("Unrecoverable configuration.");
} else {
int min = arr[0];
int mini = 0;
int max = arr[0];
int maxi = 0;
for(int i = 1; i < n; ++i) {
if(min > arr[i]) {
min = arr[i];
mini = i;
}
if(max < arr[i]) {
max = arr[i];
maxi = i;
}
}
int diff = arr[maxi] - arr[mini];
if(diff % 2 != 0) {
out.println("Unrecoverable configuration.");
} else {
arr[mini] += diff/2;
arr[maxi] -= diff/2;
Arrays.sort(arr);
if(arr[0] == arr[2]) {
out.println(diff/2 + " ml. from cup #"+(mini+1)+" to cup #"+(maxi+1)+".");
} else {
out.println("Unrecoverable configuration.");
}
}
}
}
else {
Arrays.sort(temp);
if(temp[0] == temp[temp.length-1]) out.println("Exemplary pages.");
else {
int first = -1;
int second = -1;
for(int i = 0; i < arr.length; ++i) {
if(r[arr[i]] == 1) {
if(first == -1) {
first = i;
}
for(int j = i + 1; j < arr.length; ++j) {
if(r[arr[j]] == 1) {
if(second == -1) {
second = j;
}
}
}
}
}
if(first == -1 || second == -1) {
out.println("Unrecoverable configuration.");
} else {
int diff = Math.abs(arr[first]-arr[second]);
if(diff % 2 != 0) {
out.println("Unrecoverable configuration.");
} else {
int min = -1;
int max = -1;
// out.println(arr[first] + " " + arr[second]);
if(arr[first] < arr[second]) {
min = first;
max = second;
} else {
min = second;
max = first;
}
diff /= 2;
arr[min] += diff;
arr[max] -= diff;
Arrays.sort(arr);
if(arr[0] != arr[arr.length-1]) {
// out.println("HERE?");
// out.println(Arrays.toString(arr));
out.println("Unrecoverable configuration.");
} else {
out.println(diff + " ml. from cup #"+(min+1)+" to cup #"+(max+1)+".");
}
}
}
}
}
}
}
class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
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());
}
}
| Java | ["5\n270\n250\n250\n230\n250", "5\n250\n250\n250\n250\n250", "5\n270\n250\n249\n230\n250"] | 0.5 second | ["20 ml. from cup #4 to cup #1.", "Exemplary pages.", "Unrecoverable configuration."] | null | Java 7 | standard input | [
"implementation",
"sortings"
] | 7bfc0927ea7abcef661263e978612cc5 | The first line contains integer n — the number of cups on the royal table (1 ≤ n ≤ 1000). Next n lines contain volumes of juice in each cup — non-negative integers, not exceeding 104. | 1,300 | If the pages didn't pour the juice, print "Exemplary pages." (without the quotes). If you can determine the volume of juice poured during exactly one juice pouring, print "v ml. from cup #a to cup #b." (without the quotes), where v represents the volume of poured juice, a represents the number of the cup from which the juice was poured (the cups are numbered with consecutive positive integers starting from one in the order in which the cups are described in the input data), b represents the number of the cup into which the juice was poured. Finally, if the given juice's volumes cannot be obtained using no more than one pouring (for example, the pages poured the juice from one cup to another more than once or the royal kitchen maids poured the juice into the cups incorrectly), print "Unrecoverable configuration." (without the quotes). | standard output | |
PASSED | d88f02da7c339eb5654d92d1c521df4d | train_003.jsonl | 1311346800 | In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup to another. Now Gerasim wants to check his hypothesis. The good thing is that chef Gerasim always pour the same number of milliliters of juice to all cups in the royal kitchen. Having thoroughly measured the juice in each cup, Gerasim asked you to write a program that will determine from which cup juice was poured to which one; otherwise, the program should determine that this time the pages set the table diligently.To simplify your task we shall consider the cups to be bottomless so that the juice never overfills a cup and pours out, however much it can be. Besides, by some strange reason in a far away kingdom one can only pour to a cup or from one cup to another an integer number of milliliters of juice. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
public class Main {
public static class Pair
{
int first,second;
public Pair(int a,int b) {
first=a;
second=b;
}
}
public static void main(String []argc) throws IOException
{
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw=new PrintWriter(System.out);
//StringTokenizer st=new StringTokenizer(bf.readLine());
int n=Integer.parseInt(bf.readLine());
int sum=0;
TreeMap<Integer,Pair> a=new TreeMap<Integer,Pair>();
for(int i=0;i<n;i++)
{
int x=Integer.parseInt(bf.readLine());
if(a.containsKey(x))
a.put(x, new Pair(a.get(x).first+1,i+1));
else
a.put(x, new Pair(1,i+1));
sum+=x;
}
if(a.size()>3)
pw.print("Unrecoverable configuration.");
else
{
if(a.size()==1)
pw.print("Exemplary pages.");
else
{
if(sum%n!=0)
pw.print("Unrecoverable configuration.");
else
{
int norm=sum/n;
int c=0;
ArrayList<Integer> al=new ArrayList<Integer>();
for(Integer i:a.keySet())
{
if(!i.equals(norm))
{
if(c<2)
{
al.add(i);
c++;
}
else
{
pw.print("Unrecoverable configuration.");
c++;
}
}
}
if(c==2)
{
int z=norm-al.get(0);
if((al.get(1)-z)==norm)
{
int mi=0,ma=0;
if(z<0)
z=-z;
for(Integer i:a.keySet())
{
if(i==al.get(0))
{
mi=a.get(i).second;
continue;
}
if(i==al.get(1))
{
ma=a.get(i).second;
continue;
}
}
if(!(a.size()==2&&n!=2))
{
if(al.get(1)>al.get(0))
pw.print(z+" ml. from cup #"+mi+" to cup #"+ma+".");
else
pw.print(z+" ml. from cup #"+ma+" to cup #"+mi+".");
}
else
pw.print("Unrecoverable configuration.");
}
else
pw.print("Unrecoverable configuration.");
}
}
}
}
pw.flush();
}
}
/*
aaa
5
aaa posted on bbb's wall
bbc posted on aaa's wall
aaa likes ccc's post
aaa likes aab's post
kkk posted on ccc's wall
*/ | Java | ["5\n270\n250\n250\n230\n250", "5\n250\n250\n250\n250\n250", "5\n270\n250\n249\n230\n250"] | 0.5 second | ["20 ml. from cup #4 to cup #1.", "Exemplary pages.", "Unrecoverable configuration."] | null | Java 7 | standard input | [
"implementation",
"sortings"
] | 7bfc0927ea7abcef661263e978612cc5 | The first line contains integer n — the number of cups on the royal table (1 ≤ n ≤ 1000). Next n lines contain volumes of juice in each cup — non-negative integers, not exceeding 104. | 1,300 | If the pages didn't pour the juice, print "Exemplary pages." (without the quotes). If you can determine the volume of juice poured during exactly one juice pouring, print "v ml. from cup #a to cup #b." (without the quotes), where v represents the volume of poured juice, a represents the number of the cup from which the juice was poured (the cups are numbered with consecutive positive integers starting from one in the order in which the cups are described in the input data), b represents the number of the cup into which the juice was poured. Finally, if the given juice's volumes cannot be obtained using no more than one pouring (for example, the pages poured the juice from one cup to another more than once or the royal kitchen maids poured the juice into the cups incorrectly), print "Unrecoverable configuration." (without the quotes). | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.