prob_desc_description
stringlengths
63
3.8k
prob_desc_output_spec
stringlengths
17
1.47k
βŒ€
lang_cluster
stringclasses
2 values
src_uid
stringlengths
32
32
code_uid
stringlengths
32
32
lang
stringclasses
7 values
prob_desc_output_to
stringclasses
3 values
prob_desc_memory_limit
stringclasses
19 values
file_name
stringclasses
111 values
tags
listlengths
0
11
prob_desc_created_at
stringlengths
10
10
prob_desc_sample_inputs
stringlengths
2
802
prob_desc_notes
stringlengths
4
3k
βŒ€
exec_outcome
stringclasses
1 value
difficulty
int64
-1
3.5k
βŒ€
prob_desc_input_from
stringclasses
3 values
prob_desc_time_limit
stringclasses
27 values
prob_desc_input_spec
stringlengths
28
2.42k
βŒ€
prob_desc_sample_outputs
stringlengths
2
796
source_code
stringlengths
42
65.5k
hidden_unit_tests
stringclasses
1 value
Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer n he can represent fraction as a sum of three distinct positive fractions in form .Help Vladik with that, i.e for a given n find three distinct positive integers x, y and z such that . Because Chloe can't check Vladik's answer if the numbers are large, he asks you to print numbers not exceeding 109.If there is no such answer, print -1.
If the answer exists, print 3 distinct numbers x, y and z (1 ≀ x, y, z ≀ 109, x ≠ y, x ≠ z, y ≠ z). Otherwise print -1. If there are multiple answers, print any of them.
C
f60ea0f2caaec16894e84ba87f90c061
dfb3001e2dc120e0d6438c51055be68b
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "number theory", "brute force", "math" ]
1481726100
["3", "7"]
null
PASSED
1,500
standard input
1 second
The single line contains single integer n (1 ≀ n ≀ 104).
["2 7 42", "7 8 56"]
#include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> int main(){ int n; scanf("%d",&n); if(n==1) printf("-1\n"); else printf("%d %d %d\n",n,n+1,n*(n+1)); return 0; }
Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer n he can represent fraction as a sum of three distinct positive fractions in form .Help Vladik with that, i.e for a given n find three distinct positive integers x, y and z such that . Because Chloe can't check Vladik's answer if the numbers are large, he asks you to print numbers not exceeding 109.If there is no such answer, print -1.
If the answer exists, print 3 distinct numbers x, y and z (1 ≀ x, y, z ≀ 109, x ≠ y, x ≠ z, y ≠ z). Otherwise print -1. If there are multiple answers, print any of them.
C
f60ea0f2caaec16894e84ba87f90c061
39a34849d720515ac88d74af9c34fefe
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "number theory", "brute force", "math" ]
1481726100
["3", "7"]
null
PASSED
1,500
standard input
1 second
The single line contains single integer n (1 ≀ n ≀ 104).
["2 7 42", "7 8 56"]
#include <stdio.h> int main(){ int n, x, y, z; scanf("%i", &n); if (n==1){ printf("-1"); } else{ x=n; y=n+1; z=x*y; printf("%i %i %i", x, y, z); } return 0; }
Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer n he can represent fraction as a sum of three distinct positive fractions in form .Help Vladik with that, i.e for a given n find three distinct positive integers x, y and z such that . Because Chloe can't check Vladik's answer if the numbers are large, he asks you to print numbers not exceeding 109.If there is no such answer, print -1.
If the answer exists, print 3 distinct numbers x, y and z (1 ≀ x, y, z ≀ 109, x ≠ y, x ≠ z, y ≠ z). Otherwise print -1. If there are multiple answers, print any of them.
C
f60ea0f2caaec16894e84ba87f90c061
e7eb4ad72106c01e0f276555e158177f
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "number theory", "brute force", "math" ]
1481726100
["3", "7"]
null
PASSED
1,500
standard input
1 second
The single line contains single integer n (1 ≀ n ≀ 104).
["2 7 42", "7 8 56"]
#include <stdio.h> int main() { int n; scanf("%d",&n); if(n==1) printf("-1\n"); else printf("%d %d %d\n",n, n+1, n*(n+1)); return 0; }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
9c70b74c4fad86a1c623ab7cc396f0f4
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include <stdio.h> int main () { int a,b,c,x,y,i,t; scanf ("%d",&t); for (i=0;i<t;i++){ scanf ("%d %d %d",&a,&b,&c); if (b==0){ printf ("0\n"); } else{ x=c/2; if (x>b){ printf("%d\n",3*b); } else{ b=b-x; y=b/2; if (y>a) y=a; printf ("%d\n",3*(x+y)); } } } return 0; }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
fee138b0970b27ca68bed1e1b16a7816
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include<stdio.h> int main() { int n,a,b,c,d,s,e,f,g; scanf("%d",&n); while(n--) { scanf("%d%d%d",&a,&b,&c); d=0; g=0; e=0; f=0; for(;c>=2&&b>=1;) { d=d+2; c=c-2; e=e+1; b=b-1; } for(;a>=1&&b>=2;) { f=f+1; a=a-1; g=g+2; b=b-2; } s=d+e+f+g; printf("%d\n",s); } return 0; }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
356807b32aa17a7e6c637ce580baaebd
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include<stdio.h> int main() { int t,i,sum=0; scanf("%d",&t); for(i=0;i<t;i++) { int a,b,c; scanf("%d%d%d",&a,&b,&c); if(b>0&&b>=c/2) { sum+=c/2+((c/2)*2); b-=c/2; if(a>0&&a>=b/2) { sum+=b/2+((b/2)*2); } else if(a>0&&a*2<=b) sum+=a*3; } else { if(b>0&&b*2<c) sum+=b*3; } printf("%d\n",sum); sum=0; } }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
0d70f92a54d57453d6764747f3db8711
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
/****************************************************************************** Online C Compiler. Code, Compile, Run and Debug C program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <stdio.h> int main(void) { int t,i,a,b,c,s; scanf("%d",&t); for(i=0;i<t;i++) { scanf("%d%d%d",&a,&b,&c); c=c/2; if(b-c<=0) { printf("%d\n",(b*2+b)); } else { s=(c*2+c); b=b-c; b=b/2; if(a-b<=0) { printf("%d\n",(a*2+a)+s); } else { printf("%d\n",s+(b*2+b)); } } } return 0; }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
725bb7b8b4f46c072437bdb4420fbf93
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include<stdio.h> #include<stdlib.h> int min(int x,int y) { if(x<y) return x; else return y; } int main() { int a,b,c,x,n,i,s; scanf("%d",&n); for(i=1;i<=n;i++) { s=0; scanf("%d%d%d",&a,&b,&c); x=min(b,c/2); s+=3*x; b-=x; x=min(a,b/2); s+=3*x; printf("%d\n",s); } }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
9a306185b51b3e1372e00de417b15f36
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include <stdio.h> int main() { int t,i,a,b,c,b1,b2,b3,s; scanf("%d", &t); for(i=0;i<t;i++) { s=0; scanf("%d %d %d", &a,&b,&c); while(b>=1&&c>=2) { b--; c-=2; s+=3; } while(a>=1&&b>=2) { a--; b-=2; s+=3; } printf("%d\n", s); } return 0; }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
bcf3fe346ced9c56fc07c8fdaeb48ae7
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include<stdio.h> int main() { int t, a, b, c, i; scanf("%d", &t); while(t--) { scanf("%d %d %d",&a, &b, &c); int s=0; for(i=0; ;i++) { if(b>=1 && c>=2) { s = s + 3; b = b-1; c = c-2; } else if(a>=1 && b>=2) { s = s + 3; a = a-1; b = b-2; } else {break;} } printf("%d\n", s); } }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
1479bf0a13845528b8b49b9efa5e2be2
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include <stdio.h> int main() { int q; scanf("%d",&q); while(q>0) { int a,b,c,stone=0; scanf("%d%d%d",&a,&b,&c); while(b>0&&c>1) { b--; c-=2; stone+=3; } while(a>0&&b>1) { a--; b-=2; stone+=3; } printf("%d\n",stone); q--; } return 0; }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
ada66a3f8760be7908e682be0601388b
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include<stdio.h> int main(){ int time,a,b,c; int x,y,z; scanf("%d",&time); for(int i=0;i<time;i++){ x=0;y=0;z=0; scanf("%d %d %d",&a,&b,&c); x=c/2; if(b<x){ z=z+3*b; printf("%d\n",z); }else if(b>=x){ z=z+3*x; b=b-x; y=b/2; if(a<y){ z=z+3*a; }else if(a>=y){ z=z+3*y; } printf("%d\n",z); } } }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
d6aea7740ec3743c6396e02e8751f4e3
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include<stdio.h> int main() { int x,a,b,c,p=0; scanf("%d",&x); while(x--) { scanf("%d %d %d",&a,&b,&c); while(b>0&&c>0) { if(b-1>=0&&c-2>=0) { p=p+3; b--; c=c-2; } else break; } while(a>0&&b>0) { if(a-1>=0&&b-2>=0) { p=p+3; a--; b=b-2; } else break; } printf("%d\n",p); p=0; } }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
9400b6e00229bd6c3a2a9b0793a65dbe
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include<stdio.h> int main() { int i,j[3],m,n,k,l,min=0,p; scanf("%d",&n); for(i=0;i<n;i++){ scanf("%d%d%d",&m,&k,&l); while(1){ if(k>=1 && l>=2){ min+=3; k=k-1; l=l-2; } else if(m>=1 && k>=2){ min+=3; m=m-1; k=k-2; } else break; } printf("%d\n",min); min=0; } return 0; }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
3d673ee277d08ea1fbe477420daf58d8
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include<stdio.h> int main(){ int t,i,a,b,c,count; scanf("%d",&t); for(i=1;i<=t;i++){ scanf("%d %d %d",&a,&b,&c); count=0; while(c>1&&b>0){ b--;c-=2;count+=3; } while(b>1&&a>0){ a--;b-=2;count+=3; } printf("%d\n",count); } return 0; }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
09d96d9c611e22b7dd32d84f2f71b9db
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include <stdio.h> int main() { int t,a,b,c,s; scanf("%d",&t); while(t--) { s=0; scanf("%d %d %d",&a,&b,&c); if(c/2>=b) { s=s+3*b; } else { s=s+3*(c/2); b=b-(c/2); if(b/2>=a) s=s+(3*a); else s=s+3*(b/2); } printf("%d\n",s); } return 0; }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
d2bdae072fc37b3d8602d1805d9c8857
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include<stdio.h> int main(){ long long int t,a,b,c,count=0,i; scanf("%lld",&t); for(i=0;i<t;i++) { scanf("%lld%lld%lld",&a,&b,&c); if(c==0) { while(a>0 && b>0) { a=a-1; b=b-2; count=count+3; } if(b<0 && count!=0) count=count-3; printf("%lld\n",count); } else{ while(b>0 && c>0) { b=b-1; c=c-2; count=count+3; } if(c<0 && count!=0){ count=count-3; b=b+1;} while(a>0 && b>0) { a=a-1; b=b-2; count=count+3; } if(b<0 && count!=0) count=count-3; printf("%lld\n",count); } // else // printf("%lld\n",count); count=0; } return 0; }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
eb653fbe4597c5e2deb522c58785b181
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include<stdio.h> int main() { int n; scanf("%d",&n); for(int i=0;i<n;i++) { int a,b,c,x,y; scanf("%d%d%d",&a,&b,&c); if(b==0) printf("0\n"); else if(c/2>=b) printf("%d\n",b*3); else { y=b-c/2; if(y/2<=a) { x=(c/2)*3+(y/2)*3; printf("%d\n",x); } else { x=(c/2)*3+a*3; printf("%d\n",x); } } } return 0; }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
b87d41377d29a6e54649fd438fec64ba
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include <stdio.h> #include <stdlib.h> int main() { int n, a[101], b[101], c[101], x, i; scanf("%d", &n); for(i=0; i<n; i++) { scanf("%d %d %d", &a[i], &b[i], &c[i]); } for(i=0; i<n; i++) { if((c[i]/2)>=b[i]) printf("%d\n", b[i]*3); else { x = b[i]-(c[i]/2); if((x/2)>=a[i]) printf("%d\n", (a[i]*3)+((c[i]/2)*3)); else printf("%d\n", ((x/2)*3)+((c[i]/2)*3)); } } }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
344ed3bd21d777e3e90d997c6535d049
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include <stdio.h> #define min(a,b) (a<b)?a:b; int main() { int t,a,b,c,cnt,mm; scanf("%d",&t); while(t--) { scanf("%d %d %d",&a,&b,&c); cnt=0; mm=min(b,c/2); if(mm>0) { cnt+=mm;b-=mm; } mm=min(a,b/2); if(mm>0) cnt+=mm; printf("%d\n",cnt*3); } return 0; }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
5e767c0abb65b7e20bd60d5e30ec5913
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include<stdio.h> int main() { int t,a,b,c,n,i,m,e,f,p,q; scanf("%d",&t); for(i=1; i<=t; i++) { m=0; n=0; scanf("%d %d %d",&a,&b,&c); while(b>=1&&c>=2){ m=m+3; b--; c=c-2; } while(a>=1&&b>=2){ n=n+3; a--; b=b-2; } e=m+n; printf("%d\n",e); } return 0; }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
7266664e38bfcf18b26bbdae602001cc
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include<stdio.h> int main() { int t; scanf("%d", &t); int i; int a, b, c; int ans; for (i = 0; i < t; i++) { scanf("%d %d %d", &a, &b, &c); ans = 0; if (2 * b <= c) { ans = 3 * b; b = 0; } else { ans = c / 2 * 3; b -= ans / 3; } if (2 * a <= b) ans += 3 * a; else ans += b / 2 * 3; printf("%d\n", ans); } return 0; }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
34aded60ddc26d32108ec495c2e475c7
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include <stdio.h> int main(void) { // your code goes here int a,b,c,t; scanf("%d",&t); while(t>0) { t--; scanf("%d",&a); scanf("%d",&b); scanf("%d",&c); int t=0; int rem1=b/2; int rem2=c/2; int b1=b; int s1=0; int s2=0; if(b==0) t=0; else { if(rem2<=b) { s1=s1+rem2*3; b=b-rem2; rem2=b/2; if(rem2<=a) { s1=s1+rem2*3; } else s1=s1+a*3; } else { s1=s1+b*3; } if(rem1<=a) { s2=s2+rem1*3; //a=a-rem1; if((b1-(rem1*2))>0) { if(c>=2) s2=s2+3; } } else { s2=s2+a*3; b1=b1-a*2; rem1=c/2; if(rem1<=b1) { s2=s2+rem1*3; } else s2=s2+b1*3; } } if(s1>=s2) printf("%d\n",s1); else printf("%d\n",s2); } return 0; }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
f89be47cba84882ccd0ff8b436661de0
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include <stdio.h> int main() { int a,b,c,t,i; int ara[200]; scanf("%d",&t); for(i = 0;i < t;i++){ scanf("%d %d %d",&a,&b,&c); ara[i] = 0; if(b > 0){ while(b >= 1 && c >= 2){ ara[i] = ara[i] + 3; b--; c = c - 2; } while(a >= 1 && b >= 2){ ara[i] = ara[i] + 3; a--; b = b - 2; } } } for(i = 0;i < t;i++){ printf("%d\n",ara[i]); } }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
bbe09394bfd0e1c61a287cdaf4bdac32
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include<stdio.h> int main() { int t,a,b,c,sum,j; scanf("%d",&t); for(j=0;j<t;j++) { scanf("%d%d%d",&a,&b,&c); sum=0; if(b==0) { printf("0\n"); } else { sum=0; if(b*2<=c) { sum=b*2+b; } else { c=c/2; b=b-c; sum=c*2+c; if(a>=1&&b>=2) { if(a*2<=b) { sum=sum+a*2+a; } else { b=b/2; sum=sum+(b*2)+b; } } else { sum=sum; } } printf("%d\n",sum); } } }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
fc82327eb1a3a9215c90383a80dad677
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include<stdio.h> int main() { int t;scanf("%d",&t); while(t--) { int a,b,c,ans=0;scanf("%d%d%d",&a,&b,&c); (b>c/2)?(ans+=c/2,b-=c/2):(ans+=b,b-=b); (a>b/2)?(ans+=b/2):(ans+=a); printf("%d\n",ans*3); } }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
7886a9ebef1a75ae6072afd6c6dcab4d
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include <stdio.h> int main(){ int nCasos; scanf("%d", &nCasos); int pa, pb, pc; for(int i = 0; i < nCasos; i++){ scanf("%d %d %d", &pa, &pb, &pc); int piedras = 0; if (pb == 0){ printf("0\n"); }else{ while((pc >= 2) && (pb > 0)){ pc -= 2; pb -= 1; piedras += 3; } while((pb >= 2) && (pa >= 1)){ pb -= 2; pa -= 1; piedras += 3; } printf("%d\n", piedras); } } return 0; }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
686b844271006568fb4b2a0e919d2cb8
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include <stdio.h> int main() { int a,b,c,ans,t; scanf("%d", &t); while(t--){ ans=0; scanf("%d %d %d", &a, &b, &c); while(b>=1 && c>=2){ b-=1; c-=2; ans+=3; } while(a>=1 && b>=2){ a-=1; b-=2; ans+=3; } printf("%d\n", ans); } return 0; }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
9bc4dedb7ea08af36fe6e8736d1f996a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include<stdio.h> int main () { int tc,a,b,c,avg; scanf("%d",&tc); while(tc--) { scanf("%d %d %d",&a,&b,&c); avg=0; while(b>0 && c>1) { b-=1; c-=2; avg+=3; } while(a>0 && b>1) { a-=1; b-=2; avg+=3; } printf("%d\n",avg); } return 0; }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
b78ee45f247db528dd3bab2ba30c3daf
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include<stdio.h> int main() { int a,b,c,i,t,j; scanf("%d",&t); for(j=1;j<=t;j=j+1) { scanf("%d %d %d",&a,&b,&c); int count=0,result=0; for(i=1;i!=0;i=i+1) { if(b>=1 && c>=2) { b=b-1; c=c-2; count=count+3; } else { break; } } for(i=1;i!=0;i=i+1) { if(b>=2 && a>=1) { a=a-1; b=b-2; count=count+3; } else { break; } } for(i=1;i!=0;i=i+1) { if(b>=2 && a>=1) { b=b-2; a=a-1; result=result+3; } else { break; } } for(i=1;i!=0;i=i+1) { if(b>=1 && c>=2) { c=c-2; b=b-1; result=result+3; } else { break; } } if(result>=count) { printf("%d\n",result); } else { printf("%d\n",count); } } }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
ae4cec7fac732ad2b80ec9167afce594
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include<stdio.h> #include<conio.h> #include<math.h> int min(int a, int b) { if(a<b) { return a;} else { return b;} } int main() { int t,i,a,b,c,count=0,temp1,temp2,temp3,max; scanf("%d",&t); for(i=0;i<t;i++) { count=0; max=0; scanf("%d %d %d",&a,&b,&c); int ans=0; ans+=3*min(b,c/2); b-=min(b,c/2); c-=2*min(b,c/2); ans+=3*min(a,b/2); printf("%d\n", ans); } return 0; }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
b8ac56d8c48eb08a853f8214086180f0
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include <stdio.h> #include <stdlib.h> int main() { int n,a,b,c; int count[100]; scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d %d %d",&a,&b,&c); count[i-1]=0; while(b-1>=0 && c-2>=0){ b-=1; c-=2; count[i-1]+=3; } while(a-1>=0 && b-2>=0){ a-=1; b-=2; count[i-1]+=3; } } for(int i=1;i<=n;i++)printf("%d\n",count[i-1]); return 0; }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
57adc729214f43fd6a6a13c68825a5c3
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include<stdio.h> int main() { int a,b,c,k=0,v=0,n; scanf("%d",&n); while(v<n) { scanf("%d %d %d",&a,&b,&c); while(1) { if((b>=1)&&(c>=2)) { b=b-1; c=c-2; k++; } else if((a>=1)&&(b>=2)) { a=a-1; b=b-2; k++; } else break; } printf("%d\n",k*3); k=0; v++; } return 0; }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
34815ca561095e6f32730753ce182710
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include<stdio.h> int main() { int t; scanf("%d",&t); while(t--) { int a,b,c,k=0; scanf("%d%d%d",&a,&b,&c); for(;b>=1&&c>=2;) { k+=3;; b=b-1; c=c-2; } for(;a>=1&&b>=2;) { k+=3; a=a-1; b=b-2; } printf("%d\n",k); } }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
cbb8360db463dd83b90951cbc34da611
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include<stdio.h> void main() { int t,a,b,c; scanf("%d",&t); while(t--) { int s=0; scanf("%d%d%d",&a,&b,&c); while(b>0) { c=c-2; if(c<0) break; else { b--; s=s+3;} } while(b>0 && a>0) { a--; b=b-2; if(b<0) break; else s=s+3; } printf("%d\n",s); } }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
82816a701fc148decdaee189360155f4
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include<stdio.h> int main() { int t; scanf("%d",&t); while(t>0){ int a,b,c,d,sum =0; scanf("%d %d %d",&a,&b,&c); d = b; for(int i=0;i<d;i++){ if(b>0 && c>=2){ sum++; b = b-1; c = c - 2; } else if(a>0 && b>=2){ sum++; a = a-1; b = b-2; } } printf("%d\n",sum*3); t--; } return 0; }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
d90f206f959b6be96e7520abcb66ed74
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include<stdio.h> int main(){ int tcases; scanf("%d", &tcases); while(tcases--){ int a, b, c; scanf("%d %d %d", &a, &b, &c); int ans = 0; int i, j; for(i = 0;i <= 100;i++)for(j = 0;j <= 100;j++)if(i <= a && 2*i + j <= b && 2*j <= c){ if(ans < 3*(i + j)) ans = 3*(i + j); } printf("%d\n", ans); } return 0; }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
f2ed5e9dce11688ff7e29e17b4440878
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include <stdio.h> int main(){ int t, a, b, c, s; scanf("%d", &t); for(int i = 0; i < t ; i++){ scanf("%d%d%d", &a, &b, &c); s = 0; while(b > 0 && c > 1){ b--; c -= 2; s += 3; } while(a > 0 && b > 1){ a--; b -= 2; s += 3; } printf("%d\n", s); } }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
36ecf12ffe7555c85d00bdb157000fb9
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include<stdio.h> int main(){ int time,a,b,c; int x,y,z; scanf("%d",&time); for(int i=0;i<time;i++){ x=0;y=0;z=0; scanf("%d %d %d",&a,&b,&c); x=c/2; if(b<x){ z=z+3*b; printf("%d\n",z); }else if(b>=x){ z=z+3*x; b=b-x; y=b/2; if(a<y){ z=z+3*a; }else if(a>=y){ z=z+3*y; } printf("%d\n",z); } } }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
ceadc1d0cf06fb236e1d02f0925ec7e7
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include<stdio.h> int main(){ int t,x,y,z; scanf("%d", &t); while(t--){ int s=0; scanf("%d%d%d", &x, &y, &z); while(y>=1 && z>=2){ s+=3; y=y-1; z=z-2; } while(y>=2 && x>=1){ s+=3; y=y-2; x=x-1; } printf("%d\n", s); } }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
73f6c6e98ffe596cfc741e34ecba74b8
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include <stdio.h> int main() { int n; int a,b,c,s=0,temp; scanf ("%d",&n); while (n--) { s=0; scanf ("%d %d %d",&a,&b,&c); if (b>0 && c>1) { temp=c/2; //printf ("%d \n",temp); if (temp>=b) { s+=b*3; c-=b*2; b=0; } else { s+=temp*3; c-=temp*2; b-=temp; } } if (a>0 && b>1) { temp=b/2; if (temp>=a) { s+=a*3; b-=a*2; a=0; } else { s+=temp*3; b-=temp*2; a-=temp; } } printf ("%d\n",s); } }
Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations: take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones); take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?
Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer Β β€” the maximum possible number of stones that Alice can take after making some operations.
C
14fccd50d5dfb557dd53f2896ed844c3
89a19870656ac4b3641f63c15fe19469
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "brute force" ]
1571319300
["3\n3 4 5\n1 0 5\n5 3 2"]
NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$) Β β€” the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$)Β β€” the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.
["9\n0\n6"]
#include<stdio.h> #include<stdlib.h> #include<math.h> int main() { int t; scanf("%d",&t); for(int i=0;i<t;i++) { int a,b,c;int sum=0; scanf("%d%d%d",&a,&b,&c); c=c/2; if(b<=c) { sum=b*3; } else{ sum=c*3; b=b-c; b=b/2; if(a<b) { sum=sum+a*3; } else{ sum=sum+b*3; } } printf("%d\n",sum); } }
Today Adilbek is taking his probability theory test. Unfortunately, when Adilbek arrived at the university, there had already been a long queue of students wanting to take the same test. Adilbek has estimated that he will be able to start the test only $$$T$$$ seconds after coming. Fortunately, Adilbek can spend time without revising any boring theorems or formulas. He has an app on this smartphone which contains $$$n$$$ Japanese crosswords to solve. Adilbek has decided to solve them all one by one in the order they are listed in the app, without skipping any crossword. For each crossword, a number $$$t_i$$$ is given that represents the time it takes an average crossword expert to solve this crossword (the time is given in seconds).Adilbek is a true crossword expert, but, unfortunately, he is sometimes unlucky in choosing the way to solve the crossword. So, it takes him either $$$t_i$$$ seconds or $$$t_i + 1$$$ seconds to solve the $$$i$$$-th crossword, equiprobably (with probability $$$\frac{1}{2}$$$ he solves the crossword in exactly $$$t_i$$$ seconds, and with probability $$$\frac{1}{2}$$$ he has to spend an additional second to finish the crossword). All these events are independent.After $$$T$$$ seconds pass (or after solving the last crossword, if he manages to do it in less than $$$T$$$ seconds), Adilbek closes the app (if he finishes some crossword at the same moment, that crossword is considered solved; otherwise Adilbek does not finish solving the current crossword at all). He thinks it would be an interesting probability theory problem to calculate $$$E$$$ β€” the expected number of crosswords he will be able to solve completely. Can you calculate it? Recall that the expected value of a discrete random variable is the probability-weighted average of all possible values β€” in this problem it means that the expected value of the number of solved crosswords can be calculated as $$$E = \sum \limits_{i = 0}^{n} i p_i$$$, where $$$p_i$$$ is the probability that Adilbek will solve exactly $$$i$$$ crosswords. We can represent $$$E$$$ as rational fraction $$$\frac{P}{Q}$$$ with $$$Q &gt; 0$$$. To give the answer, you should print $$$P \cdot Q^{-1} \bmod (10^9 + 7)$$$.
Print one integer β€” the expected value of the number of crosswords Adilbek solves in $$$T$$$ seconds, expressed in the form of $$$P \cdot Q^{-1} \bmod (10^9 + 7)$$$.
C
a44cba5685500b16e24b8fba30451bc5
a5953a3aa804a10717965b2444b49604
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "dp", "combinatorics", "two pointers", "number theory", "probabilities" ]
1563115500
["3 5\n2 2 2", "3 5\n2 1 2"]
NoteThe answer for the first sample is equal to $$$\frac{14}{8}$$$.The answer for the second sample is equal to $$$\frac{17}{8}$$$.
PASSED
2,400
standard input
2 seconds
The first line contains two integers $$$n$$$ and $$$T$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le T \le 2 \cdot 10^{14}$$$) β€” the number of crosswords and the time Adilbek has to spend, respectively. The second line contains $$$n$$$ integers $$$t_1, t_2, \dots, t_n$$$ ($$$1 \le t_i \le 10^9$$$), where $$$t_i$$$ is the time it takes a crossword expert to solve the $$$i$$$-th crossword. Note that Adilbek solves the crosswords in the order they are given in the input without skipping any of them.
["750000007", "125000003"]
#include <stdio.h> #define N 200000 #define MD 1000000007 #define INV2 ((MD + 1) / 2) int d_, x_, y_; void gcd_(int a, int b) { if (b == 0) d_ = a, x_ = 1, y_ = 0; else { int tmp; gcd_(b, a % b); tmp = x_ - a / b * y_, x_ = y_, y_ = tmp; } } int inv(int a) { gcd_(a, MD); return x_; } int ff[N + 1], gg[N + 1]; void init() { int i, f; f = 1; for (i = 0; i <= N; i++) { gg[i] = inv(ff[i] = f); f = (long long) f * (i + 1) % MD; } } int choose(int n, int k) { return (long long) ff[n] * gg[k] % MD * gg[n - k] % MD; } int main() { int n, k, ans; long long s, x, p; init(); scanf("%d%lld", &n, &s); ans = 0, x = 1, p = 1; for (k = 1; k <= n; k++) { int t; long long s_; scanf("%d", &t); if ((s_ = s - t) < 0) break; x = (x * 2 - (k - 1 >= s ? choose(k - 1, s) : 0)) % MD; if (s_ < k) { if (s > k) s = k; while (s > s_) x = (x - choose(k, s--)) % MD; } else s = s_; ans = (ans + x * (p = p * INV2 % MD)) % MD; } if (ans < 0) ans += MD; printf("%d\n", ans); return 0; }
Today Adilbek is taking his probability theory test. Unfortunately, when Adilbek arrived at the university, there had already been a long queue of students wanting to take the same test. Adilbek has estimated that he will be able to start the test only $$$T$$$ seconds after coming. Fortunately, Adilbek can spend time without revising any boring theorems or formulas. He has an app on this smartphone which contains $$$n$$$ Japanese crosswords to solve. Adilbek has decided to solve them all one by one in the order they are listed in the app, without skipping any crossword. For each crossword, a number $$$t_i$$$ is given that represents the time it takes an average crossword expert to solve this crossword (the time is given in seconds).Adilbek is a true crossword expert, but, unfortunately, he is sometimes unlucky in choosing the way to solve the crossword. So, it takes him either $$$t_i$$$ seconds or $$$t_i + 1$$$ seconds to solve the $$$i$$$-th crossword, equiprobably (with probability $$$\frac{1}{2}$$$ he solves the crossword in exactly $$$t_i$$$ seconds, and with probability $$$\frac{1}{2}$$$ he has to spend an additional second to finish the crossword). All these events are independent.After $$$T$$$ seconds pass (or after solving the last crossword, if he manages to do it in less than $$$T$$$ seconds), Adilbek closes the app (if he finishes some crossword at the same moment, that crossword is considered solved; otherwise Adilbek does not finish solving the current crossword at all). He thinks it would be an interesting probability theory problem to calculate $$$E$$$ β€” the expected number of crosswords he will be able to solve completely. Can you calculate it? Recall that the expected value of a discrete random variable is the probability-weighted average of all possible values β€” in this problem it means that the expected value of the number of solved crosswords can be calculated as $$$E = \sum \limits_{i = 0}^{n} i p_i$$$, where $$$p_i$$$ is the probability that Adilbek will solve exactly $$$i$$$ crosswords. We can represent $$$E$$$ as rational fraction $$$\frac{P}{Q}$$$ with $$$Q &gt; 0$$$. To give the answer, you should print $$$P \cdot Q^{-1} \bmod (10^9 + 7)$$$.
Print one integer β€” the expected value of the number of crosswords Adilbek solves in $$$T$$$ seconds, expressed in the form of $$$P \cdot Q^{-1} \bmod (10^9 + 7)$$$.
C
a44cba5685500b16e24b8fba30451bc5
a2a888fe9054f4508f4796e442503a8b
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "dp", "combinatorics", "two pointers", "number theory", "probabilities" ]
1563115500
["3 5\n2 2 2", "3 5\n2 1 2"]
NoteThe answer for the first sample is equal to $$$\frac{14}{8}$$$.The answer for the second sample is equal to $$$\frac{17}{8}$$$.
PASSED
2,400
standard input
2 seconds
The first line contains two integers $$$n$$$ and $$$T$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le T \le 2 \cdot 10^{14}$$$) β€” the number of crosswords and the time Adilbek has to spend, respectively. The second line contains $$$n$$$ integers $$$t_1, t_2, \dots, t_n$$$ ($$$1 \le t_i \le 10^9$$$), where $$$t_i$$$ is the time it takes a crossword expert to solve the $$$i$$$-th crossword. Note that Adilbek solves the crosswords in the order they are given in the input without skipping any of them.
["750000007", "125000003"]
#include<stdio.h> #include<stdlib.h> #include<stdint.h> #include<inttypes.h> typedef int64_t i64; typedef int32_t i32; static void print_int(i64 n){if(n<0){putchar('-');n=-n;}if(n==0){putchar('0');return;}int s[20],len=0;while(n>0){s[len++]=n%10+'0';n/=10;}while(len>0){putchar(s[--len]);}} static i64 read_int(void){int prev='\0';int c=getchar();while(!('0'<=c && c<='9')){prev=c;c=getchar();}i64 res=0;while('0'<=c && c<='9'){res=10*res+c-'0';c=getchar();}return prev=='-'?-res:res;} const i32 mod = 1000000007; i32 mod_pow (i32 r, i32 n) { i32 t = 1; i32 s = r; while (n > 0) { if (n & 1) t = (i64) t * s % mod; s = (i64) s * s % mod; n >>= 1; } return t; } i32 inv (i32 a) { return mod_pow (a, mod - 2); } i32 *FACT = NULL; i32 *I_FACT = NULL; i32 FACT_SIZE = -1; void init_fact (const i32 n) { if (FACT != NULL) { free (FACT); free (I_FACT); } FACT_SIZE = n; FACT = (i32 *) calloc (n + 1, sizeof (i32)); FACT[0] = 1; for (i32 i = 1; i <= n; ++i) { FACT[i] = (i64) i * FACT[i - 1] % mod; } I_FACT = (i32 *) calloc (n + 1, sizeof (i32)); I_FACT[n] = inv (FACT[n]); for (i32 i = n - 1; i >= 0; --i) { I_FACT[i] = (i64) (i + 1) * I_FACT[i + 1] % mod; } } i32 comb (i32 n, i32 k) { if (!(0 <= k && k <= n)) return 0; return (i64) FACT[n] * I_FACT[k] % mod * I_FACT[n - k] % mod; } void run (void) { i32 n = read_int(); i64 t = read_int(); init_fact (n); i64 ans = 0; i64 sum = 0; i64 remain = 1; i64 right = 1; i32 k = 0; for (i32 i = 1; i <= n; ++i) { sum += read_int(); ++k; right = inv (2) * right % mod; while (k >= 0 && sum + k > t) { remain = (remain + mod - right) % mod; k--; right = (i64) comb (i, k) * mod_pow (inv (2), i) % mod; } if (k < 0) break; ans += remain; } ans %= mod; print_int (ans); puts (""); } int main (void) { run (); return 0; }
The little girl loves the problems on array queries very much.One day she came across a rather well-known problem: you've got an array of $$$n$$$ elements (the elements of the array are indexed starting from 1); also, there are $$$q$$$ queries, each one is defined by a pair of integers $$$l_i$$$, $$$r_i$$$ $$$(1 \le l_i \le r_i \le n)$$$. You need to find for each query the sum of elements of the array with indexes from $$$l_i$$$ to $$$r_i$$$, inclusive.The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum.
In a single line print, a single integer β€” the maximum sum of query replies after the array elements are reordered. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
926ec28d1c80e7cbe0bb6d209e664f48
acf46322bde10a4d964b268f3a80e4f4
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "data structures", "implementation", "sortings", "greedy" ]
1361719800
["3 3\n5 3 2\n1 2\n2 3\n1 3", "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3"]
null
PASSED
1,500
standard input
1 second
The first line contains two space-separated integers $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) and $$$q$$$ ($$$1 \le q \le 2\cdot10^5$$$) β€” the number of elements in the array and the number of queries, correspondingly. The next line contains $$$n$$$ space-separated integers $$$a_i$$$ ($$$1 \le a_i \le 2\cdot10^5$$$) β€” the array elements. Each of the following $$$q$$$ lines contains two space-separated integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le n$$$) β€” the $$$i$$$-th query.
["25", "33"]
#include <stdio.h> #include <math.h> void merge(int a[],int l,int m,int r) { int l_n = m-l+1; int r_n = r-m; int L[l_n],R[r_n]; for(int i=0;i<l_n;i++) { L[i]=a[l+i]; } for(int i=0;i<r_n;i++) { R[i]=a[m+1+i]; } int i=0,j=0,k=l; while(i<l_n && j<r_n) { if(L[i]<R[j]) { a[k]=L[i]; i++; } else { a[k]=R[j]; j++; } k++; } while(i<l_n) { a[k]=L[i]; i++; k++; } while(j<r_n) { a[k]=R[j]; j++; k++; } } void mergesort(int a[],int l,int r) { if(l<r) { int m = l + (r-l)/2; mergesort(a,l,m); mergesort(a,m+1,r); merge(a,l,m,r); } } int main() { int n,q; scanf("%d%d",&n,&q); int a[n]; int cumulative[n]; for(int i=0;i<n;i++) { scanf("%lld",&a[i]); cumulative[i]=0; } for(int i=0;i<q;i++) { int l,r; scanf("%d%d",&l,&r); cumulative[l-1]++; cumulative[r]--; } for(int i=1;i<n;i++) { cumulative[i]+=cumulative[i-1]; } mergesort(a,0,n-1); mergesort(cumulative,0,n-1); long long int sum = 0; for(int i=0;i<n;i++) { sum+=(long long)a[i]*cumulative[i]; } printf("%lld",sum); }
The little girl loves the problems on array queries very much.One day she came across a rather well-known problem: you've got an array of $$$n$$$ elements (the elements of the array are indexed starting from 1); also, there are $$$q$$$ queries, each one is defined by a pair of integers $$$l_i$$$, $$$r_i$$$ $$$(1 \le l_i \le r_i \le n)$$$. You need to find for each query the sum of elements of the array with indexes from $$$l_i$$$ to $$$r_i$$$, inclusive.The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum.
In a single line print, a single integer β€” the maximum sum of query replies after the array elements are reordered. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
926ec28d1c80e7cbe0bb6d209e664f48
c6865f156ffedb1cc0b95197966594fb
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "data structures", "implementation", "sortings", "greedy" ]
1361719800
["3 3\n5 3 2\n1 2\n2 3\n1 3", "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3"]
null
PASSED
1,500
standard input
1 second
The first line contains two space-separated integers $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) and $$$q$$$ ($$$1 \le q \le 2\cdot10^5$$$) β€” the number of elements in the array and the number of queries, correspondingly. The next line contains $$$n$$$ space-separated integers $$$a_i$$$ ($$$1 \le a_i \le 2\cdot10^5$$$) β€” the array elements. Each of the following $$$q$$$ lines contains two space-separated integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le n$$$) β€” the $$$i$$$-th query.
["25", "33"]
/* AUTHOR:AKASH JAIN * USERNAME:akash19jain * DATE:17/10/2019 */ // #include<algorithm> // #include <bits/stdc++.h> // using namespace std; #include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> #include<stdbool.h> #include<ctype.h> #define SC1(x) scanf("%lld",&x) #define SC2(x,y) scanf("%lld%lld",&x,&y) #define SC3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z) #define SCS(x) scanf("\n%s", x) #define PF1(x) printf("%lld\n",x) #define PF2(x,y) printf("%lld %lld\n",x,y) #define PF3(x,y,z) printf("%lld %lld %lld\n",x,y,z) #define PFN printf("\n") #define REP(i,n) for(long long i=0;i<(n);i++) #define FOR(i,a,b) for(long long i=(a);i<=(b);i++) #define FORD(i,a,b) for(long long i=(a);i>=(b);i--) #define WHILE(n) while(n--) #define MEM(a, b) memset(a, (b), sizeof(a)) #define ITOC(c) ((char)(((ll)'0')+c)) #define MID(s,e) (s+(e-s)/2) #define SZ(a) strlen(a) #define MOD 1000000007 #define MAX 10000000005 #define MIN -10000000005 #define PI 3.1415926535897932384626433832795 #define DEB(x) printf("The value of \"%s\" is: %d\n",#x,x) #define CASES ll t;SC1(t);while(t--) #define ABS(a) ((a>0)?a:-(a)) #define SWAP(a,b) ll z=a;a=b;b=z #define SWAPC(a,b) char z=a;a=b;b=z const int INF = 1<<29; typedef long long ll; typedef unsigned long long ull; #define FILEIO(name) \ freopen(name".in", "r", stdin); \ freopen(name".out", "w", stdout); int cmp(const void * a,const void * b); long long maxv(long long a,long long b); long long minv(long long a,long long b); long long gcd(long long u,long long v); long long digits(long long n); bool isPoweroftwo(long long n); int main() { ll n,q; SC2(n,q); ll arr[n]; REP(i,n) SC1(arr[i]); qsort(arr,n,sizeof(arr[0]),cmp); ll val[n]; MEM(val,0); REP(i,q) { ll l,r; SC2(l,r); l--; r--; val[l]++; if(r<n-1) val[r+1]--; } ll b[n]; MEM(b,0); ll c=0; REP(i,n) { c+=val[i]; b[i]=c; } qsort(b,n,sizeof(b[0]),cmp); ll ans=0; REP(i,n) { ans+=b[i]*arr[i]; } PF1(ans); return 0; } //qsort(arr,n,sizeof(arr[0]),cmp); int cmp (const void * a, const void * b) { if( *(ll*)a - *(ll*)b < 0 ) return -1; if( *(ll*)a - *(ll*)b > 0 ) return 1; return 0; } long long maxv(long long a,long long b) { if(a>b) return a; return b; } long long minv(long long a,long long b) { if(a<b) return a; return b; } long long gcd(long long u,long long v) { if (v == 0) return u; return gcd(v, u%v); } long long digits(long long n) //to calculate no of digits in a number { return floor(log10(n))+1; } bool isPoweroftwo(long long x) { return x && (!(x&(x-1))); }
The little girl loves the problems on array queries very much.One day she came across a rather well-known problem: you've got an array of $$$n$$$ elements (the elements of the array are indexed starting from 1); also, there are $$$q$$$ queries, each one is defined by a pair of integers $$$l_i$$$, $$$r_i$$$ $$$(1 \le l_i \le r_i \le n)$$$. You need to find for each query the sum of elements of the array with indexes from $$$l_i$$$ to $$$r_i$$$, inclusive.The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum.
In a single line print, a single integer β€” the maximum sum of query replies after the array elements are reordered. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
926ec28d1c80e7cbe0bb6d209e664f48
8e529de5fc8b5e0bb390486bf6d3f5df
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "data structures", "implementation", "sortings", "greedy" ]
1361719800
["3 3\n5 3 2\n1 2\n2 3\n1 3", "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3"]
null
PASSED
1,500
standard input
1 second
The first line contains two space-separated integers $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) and $$$q$$$ ($$$1 \le q \le 2\cdot10^5$$$) β€” the number of elements in the array and the number of queries, correspondingly. The next line contains $$$n$$$ space-separated integers $$$a_i$$$ ($$$1 \le a_i \le 2\cdot10^5$$$) β€” the array elements. Each of the following $$$q$$$ lines contains two space-separated integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le n$$$) β€” the $$$i$$$-th query.
["25", "33"]
#include <stdio.h> #include<string.h> #include<stdlib.h> long long int max(long long int a,long long int b){ if(a>b){ return a; } return b; } long long int cmp(const void *a,const void *b){ return *(long long int *)b-*(long long int*)a; } int main() { long long int i,j,test,k,m,l,r,flag=0,max=0,n,m1,m2,x,sum=0,ans=0,count, a[1000000]={0},b[1000000]={0}; scanf("%lld%lld",&n,&m); b[0]=0; for(i=0;i<n;i++){ scanf("%lld",&a[i]); } sum=0; for(i=0;i<m;i++){ scanf("%lld%lld",&l,&r); b[l-1]++; b[r]--; } for(i=0;i<n;i++){ b[i+1]+=b[i]; } qsort(a,n,sizeof(long long int),cmp); qsort(b,n,sizeof(long long int),cmp); sum=0; for(i=0;i<n;i++){ sum+=a[i]*b[i]; } printf("%lld",sum); return 0; }
The little girl loves the problems on array queries very much.One day she came across a rather well-known problem: you've got an array of $$$n$$$ elements (the elements of the array are indexed starting from 1); also, there are $$$q$$$ queries, each one is defined by a pair of integers $$$l_i$$$, $$$r_i$$$ $$$(1 \le l_i \le r_i \le n)$$$. You need to find for each query the sum of elements of the array with indexes from $$$l_i$$$ to $$$r_i$$$, inclusive.The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum.
In a single line print, a single integer β€” the maximum sum of query replies after the array elements are reordered. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
926ec28d1c80e7cbe0bb6d209e664f48
5c08bb66f0e7d25027302276f5582756
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "data structures", "implementation", "sortings", "greedy" ]
1361719800
["3 3\n5 3 2\n1 2\n2 3\n1 3", "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3"]
null
PASSED
1,500
standard input
1 second
The first line contains two space-separated integers $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) and $$$q$$$ ($$$1 \le q \le 2\cdot10^5$$$) β€” the number of elements in the array and the number of queries, correspondingly. The next line contains $$$n$$$ space-separated integers $$$a_i$$$ ($$$1 \le a_i \le 2\cdot10^5$$$) β€” the array elements. Each of the following $$$q$$$ lines contains two space-separated integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le n$$$) β€” the $$$i$$$-th query.
["25", "33"]
#include<stdio.h> #include<stdlib.h> long long int ele[400009]; long long int trick[400009]={0},b[400009]; int cmp(const void *a,const void *b){ long long int res = (*(long long int *)a - *(long long int *)b); if(res > 0){ return 1; } else if (res == 0){ return 0; } else{ return -1; } } int main(){ long long int n,q; scanf("%I64d %I64d",&n,&q); long long int i; ele[0] =-999999; b[0] = -999999; for(i = 1 ; i <= n ; i++) scanf("%I64d",&ele[i]); i = 1; while(i <= q){ long long int l,r; scanf("%I64d %I64d",&l,&r); trick[l]++; if(r < n ) trick[r+1]--; i++; } long long int freq = 0; for(i = 1 ; i <= n ; i++){ freq += trick[i]; b[i] = freq; } qsort(ele,n+1,sizeof(long long int),cmp); qsort(b,n+1,sizeof(long long int),cmp); long long int res = 0; for(i = 1 ; i <= n ; i++){ res += ele[i]*b[i]; } printf("%I64d\n",res); return 0; }
The little girl loves the problems on array queries very much.One day she came across a rather well-known problem: you've got an array of $$$n$$$ elements (the elements of the array are indexed starting from 1); also, there are $$$q$$$ queries, each one is defined by a pair of integers $$$l_i$$$, $$$r_i$$$ $$$(1 \le l_i \le r_i \le n)$$$. You need to find for each query the sum of elements of the array with indexes from $$$l_i$$$ to $$$r_i$$$, inclusive.The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum.
In a single line print, a single integer β€” the maximum sum of query replies after the array elements are reordered. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
926ec28d1c80e7cbe0bb6d209e664f48
69153bc6ec274ad0cded237bce888bd0
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "data structures", "implementation", "sortings", "greedy" ]
1361719800
["3 3\n5 3 2\n1 2\n2 3\n1 3", "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3"]
null
PASSED
1,500
standard input
1 second
The first line contains two space-separated integers $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) and $$$q$$$ ($$$1 \le q \le 2\cdot10^5$$$) β€” the number of elements in the array and the number of queries, correspondingly. The next line contains $$$n$$$ space-separated integers $$$a_i$$$ ($$$1 \le a_i \le 2\cdot10^5$$$) β€” the array elements. Each of the following $$$q$$$ lines contains two space-separated integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le n$$$) β€” the $$$i$$$-th query.
["25", "33"]
#include <stdio.h> #include <stdlib.h> #include <string.h> #define SZ 200010 typedef unsigned long long num; num getnum() { char c=getchar(); int flag=0; num v = 0; while(c < '0' || c > '9') { if(c == '-') flag = 1; c = getchar(); } while(c >= '0' && c <= '9') v = v * 10 + (c - '0'), c = getchar(); return flag? -v: v; }; int range[SZ], vals[SZ]; int cmp(const void* a, const void* b) { int va = *(const int*) a; int vb = *(const int*) b; return (va < vb) - (va > vb); } int main() { num i, acc, n = getnum(), q = getnum(); for(i = 0; i < n; i++) vals[i] = getnum(); qsort(vals, n, sizeof(int), cmp); for(i = 0; i < q; i++) { num left = getnum()-1, right = getnum(); range[left]++; range[right]--; } for(i = 0, acc = 0; i < n; i++) range[i] = (acc += range[i]); qsort(range, n, sizeof(int), cmp); num ans = 0; for(i = 0; i < n; i++) ans += range[i] * 1ll * vals[i]; printf("%I64d\n", ans); }
The little girl loves the problems on array queries very much.One day she came across a rather well-known problem: you've got an array of $$$n$$$ elements (the elements of the array are indexed starting from 1); also, there are $$$q$$$ queries, each one is defined by a pair of integers $$$l_i$$$, $$$r_i$$$ $$$(1 \le l_i \le r_i \le n)$$$. You need to find for each query the sum of elements of the array with indexes from $$$l_i$$$ to $$$r_i$$$, inclusive.The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum.
In a single line print, a single integer β€” the maximum sum of query replies after the array elements are reordered. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
926ec28d1c80e7cbe0bb6d209e664f48
0a808e75bbe2a8e39638c5121be47ec3
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "data structures", "implementation", "sortings", "greedy" ]
1361719800
["3 3\n5 3 2\n1 2\n2 3\n1 3", "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3"]
null
PASSED
1,500
standard input
1 second
The first line contains two space-separated integers $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) and $$$q$$$ ($$$1 \le q \le 2\cdot10^5$$$) β€” the number of elements in the array and the number of queries, correspondingly. The next line contains $$$n$$$ space-separated integers $$$a_i$$$ ($$$1 \le a_i \le 2\cdot10^5$$$) β€” the array elements. Each of the following $$$q$$$ lines contains two space-separated integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le n$$$) β€” the $$$i$$$-th query.
["25", "33"]
// we will keep track on how many times each element was queried // then we sort both numbers array and "count" array and just "distribute" numbers so bigger ones are more frequently queried #define __STDC_FORMAT_MACROS #include <inttypes.h> #include <stdio.h> #include <stdlib.h> static inline int64_t fenwick_sum(int n, int64_t tree[static n], int64_t idx) { int ret = 0; while(idx >= 1) { ret += tree[idx]; idx -= idx & -idx; } return ret; } static inline void fenwick_add(int n, int64_t tree[static n], int idx, int64_t x) { while(idx <= n) { tree[idx] += x; idx += idx & -idx; } } static inline void fenwick_add_range(int n, int64_t tree[static n], int l, int r, int64_t x) { fenwick_add(n, tree, l, x); fenwick_add(n, tree, r+1, -x); } // adding x to [l,r] and query elem i afterwards is same as // adding x to f[l], substracting x from f[r+1] query sumf(i) #define MAX_N 200000 static int _a[MAX_N] = {}, _f[MAX_N] = {}; static int64_t _fenwick[MAX_N+1] = {}; static int compare_int(const void* a, const void* b) { return *(const int*)a - *(const int*)b; } int main() { int N,Q; scanf("%d %d\n", &N,&Q); for(int i = 0 ; i < N ; ++i) scanf("%d ", &_a[i]); for(int i = 0 ; i < Q ; ++i) { int l,r; scanf("%d %d\n", &l,&r); fenwick_add_range(N, _fenwick, l, r, 1); } for(int i = 0 ; i < N ; ++i) _f[i] = fenwick_sum(N, _fenwick, i+1); qsort(_a,N,sizeof(int),compare_int); qsort(_f,N,sizeof(int),compare_int); int64_t sum = 0; for(int i = 0 ; i < N ; ++i) sum += (int64_t)_a[i] * (int64_t)_f[i]; printf("%" PRId64 "\n", sum); return 0; }
The little girl loves the problems on array queries very much.One day she came across a rather well-known problem: you've got an array of $$$n$$$ elements (the elements of the array are indexed starting from 1); also, there are $$$q$$$ queries, each one is defined by a pair of integers $$$l_i$$$, $$$r_i$$$ $$$(1 \le l_i \le r_i \le n)$$$. You need to find for each query the sum of elements of the array with indexes from $$$l_i$$$ to $$$r_i$$$, inclusive.The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum.
In a single line print, a single integer β€” the maximum sum of query replies after the array elements are reordered. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
926ec28d1c80e7cbe0bb6d209e664f48
bf6b17a8de7ee76b5af70f24150a9b25
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "data structures", "implementation", "sortings", "greedy" ]
1361719800
["3 3\n5 3 2\n1 2\n2 3\n1 3", "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3"]
null
PASSED
1,500
standard input
1 second
The first line contains two space-separated integers $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) and $$$q$$$ ($$$1 \le q \le 2\cdot10^5$$$) β€” the number of elements in the array and the number of queries, correspondingly. The next line contains $$$n$$$ space-separated integers $$$a_i$$$ ($$$1 \le a_i \le 2\cdot10^5$$$) β€” the array elements. Each of the following $$$q$$$ lines contains two space-separated integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le n$$$) β€” the $$$i$$$-th query.
["25", "33"]
#include <stdio.h> #include <stdlib.h> #define MAXN 234567 int arr[MAXN], reps[MAXN]; int sort(const void *a, const void *b) { return *(int *) b - *(int *) a; } int main() { int n, q, i; scanf("%d%d", &n, &q); for (i = 0; i < n; i++) { scanf("%d", arr+i); } for (i = 0; i < q; i++) { int l, r; scanf("%d%d", &l,&r); reps[l - 1]++, reps[r]--; } for (i = 0; i < n; i++) { reps[i + 1] += reps[i]; } qsort(arr, n, sizeof(int), sort); qsort(reps, n, sizeof(int), sort); long long answer = 0L; for (int i = 0; i < n; i++) { answer += (long long)arr[i] * reps[i]; } printf("%lld", answer); return 0; }
The little girl loves the problems on array queries very much.One day she came across a rather well-known problem: you've got an array of $$$n$$$ elements (the elements of the array are indexed starting from 1); also, there are $$$q$$$ queries, each one is defined by a pair of integers $$$l_i$$$, $$$r_i$$$ $$$(1 \le l_i \le r_i \le n)$$$. You need to find for each query the sum of elements of the array with indexes from $$$l_i$$$ to $$$r_i$$$, inclusive.The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum.
In a single line print, a single integer β€” the maximum sum of query replies after the array elements are reordered. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
926ec28d1c80e7cbe0bb6d209e664f48
5e5c2bf586eb6d414d66e84bc3b252cc
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "data structures", "implementation", "sortings", "greedy" ]
1361719800
["3 3\n5 3 2\n1 2\n2 3\n1 3", "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3"]
null
PASSED
1,500
standard input
1 second
The first line contains two space-separated integers $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) and $$$q$$$ ($$$1 \le q \le 2\cdot10^5$$$) β€” the number of elements in the array and the number of queries, correspondingly. The next line contains $$$n$$$ space-separated integers $$$a_i$$$ ($$$1 \le a_i \le 2\cdot10^5$$$) β€” the array elements. Each of the following $$$q$$$ lines contains two space-separated integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le n$$$) β€” the $$$i$$$-th query.
["25", "33"]
#include <stdio.h> #include <stdlib.h> #define MAXN 234567 typedef long long int lli; int n, q, arr[MAXN], reps[MAXN]; int compare(const void *a, const void *b) { return *(int *) b - *(int *) a; } int main() { scanf("%d%d", &n, &q); for (int i = 0; i < n; i++) { scanf("%d", arr + i); } for (int i = 0; i < q; i++) { int l, r; scanf("%d%d", &l ,&r); reps[l - 1]++, reps[r]--; } for (int i = 0; i < n; i++) { reps[i + 1] += reps[i]; } qsort(arr, n, sizeof(int), compare); qsort(reps, n, sizeof(int), compare); lli answer = 0L; for (int i = 0; i < n; i++) { answer += (lli) arr[i] * reps[i]; } printf("%I64d", answer); return EXIT_SUCCESS; }
The little girl loves the problems on array queries very much.One day she came across a rather well-known problem: you've got an array of $$$n$$$ elements (the elements of the array are indexed starting from 1); also, there are $$$q$$$ queries, each one is defined by a pair of integers $$$l_i$$$, $$$r_i$$$ $$$(1 \le l_i \le r_i \le n)$$$. You need to find for each query the sum of elements of the array with indexes from $$$l_i$$$ to $$$r_i$$$, inclusive.The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum.
In a single line print, a single integer β€” the maximum sum of query replies after the array elements are reordered. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
926ec28d1c80e7cbe0bb6d209e664f48
3279c16d77806080a1d6cdff9d173044
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "data structures", "implementation", "sortings", "greedy" ]
1361719800
["3 3\n5 3 2\n1 2\n2 3\n1 3", "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3"]
null
PASSED
1,500
standard input
1 second
The first line contains two space-separated integers $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) and $$$q$$$ ($$$1 \le q \le 2\cdot10^5$$$) β€” the number of elements in the array and the number of queries, correspondingly. The next line contains $$$n$$$ space-separated integers $$$a_i$$$ ($$$1 \le a_i \le 2\cdot10^5$$$) β€” the array elements. Each of the following $$$q$$$ lines contains two space-separated integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le n$$$) β€” the $$$i$$$-th query.
["25", "33"]
#include <stdio.h> #include <stdlib.h> #define MAXN 234567 typedef long long int lli; int n, q, arr[MAXN], reps[MAXN]; int compare(const void *a, const void *b) { return *(int *) a - *(int *) b; } int main() { scanf("%d%d", &n, &q); for (int i = 0; i < n; i++) { scanf("%d", arr + i); } for (int i = 0; i < q; i++) { int l, r; scanf("%d%d", &l ,&r); reps[l - 1]++, reps[r]--; } for (int i = 0; i < n; i++) { reps[i + 1] += reps[i]; } qsort(arr, n, sizeof(int), compare); qsort(reps, n, sizeof(int), compare); lli answer = 0L; for (int i = 0; i < n; i++) { answer += (lli) arr[i] * reps[i]; } printf("%I64d", answer); return EXIT_SUCCESS; }
The little girl loves the problems on array queries very much.One day she came across a rather well-known problem: you've got an array of $$$n$$$ elements (the elements of the array are indexed starting from 1); also, there are $$$q$$$ queries, each one is defined by a pair of integers $$$l_i$$$, $$$r_i$$$ $$$(1 \le l_i \le r_i \le n)$$$. You need to find for each query the sum of elements of the array with indexes from $$$l_i$$$ to $$$r_i$$$, inclusive.The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum.
In a single line print, a single integer β€” the maximum sum of query replies after the array elements are reordered. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
926ec28d1c80e7cbe0bb6d209e664f48
fd3df42346368c29258e2ab0b2b30dac
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "data structures", "implementation", "sortings", "greedy" ]
1361719800
["3 3\n5 3 2\n1 2\n2 3\n1 3", "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3"]
null
PASSED
1,500
standard input
1 second
The first line contains two space-separated integers $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) and $$$q$$$ ($$$1 \le q \le 2\cdot10^5$$$) β€” the number of elements in the array and the number of queries, correspondingly. The next line contains $$$n$$$ space-separated integers $$$a_i$$$ ($$$1 \le a_i \le 2\cdot10^5$$$) β€” the array elements. Each of the following $$$q$$$ lines contains two space-separated integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le n$$$) β€” the $$$i$$$-th query.
["25", "33"]
#include <stdio.h> int mergesort(long long int a[],long long int s,long long int e) { long long int m=(s+e)/2,i; long long int b[e+1]; if(s==e)return 0; mergesort(a,s,m); mergesort(a,m+1,e); int x=s,y=m+1; for ( i = s; i < e+1 && (x<m+1 && y<e+1); i++) { if(a[x]<a[y]){ b[i]=a[x]; x++; } else { b[i]=a[y]; y++; } } while (x<m+1) { b[i]=a[x]; i++; x++; } while (y<e+1) { b[i]=a[y]; i++; y++; } for ( i = s; i < e+1; i++) { a[i]=b[i]; } return 0; } int main() { long long int x,y,z,i,j,k,n,q,m,l,r; scanf("%lld %lld",&n,&q); long long int a[n],b[n]; for (i = 0; i < n; i++) { scanf("%lld",&a[i]); b[i]=0; } for ( i = 0; i < q; i++) { scanf("%lld %lld",&l,&r); b[l-1]++; if (r!=n) { b[r]--; } } for ( i = 1; i < n; i++) { b[i]+=b[i-1]; } mergesort(a,0,n-1); mergesort(b,0,n-1); long long int sum=0; for ( i = 0; i < n; i++) { sum+=a[i]*b[i]; } printf("%lld",sum); }
The little girl loves the problems on array queries very much.One day she came across a rather well-known problem: you've got an array of $$$n$$$ elements (the elements of the array are indexed starting from 1); also, there are $$$q$$$ queries, each one is defined by a pair of integers $$$l_i$$$, $$$r_i$$$ $$$(1 \le l_i \le r_i \le n)$$$. You need to find for each query the sum of elements of the array with indexes from $$$l_i$$$ to $$$r_i$$$, inclusive.The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum.
In a single line print, a single integer β€” the maximum sum of query replies after the array elements are reordered. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
926ec28d1c80e7cbe0bb6d209e664f48
11a9eba5c0b9f1ff626507bae7fb1a22
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "data structures", "implementation", "sortings", "greedy" ]
1361719800
["3 3\n5 3 2\n1 2\n2 3\n1 3", "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3"]
null
PASSED
1,500
standard input
1 second
The first line contains two space-separated integers $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) and $$$q$$$ ($$$1 \le q \le 2\cdot10^5$$$) β€” the number of elements in the array and the number of queries, correspondingly. The next line contains $$$n$$$ space-separated integers $$$a_i$$$ ($$$1 \le a_i \le 2\cdot10^5$$$) β€” the array elements. Each of the following $$$q$$$ lines contains two space-separated integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le n$$$) β€” the $$$i$$$-th query.
["25", "33"]
#include <stdio.h> #include <stdlib.h> #include <sys/time.h> int aa[1234567]; int f[1234567]; void srand_(){ struct timeval tv; gettimeofday(&tv , NULL); srand(tv.tv_sec ^ tv.tv_usec); } int rand_(int n){ return (rand() * 76543LL + rand()) % n; } int compare(void const *a, void const *b){ int ia = *(int *) a; int ib = *(int *) b; return ia - ib; } void sort(int *aa , int n){ for(int i = 0;i < n; i++){ int j = rand_(i + 1) , tmp; tmp = aa[i] , aa[i] = aa[j] , aa[j] = tmp; } qsort(aa , n , sizeof *aa , compare); } int main(){ srand_(); int n, m; scanf("%d%d", &n, &m); for(int i = 0; i < n; i++){ scanf("%d", &aa[i]); } for(int i = 0; i < m; i++){ int l, r; scanf("%d%d", &l, &r); ++f[--l]; --f[r]; } long long tmp = 0; for(int i = 0; i < n; i++){ tmp += f[i]; f[i] = tmp; } sort(aa, n); sort(f, n); long long ans = 0; for(int i = 0; i < n; i++){ ans += 1LL * f[i] * aa[i]; } printf("%lld\n", ans); return 0; }
Xenia lives in a city that has n houses built along the main ringroad. The ringroad houses are numbered 1 through n in the clockwise order. The ringroad traffic is one way and also is clockwise.Xenia has recently moved into the ringroad house number 1. As a result, she's got m things to do. In order to complete the i-th task, she needs to be in the house number ai and complete all tasks with numbers less than i. Initially, Xenia is in the house number 1, find the minimum time she needs to complete all her tasks if moving from a house to a neighboring one along the ringroad takes one unit of time.
Print a single integer β€” the time Xenia needs to complete all tasks. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
2c9c96dc5b6f8d1f0ddeea8e07640d3e
64875c602fdb18c7bdc67e05fb43dad0
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1377531000
["4 3\n3 2 3", "4 3\n2 3 3"]
NoteIn the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units.
PASSED
1,000
standard input
2 seconds
The first line contains two integers n and m (2 ≀ n ≀ 105, 1 ≀ m ≀ 105). The second line contains m integers a1, a2, ..., am (1 ≀ ai ≀ n). Note that Xenia can have multiple consecutive tasks in one house.
["6", "2"]
#include <stdio.h> int main() { int n, m, i, last; double result = 0.0; scanf("%d%d", &n, &m); last = 1; while (m--) { scanf("%d", &i); if (last < i) { result += i - last; } else if (last > i) { result += n - last + i; } last = i; } printf("%0.0lf", result); return 0; }
Xenia lives in a city that has n houses built along the main ringroad. The ringroad houses are numbered 1 through n in the clockwise order. The ringroad traffic is one way and also is clockwise.Xenia has recently moved into the ringroad house number 1. As a result, she's got m things to do. In order to complete the i-th task, she needs to be in the house number ai and complete all tasks with numbers less than i. Initially, Xenia is in the house number 1, find the minimum time she needs to complete all her tasks if moving from a house to a neighboring one along the ringroad takes one unit of time.
Print a single integer β€” the time Xenia needs to complete all tasks. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
2c9c96dc5b6f8d1f0ddeea8e07640d3e
5bb3f2c0773f78ee2a4743725d3f85fc
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1377531000
["4 3\n3 2 3", "4 3\n2 3 3"]
NoteIn the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units.
PASSED
1,000
standard input
2 seconds
The first line contains two integers n and m (2 ≀ n ≀ 105, 1 ≀ m ≀ 105). The second line contains m integers a1, a2, ..., am (1 ≀ ai ≀ n). Note that Xenia can have multiple consecutive tasks in one house.
["6", "2"]
#include <stdio.h> #include <stdlib.h> int main() { int n, m; int i, j; long long int time = 0; scanf(" %d %d", &n, &m); int a[m]; for(i=0; i<m; i++){ scanf(" %d", &a[i]); } int max = a[0]; int temp = 1; for(i=0; i<m; i++){ if(a[i] >= max){ time += a[i] - temp; temp = a[i]; }else{ time += n - (temp - a[i]); temp = a[i]; } max = a[i]; } printf("\n%lld\n",time); return 0; }
Xenia lives in a city that has n houses built along the main ringroad. The ringroad houses are numbered 1 through n in the clockwise order. The ringroad traffic is one way and also is clockwise.Xenia has recently moved into the ringroad house number 1. As a result, she's got m things to do. In order to complete the i-th task, she needs to be in the house number ai and complete all tasks with numbers less than i. Initially, Xenia is in the house number 1, find the minimum time she needs to complete all her tasks if moving from a house to a neighboring one along the ringroad takes one unit of time.
Print a single integer β€” the time Xenia needs to complete all tasks. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
2c9c96dc5b6f8d1f0ddeea8e07640d3e
16fdbe0e7e2afafb03a944aeedcdbe4f
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1377531000
["4 3\n3 2 3", "4 3\n2 3 3"]
NoteIn the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units.
PASSED
1,000
standard input
2 seconds
The first line contains two integers n and m (2 ≀ n ≀ 105, 1 ≀ m ≀ 105). The second line contains m integers a1, a2, ..., am (1 ≀ ai ≀ n). Note that Xenia can have multiple consecutive tasks in one house.
["6", "2"]
#include<stdio.h> int main() { __int64 n,m,t,s=0,i,x=1; scanf("%I64d %I64d",&n,&m); for(i=0;i<m;i++) { scanf("%I64d",&t); if(t==x); else if(t>x) {s+=t-x;x=t;} else {s+=t+n-x;x=t;} } printf("%I64d",s); return 0; }
Xenia lives in a city that has n houses built along the main ringroad. The ringroad houses are numbered 1 through n in the clockwise order. The ringroad traffic is one way and also is clockwise.Xenia has recently moved into the ringroad house number 1. As a result, she's got m things to do. In order to complete the i-th task, she needs to be in the house number ai and complete all tasks with numbers less than i. Initially, Xenia is in the house number 1, find the minimum time she needs to complete all her tasks if moving from a house to a neighboring one along the ringroad takes one unit of time.
Print a single integer β€” the time Xenia needs to complete all tasks. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
2c9c96dc5b6f8d1f0ddeea8e07640d3e
e226c6b8247601684abbd108f74db6bd
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1377531000
["4 3\n3 2 3", "4 3\n2 3 3"]
NoteIn the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units.
PASSED
1,000
standard input
2 seconds
The first line contains two integers n and m (2 ≀ n ≀ 105, 1 ≀ m ≀ 105). The second line contains m integers a1, a2, ..., am (1 ≀ ai ≀ n). Note that Xenia can have multiple consecutive tasks in one house.
["6", "2"]
#include <stdio.h> int main() { long int n,m,a=1,b,i; long long int t=0; scanf("%ld%ld",&n,&m); for(i=1;i<=m;i++) { scanf("%ld",&b); if(a<=b) { t=t+(b-a); } else { t=t+((n-a)+b); } a=b; } printf("%lld",t); return 0; }
Xenia lives in a city that has n houses built along the main ringroad. The ringroad houses are numbered 1 through n in the clockwise order. The ringroad traffic is one way and also is clockwise.Xenia has recently moved into the ringroad house number 1. As a result, she's got m things to do. In order to complete the i-th task, she needs to be in the house number ai and complete all tasks with numbers less than i. Initially, Xenia is in the house number 1, find the minimum time she needs to complete all her tasks if moving from a house to a neighboring one along the ringroad takes one unit of time.
Print a single integer β€” the time Xenia needs to complete all tasks. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
2c9c96dc5b6f8d1f0ddeea8e07640d3e
b09327fa47bb2f3ff58ec868788b88d7
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1377531000
["4 3\n3 2 3", "4 3\n2 3 3"]
NoteIn the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units.
PASSED
1,000
standard input
2 seconds
The first line contains two integers n and m (2 ≀ n ≀ 105, 1 ≀ m ≀ 105). The second line contains m integers a1, a2, ..., am (1 ≀ ai ≀ n). Note that Xenia can have multiple consecutive tasks in one house.
["6", "2"]
#include<stdio.h> main() { long long n,m,task,i,time,j; while(scanf("%lld %lld",&n,&m)!=EOF) { time=0; j=1; for(i=1; i<=m; i++) { scanf("%lld",&task); if(task>=j) { time=time+task-j; } else { time=time+n-(j-task); } j=task; } printf("%lld\n",time); } return 0; }
Xenia lives in a city that has n houses built along the main ringroad. The ringroad houses are numbered 1 through n in the clockwise order. The ringroad traffic is one way and also is clockwise.Xenia has recently moved into the ringroad house number 1. As a result, she's got m things to do. In order to complete the i-th task, she needs to be in the house number ai and complete all tasks with numbers less than i. Initially, Xenia is in the house number 1, find the minimum time she needs to complete all her tasks if moving from a house to a neighboring one along the ringroad takes one unit of time.
Print a single integer β€” the time Xenia needs to complete all tasks. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
2c9c96dc5b6f8d1f0ddeea8e07640d3e
f7efd63e30a7f1b7b04e970d8260bb68
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1377531000
["4 3\n3 2 3", "4 3\n2 3 3"]
NoteIn the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units.
PASSED
1,000
standard input
2 seconds
The first line contains two integers n and m (2 ≀ n ≀ 105, 1 ≀ m ≀ 105). The second line contains m integers a1, a2, ..., am (1 ≀ ai ≀ n). Note that Xenia can have multiple consecutive tasks in one house.
["6", "2"]
#include <stdio.h> #include <stdlib.h> int main() { long long int num , task; long long int a[100000]; scanf("%I64d" , &num ); scanf("%I64d" , &task ); long long int i; for(i = 0; i < task; i++) { scanf("%I64d" , &a[i]); } long long int time = 0, j = 0 , position = 1 ,t; while(j != task) { if(position != a[j] && position < a[j]) { t = a[j] - position; time += t; }else if(position != a[j] && position > a[j]) { t = num - position; t += a[j]; time += t; } position = a[j]; j++; } printf("%I64d" , time); return 0; }
Xenia lives in a city that has n houses built along the main ringroad. The ringroad houses are numbered 1 through n in the clockwise order. The ringroad traffic is one way and also is clockwise.Xenia has recently moved into the ringroad house number 1. As a result, she's got m things to do. In order to complete the i-th task, she needs to be in the house number ai and complete all tasks with numbers less than i. Initially, Xenia is in the house number 1, find the minimum time she needs to complete all her tasks if moving from a house to a neighboring one along the ringroad takes one unit of time.
Print a single integer β€” the time Xenia needs to complete all tasks. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
2c9c96dc5b6f8d1f0ddeea8e07640d3e
04e2b2152a1b45b46fb7792e240b4e59
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1377531000
["4 3\n3 2 3", "4 3\n2 3 3"]
NoteIn the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units.
PASSED
1,000
standard input
2 seconds
The first line contains two integers n and m (2 ≀ n ≀ 105, 1 ≀ m ≀ 105). The second line contains m integers a1, a2, ..., am (1 ≀ ai ≀ n). Note that Xenia can have multiple consecutive tasks in one house.
["6", "2"]
#include <stdio.h> #include <stdlib.h> int main() { long long n,m; scanf("%lli%lli",&n,&m); int i; long long a[m]; for(i=0;i<m;i++) scanf("%lli",&a[i]); long long time=a[0]-1; for(i=1;i<m;i++) { if(a[i]<a[i-1]) time+=(a[i]+n)-a[i-1]; else time+=a[i]-a[i-1]; } printf("%lli\n",time); return 0; }
Xenia lives in a city that has n houses built along the main ringroad. The ringroad houses are numbered 1 through n in the clockwise order. The ringroad traffic is one way and also is clockwise.Xenia has recently moved into the ringroad house number 1. As a result, she's got m things to do. In order to complete the i-th task, she needs to be in the house number ai and complete all tasks with numbers less than i. Initially, Xenia is in the house number 1, find the minimum time she needs to complete all her tasks if moving from a house to a neighboring one along the ringroad takes one unit of time.
Print a single integer β€” the time Xenia needs to complete all tasks. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
2c9c96dc5b6f8d1f0ddeea8e07640d3e
82ab7b8dc52422c5b0b4b2b9c944e48f
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1377531000
["4 3\n3 2 3", "4 3\n2 3 3"]
NoteIn the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units.
PASSED
1,000
standard input
2 seconds
The first line contains two integers n and m (2 ≀ n ≀ 105, 1 ≀ m ≀ 105). The second line contains m integers a1, a2, ..., am (1 ≀ ai ≀ n). Note that Xenia can have multiple consecutive tasks in one house.
["6", "2"]
#include<stdio.h> int main(){ int n,m,i; int arr[100000]; scanf("%d %d",&n,&m); arr[0]=1; for(i=1;i<=m;i++){ scanf("%d",&arr[i]); } long long int sum=0; for(i=1;i<=m;i++){ if(arr[i]>=arr[i-1]){ sum+=arr[i]-arr[i-1]; } else{ sum+=arr[i]+n-arr[i-1]; } } printf("%lld",sum); return 0; }
Xenia lives in a city that has n houses built along the main ringroad. The ringroad houses are numbered 1 through n in the clockwise order. The ringroad traffic is one way and also is clockwise.Xenia has recently moved into the ringroad house number 1. As a result, she's got m things to do. In order to complete the i-th task, she needs to be in the house number ai and complete all tasks with numbers less than i. Initially, Xenia is in the house number 1, find the minimum time she needs to complete all her tasks if moving from a house to a neighboring one along the ringroad takes one unit of time.
Print a single integer β€” the time Xenia needs to complete all tasks. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
2c9c96dc5b6f8d1f0ddeea8e07640d3e
819e8502d769a2dde285b3b373c16ed1
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1377531000
["4 3\n3 2 3", "4 3\n2 3 3"]
NoteIn the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units.
PASSED
1,000
standard input
2 seconds
The first line contains two integers n and m (2 ≀ n ≀ 105, 1 ≀ m ≀ 105). The second line contains m integers a1, a2, ..., am (1 ≀ ai ≀ n). Note that Xenia can have multiple consecutive tasks in one house.
["6", "2"]
#include<stdio.h> int main(){ int n,m,i; int arr[100000]; scanf("%d %d",&n,&m); arr[0]=1; for(i=1;i<=m;i++){ scanf("%d",&arr[i]); } long long int sum=0; for(i=1;i<=m;i++){ if(arr[i]>=arr[i-1]){ sum+=arr[i]-arr[i-1]; } else{ sum+=arr[i]+n-arr[i-1]; } } printf("%I64d",sum); return 0; }
Xenia lives in a city that has n houses built along the main ringroad. The ringroad houses are numbered 1 through n in the clockwise order. The ringroad traffic is one way and also is clockwise.Xenia has recently moved into the ringroad house number 1. As a result, she's got m things to do. In order to complete the i-th task, she needs to be in the house number ai and complete all tasks with numbers less than i. Initially, Xenia is in the house number 1, find the minimum time she needs to complete all her tasks if moving from a house to a neighboring one along the ringroad takes one unit of time.
Print a single integer β€” the time Xenia needs to complete all tasks. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
2c9c96dc5b6f8d1f0ddeea8e07640d3e
7280758ab0f02f996e868dfc52182f9c
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1377531000
["4 3\n3 2 3", "4 3\n2 3 3"]
NoteIn the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units.
PASSED
1,000
standard input
2 seconds
The first line contains two integers n and m (2 ≀ n ≀ 105, 1 ≀ m ≀ 105). The second line contains m integers a1, a2, ..., am (1 ≀ ai ≀ n). Note that Xenia can have multiple consecutive tasks in one house.
["6", "2"]
#include <stdio.h> int go(int *, int, int); // Go to a location. Return the time taken to do so. int main() { int n, m, a, pos = 1, i; long long t = 0; scanf("%d%d", &n, &m); // Taking n, m for (i = 0 ; i < m ; i++) { scanf("%d", &a); t += (a - pos + n) % n; pos = a; } printf("%lld\n", t); return 0; }
Xenia lives in a city that has n houses built along the main ringroad. The ringroad houses are numbered 1 through n in the clockwise order. The ringroad traffic is one way and also is clockwise.Xenia has recently moved into the ringroad house number 1. As a result, she's got m things to do. In order to complete the i-th task, she needs to be in the house number ai and complete all tasks with numbers less than i. Initially, Xenia is in the house number 1, find the minimum time she needs to complete all her tasks if moving from a house to a neighboring one along the ringroad takes one unit of time.
Print a single integer β€” the time Xenia needs to complete all tasks. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
2c9c96dc5b6f8d1f0ddeea8e07640d3e
5d5f7247f987b8ff670263f189796193
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1377531000
["4 3\n3 2 3", "4 3\n2 3 3"]
NoteIn the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units.
PASSED
1,000
standard input
2 seconds
The first line contains two integers n and m (2 ≀ n ≀ 105, 1 ≀ m ≀ 105). The second line contains m integers a1, a2, ..., am (1 ≀ ai ≀ n). Note that Xenia can have multiple consecutive tasks in one house.
["6", "2"]
#include<stdio.h> int main() { int p,q; long long int n,m,s=0,i; scanf("%I64d %I64d",&n,&m); long long int arr[m]; for(i=0;i<m;i++){ scanf("%I64d",&arr[i]); } s=s+arr[0]-1; for(i=0;i<(m-1);i++){ if(arr[i]>arr[i+1]){ q=n-arr[i]; p=arr[i+1]; s=s+q+p; } else if(arr[i]<arr[i+1]){ p=arr[i+1]-arr[i]; s=s+p; } } printf("%I64d",s); return 0; }
Xenia lives in a city that has n houses built along the main ringroad. The ringroad houses are numbered 1 through n in the clockwise order. The ringroad traffic is one way and also is clockwise.Xenia has recently moved into the ringroad house number 1. As a result, she's got m things to do. In order to complete the i-th task, she needs to be in the house number ai and complete all tasks with numbers less than i. Initially, Xenia is in the house number 1, find the minimum time she needs to complete all her tasks if moving from a house to a neighboring one along the ringroad takes one unit of time.
Print a single integer β€” the time Xenia needs to complete all tasks. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
2c9c96dc5b6f8d1f0ddeea8e07640d3e
e930ad517c3cb9fac4f86c6899beaa0c
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1377531000
["4 3\n3 2 3", "4 3\n2 3 3"]
NoteIn the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units.
PASSED
1,000
standard input
2 seconds
The first line contains two integers n and m (2 ≀ n ≀ 105, 1 ≀ m ≀ 105). The second line contains m integers a1, a2, ..., am (1 ≀ ai ≀ n). Note that Xenia can have multiple consecutive tasks in one house.
["6", "2"]
#include <stdio.h> #include <string.h> int num[100005]; int main() { int n, m, former; __int64 sum = 0; scanf("%d %d", &n, &m); int i; for(i = 1; i <= m ; i++) scanf("%d", num + i); for(i = 1, former = 1; i <= m; i++) { if(num[i] > former) sum += (num[i] - former); else if(num[i] < former) sum += (n - former + num[i]); former = num[i]; } printf("%I64d\n", sum); return 0; }
Xenia lives in a city that has n houses built along the main ringroad. The ringroad houses are numbered 1 through n in the clockwise order. The ringroad traffic is one way and also is clockwise.Xenia has recently moved into the ringroad house number 1. As a result, she's got m things to do. In order to complete the i-th task, she needs to be in the house number ai and complete all tasks with numbers less than i. Initially, Xenia is in the house number 1, find the minimum time she needs to complete all her tasks if moving from a house to a neighboring one along the ringroad takes one unit of time.
Print a single integer β€” the time Xenia needs to complete all tasks. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
2c9c96dc5b6f8d1f0ddeea8e07640d3e
ae25160462f479ab1c71536aaa484cef
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1377531000
["4 3\n3 2 3", "4 3\n2 3 3"]
NoteIn the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units.
PASSED
1,000
standard input
2 seconds
The first line contains two integers n and m (2 ≀ n ≀ 105, 1 ≀ m ≀ 105). The second line contains m integers a1, a2, ..., am (1 ≀ ai ≀ n). Note that Xenia can have multiple consecutive tasks in one house.
["6", "2"]
#include <Stdio.h> #include <String.h> int v[100010]; int main(void) { __int64 n,m; while(scanf("%I64d %I64d",&n,&m)!=EOF) { memset(v,0,sizeof(v)); __int64 ans,i; for(i=1;i<=m;i++) scanf("%I64d",&v[i]); for(ans=v[1]-1,i=2;i<=m;i++) { if(v[i]==v[i-1]) continue; else if(v[i]>v[i-1]) { ans+=v[i]-v[i-1]; } else ans+=n-v[i-1]+v[i]; } printf("%I64d\n",ans); } return 0; }
Xenia lives in a city that has n houses built along the main ringroad. The ringroad houses are numbered 1 through n in the clockwise order. The ringroad traffic is one way and also is clockwise.Xenia has recently moved into the ringroad house number 1. As a result, she's got m things to do. In order to complete the i-th task, she needs to be in the house number ai and complete all tasks with numbers less than i. Initially, Xenia is in the house number 1, find the minimum time she needs to complete all her tasks if moving from a house to a neighboring one along the ringroad takes one unit of time.
Print a single integer β€” the time Xenia needs to complete all tasks. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
2c9c96dc5b6f8d1f0ddeea8e07640d3e
0ed000d7cd48cf1e2ec6b41f2f457cdb
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1377531000
["4 3\n3 2 3", "4 3\n2 3 3"]
NoteIn the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units.
PASSED
1,000
standard input
2 seconds
The first line contains two integers n and m (2 ≀ n ≀ 105, 1 ≀ m ≀ 105). The second line contains m integers a1, a2, ..., am (1 ≀ ai ≀ n). Note that Xenia can have multiple consecutive tasks in one house.
["6", "2"]
#include <stdio.h> int main() { int i, n, m, a[100001], moves, position = 1; long long count = 0; scanf("%d %d", &n, &m); for (i = 0; i < m; i++) { scanf("%d", &a[i]); } for (i = 0; i < m; i++) { if (a[i] >= position) { moves = a[i] - position; } else { moves = n - position + a[i]; } count += moves; position = a[i]; } printf("%I64d\n", count); return 0; }
Xenia lives in a city that has n houses built along the main ringroad. The ringroad houses are numbered 1 through n in the clockwise order. The ringroad traffic is one way and also is clockwise.Xenia has recently moved into the ringroad house number 1. As a result, she's got m things to do. In order to complete the i-th task, she needs to be in the house number ai and complete all tasks with numbers less than i. Initially, Xenia is in the house number 1, find the minimum time she needs to complete all her tasks if moving from a house to a neighboring one along the ringroad takes one unit of time.
Print a single integer β€” the time Xenia needs to complete all tasks. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
2c9c96dc5b6f8d1f0ddeea8e07640d3e
f2eed7a6cc0ed8d3902c86ce1b45a4cf
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1377531000
["4 3\n3 2 3", "4 3\n2 3 3"]
NoteIn the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units.
PASSED
1,000
standard input
2 seconds
The first line contains two integers n and m (2 ≀ n ≀ 105, 1 ≀ m ≀ 105). The second line contains m integers a1, a2, ..., am (1 ≀ ai ≀ n). Note that Xenia can have multiple consecutive tasks in one house.
["6", "2"]
#include <stdio.h> #include <stdlib.h> int main() { int n,m,i; long long count=0; long long currentpos=1; scanf("%d%d",&n,&m); int x[m]; for(i=0;i<m;i++) { scanf("%d",&x[i]); if(x[i]>n||x[i]<0) { break; } } for(i=0;i<m;i++) { long long test=x[i]; if(currentpos<=test) { count=count+(x[i]-currentpos); } else if(currentpos>test) { count=count+(n-currentpos)+(x[i]); } currentpos=test; } printf("%I64d",count); return 0; }
Xenia lives in a city that has n houses built along the main ringroad. The ringroad houses are numbered 1 through n in the clockwise order. The ringroad traffic is one way and also is clockwise.Xenia has recently moved into the ringroad house number 1. As a result, she's got m things to do. In order to complete the i-th task, she needs to be in the house number ai and complete all tasks with numbers less than i. Initially, Xenia is in the house number 1, find the minimum time she needs to complete all her tasks if moving from a house to a neighboring one along the ringroad takes one unit of time.
Print a single integer β€” the time Xenia needs to complete all tasks. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
2c9c96dc5b6f8d1f0ddeea8e07640d3e
06efb8f9792ca05c6d131e7a81f8e982
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1377531000
["4 3\n3 2 3", "4 3\n2 3 3"]
NoteIn the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units.
PASSED
1,000
standard input
2 seconds
The first line contains two integers n and m (2 ≀ n ≀ 105, 1 ≀ m ≀ 105). The second line contains m integers a1, a2, ..., am (1 ≀ ai ≀ n). Note that Xenia can have multiple consecutive tasks in one house.
["6", "2"]
#include<stdio.h> int a[100010]; int abs(int x) { if (x<0) return -1*x; return x; } int main() { int n,m; scanf("%d%d",&n,&m); for (int i=1;i<=m;i++) { scanf("%d",&a[i]); a[i]--; } int cur=0; __int64 ans=0; for (int i=1;i<=m;i++) { if (a[i]>=cur) ans+=a[i]-cur; else ans+=n-(cur-a[i]); cur=a[i]; } printf("%I64d\n",ans); return 0; }
Xenia lives in a city that has n houses built along the main ringroad. The ringroad houses are numbered 1 through n in the clockwise order. The ringroad traffic is one way and also is clockwise.Xenia has recently moved into the ringroad house number 1. As a result, she's got m things to do. In order to complete the i-th task, she needs to be in the house number ai and complete all tasks with numbers less than i. Initially, Xenia is in the house number 1, find the minimum time she needs to complete all her tasks if moving from a house to a neighboring one along the ringroad takes one unit of time.
Print a single integer β€” the time Xenia needs to complete all tasks. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
2c9c96dc5b6f8d1f0ddeea8e07640d3e
16f47d7e7af4621b3d373a4e4069705a
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1377531000
["4 3\n3 2 3", "4 3\n2 3 3"]
NoteIn the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units.
PASSED
1,000
standard input
2 seconds
The first line contains two integers n and m (2 ≀ n ≀ 105, 1 ≀ m ≀ 105). The second line contains m integers a1, a2, ..., am (1 ≀ ai ≀ n). Note that Xenia can have multiple consecutive tasks in one house.
["6", "2"]
#include<stdio.h> int main() { long long int i,xp=1,n,m,t=0,a[100000]; scanf("%I64d%I64d",&n,&m); for(i=0;i<m;i++) scanf("%I64d",&a[i]); for(i=0;i<m;i++) { if(xp<a[i]) {t+=a[i]-xp; xp=a[i]; } else if(xp>a[i]) {t+=n-xp+a[i]; xp=a[i]; } } printf("%I64d",t); return 0; }
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer n. Help Anton to determine the exchange rate of currency you all know for tomorrow!
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print  - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.
C
bc375e27bd52f413216aaecc674366f8
a1f19872cea4e1abaf3580a1d6b0e6ca
GNU C
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "strings" ]
1422376200
["527", "4573", "1357997531"]
null
PASSED
1,300
standard input
0.5 seconds
The first line contains an odd positive integer nΒ β€” the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes.
["572", "3574", "-1"]
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<math.h> typedef int ll; int main() { ll t,i,n,a[100005],count=0,flag=0,p,min; char str[100005]; scanf("%s",str); n=strlen(str); min=10; for(i=0;i<n;i++) { a[i]=str[i]-'0'; if(a[i]%2==0) { count++; } } if(count==0) { printf("-1\n"); } else { for(i=0;i<n-1&&flag==0;i++) { if((a[i]<a[n-1]&&a[i]%2==0)||(a[i]%2==0&&count==1)) { flag=1; p=i; } else if(a[i]%2==0) { count--; } } t=a[p]; a[p]=a[n-1]; a[n-1]=t; for(i=0;i<n;i++) { printf("%d",a[i]); } printf("\n"); } return 0; }
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer n. Help Anton to determine the exchange rate of currency you all know for tomorrow!
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print  - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.
C
bc375e27bd52f413216aaecc674366f8
d40f8f5545c4292fd386c65a7078547c
GNU C
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "strings" ]
1422376200
["527", "4573", "1357997531"]
null
PASSED
1,300
standard input
0.5 seconds
The first line contains an odd positive integer nΒ β€” the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes.
["572", "3574", "-1"]
#include <stdio.h> #include <string.h> int main() { char num[100010],c; scanf("%s",num); int l=strlen(num),i=0; while(i<l) { if(num[i]<num[l-1] && !((num[i]-'0')%2)) { c=num[i]; num[i]=num[l-1]; num[l-1]=c; printf("%s\n",num); return 0; } i++; } i--; while(i>=0) { if(!((num[i]-'0')%2)) { c=num[i]; num[i]=num[l-1]; num[l-1]=c; printf("%s\n",num); return 0; } i--; } printf("-1\n"); return 0; }
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer n. Help Anton to determine the exchange rate of currency you all know for tomorrow!
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print  - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.
C
bc375e27bd52f413216aaecc674366f8
82b388eb5a1c055e05d4540fa69a4c66
GNU C
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "strings" ]
1422376200
["527", "4573", "1357997531"]
null
PASSED
1,300
standard input
0.5 seconds
The first line contains an odd positive integer nΒ β€” the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes.
["572", "3574", "-1"]
#include"stdio.h" int main() { char currency[100001], cu; char temp[100001];int maxi = 0; int i = 0 ,ans = 0 ,j; scanf("%s" , currency); for(i = 0; i < strlen(currency) - 1 ; ++i){ if((currency[i] - '0') % 2 == 0 && currency[strlen(currency) - 1] > currency[i] ){ maxi = 1; strcpy(temp ,currency ); cu = temp[strlen(currency) - 1]; temp[strlen(currency) - 1] = temp[i]; temp[i] = cu; ++ans; } if(maxi)break; } if(ans == 0){ for(i = strlen(currency) - 2; i > -1 ; --i){ if((currency[i] - '0') % 2 == 0 ){ strcpy(temp ,currency ); cu = temp[strlen(currency) - 1]; temp[strlen(currency) - 1] = temp[i]; temp[i] = cu; ++ans; printf("%s" , temp); return 0; } } if(ans==0)printf("-1"); } else{ printf("%s" , temp); } return 0; }
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer n. Help Anton to determine the exchange rate of currency you all know for tomorrow!
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print  - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.
C
bc375e27bd52f413216aaecc674366f8
521ad06329e69fd3984a951d52c0831b
GNU C
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "strings" ]
1422376200
["527", "4573", "1357997531"]
null
PASSED
1,300
standard input
0.5 seconds
The first line contains an odd positive integer nΒ β€” the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes.
["572", "3574", "-1"]
#include <stdio.h> #include <string.h> void swap(char *a, char *b) { *a = *a + *b - (*b = *a); } int main() { char num[200005]; scanf("%s", num); int n = strlen(num), i; for(i = 0; i < n; i++) { if((num[i] - '0')%2 == 0 && num[i] < num[n - 1]) { swap(num + i, num + n - 1); printf("%s\n", num); return 0; } } for(i = n - 2; i >= 0; i--) { if((num[i] - '0')%2 == 0 && num[i] > num[n - 1]) { swap(num + i, num + n - 1); printf("%s\n", num); return 0; } } printf("-1\n"); return 0; }
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer n. Help Anton to determine the exchange rate of currency you all know for tomorrow!
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print  - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.
C
bc375e27bd52f413216aaecc674366f8
d1a9478f00ce985654d51f4b12031bd0
GNU C
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "strings" ]
1422376200
["527", "4573", "1357997531"]
null
PASSED
1,300
standard input
0.5 seconds
The first line contains an odd positive integer nΒ β€” the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes.
["572", "3574", "-1"]
#include<stdio.h> #include<string.h> int main() { char str[100005]; scanf("%s",str); int curr,flag=0,i,len=strlen(str),min=99; for(i=0;i<len;i++) { if((str[i]-'0')%2==0) { flag=1; if((str[i]-'0')<(str[len-1]-'0')) { flag=2; str[i]=(str[len-1]+str[i])-(str[len-1]=str[i]); break; } /*if((str[i]-'0')<=min) { (min=str[i]-'0');*/curr=i; } // printf("%d",flag); } //printf("%d",flag); if(flag==0) printf("-1"); else { if(flag==1){str[len-1]=(str[curr]+str[len-1])-(str[curr]=str[len-1]);} printf("%s",str); } return 0; }
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer n. Help Anton to determine the exchange rate of currency you all know for tomorrow!
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print  - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.
C
bc375e27bd52f413216aaecc674366f8
a4481225d182747188a0f5831cbf773b
GNU C
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "strings" ]
1422376200
["527", "4573", "1357997531"]
null
PASSED
1,300
standard input
0.5 seconds
The first line contains an odd positive integer nΒ β€” the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes.
["572", "3574", "-1"]
#include<stdio.h> #include<string.h> int main() { long long int a,b,c,i=0,j,k,f=0; char s[110000]; scanf("%s",&s); a=strlen(s); for(i=a-1;i>=0;i--){ b=s[i]-'0'; if(b%2==0&&f==0){ k=s[i];c=i;f=1; //printf("%d\n",b/2); break; } } // printf("%d\n",a); /*for(j=0;j<a;j++){ printf("%c ",s[j]); }*/ if(f==1){ for(j=a-1;j>=0;j--){ b=s[j]-'0'; if(b%2==0&&s[a-1]>s[j]) {k=s[j];c=j;} } } j=s[a-1]; s[a-1]=k; s[c]=j; if(f==1){ for(j=0;j<a;j++){ printf("%c",s[j]); } } else printf("%d",-1); return 0; }
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer n. Help Anton to determine the exchange rate of currency you all know for tomorrow!
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print  - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.
C
bc375e27bd52f413216aaecc674366f8
0cb5153ab4d0a39c54ee9ce9d473c79b
GNU C
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "strings" ]
1422376200
["527", "4573", "1357997531"]
null
PASSED
1,300
standard input
0.5 seconds
The first line contains an odd positive integer nΒ β€” the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes.
["572", "3574", "-1"]
#include<stdio.h> #include<string.h> void swap(char *x,char *y) { char temp = *x; *x = *y; *y = temp; } int main() { int i, c=0, l, lo = 0; char num[1000000], c2[1000000], x; scanf("%s", num); l = strlen(num); for(i = 0 ; num[i] != '\0' ; i++) if((num[i] - 48) % 2 == 0 && num[i] < num[l-1]) { swap(&num[l-1], &num[i]); strcpy(c2, num); break; } else if((num[i] - 48) % 2 == 0) { x = num[i]; lo = i; } else c++; if(i == l) { swap(&num[lo], &num[l-1]); strcpy(c2, num); } if(c == l) printf("-1"); else puts(c2); return 0; }
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer n. Help Anton to determine the exchange rate of currency you all know for tomorrow!
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print  - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.
C
bc375e27bd52f413216aaecc674366f8
deac9d72db4fcdbabd2429ffb777c168
GNU C
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "strings" ]
1422376200
["527", "4573", "1357997531"]
null
PASSED
1,300
standard input
0.5 seconds
The first line contains an odd positive integer nΒ β€” the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes.
["572", "3574", "-1"]
#include<stdio.h> #include<math.h> #include<string.h> #include<ctype.h> int main() { char n[100001],temp; gets(n); int l=strlen(n),i,ck=0,t; for(i=0;i<l-1;i++) { if(n[i]=='0'||n[i]=='2'||n[i]=='4'||n[i]=='6'||n[i]=='8') ck=1; } if(ck==0) { printf("-1"); return 0; } for(i=0;i<l-1;i++) { if((n[i]=='0'||n[i]=='2'||n[i]=='4'||n[i]=='6'||n[i]=='8')&&(n[i]<n[l-1])) {temp=n[i]; n[i]=n[l-1]; n[l-1]=temp; printf("%s",n); return 0;} else; } for(i=l-2;i>=0;i--) { if((n[i]=='0'||n[i]=='2'||n[i]=='4'||n[i]=='6'||n[i]=='8')&&(n[i]>n[l-1])) {temp=n[i]; n[i]=n[l-1]; n[l-1]=temp; printf("%s",n); return 0;} } }
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer n. Help Anton to determine the exchange rate of currency you all know for tomorrow!
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print  - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.
C
bc375e27bd52f413216aaecc674366f8
2ab4aff0cf33445665a9b7a46d69c501
GNU C
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "strings" ]
1422376200
["527", "4573", "1357997531"]
null
PASSED
1,300
standard input
0.5 seconds
The first line contains an odd positive integer nΒ β€” the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes.
["572", "3574", "-1"]
#include <stdio.h> #include <string.h> int main() { char a[100005]; scanf("%s",&a); int n = strlen(a); int i,st=10,sti=-1; int x = (int) a[n-1]; for (i = 0; i < n-1; i++) { int y = (int) a[i]; if (y % 2 == 0 && y < x) { sti = i; break; } else if (y % 2 == 0 && y > x) { sti = i; } } if (sti == -1) { puts("-1"); return 0; } else { char c = a[sti]; a[sti] = a[n-1]; a[n-1] = c; printf("%s\n",a); } return 0; }
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer n. Help Anton to determine the exchange rate of currency you all know for tomorrow!
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print  - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.
C
bc375e27bd52f413216aaecc674366f8
66f5833445d7c1a655b2385f88124806
GNU C
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "strings" ]
1422376200
["527", "4573", "1357997531"]
null
PASSED
1,300
standard input
0.5 seconds
The first line contains an odd positive integer nΒ β€” the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes.
["572", "3574", "-1"]
/* /~\. ( oo| Hello World! _\=/_ ___ # / _ \. / ()\ \\//|/.\|\\. _|_____|_ \/ \_/ || | | === | | |\ /| || |_| O |_| \_ _/ # || O || | | | ||__*__|| | | | |~ \___/ ~| []|[] /=\ /=\ /=\ | | | ________________[_]_[_]_[_]________/_]_[_\_________________________*/ #include<stdlib.h> #include<string.h> #include<stdio.h> #include<ctype.h> #include<time.h> #include<math.h> #define FOR(i,a,b) for(i = a; i <= b; i++) #define ROF(i,a,b) for(i = a; i >= b; i--) #define SWAP(a,b,t) t = a; a = b; b = t #define lli long long int #define endl puts("") #define MAX 199999 #define Max 10001 #define WH while char str[MAX]; int i, j, u, s, k, a, b, t; int main() { scanf("%s", str); u = strlen(str); FOR(i,0,u-1){ if((str[i] - '0') % 2 == 0){ if(str[i] < str[u - 1]){ a = str[i]; str[i] = str[u - 1]; str[u - 1] = a; printf("%s", str), endl; return 0; } s = i + 1; } } if(!s){ printf("-1"), endl; return 0; } s--; a = str[s]; str[s] = str[u - 1]; str[u - 1] = a; printf("%s", str), endl; return 0; }
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer n. Help Anton to determine the exchange rate of currency you all know for tomorrow!
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print  - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.
C
bc375e27bd52f413216aaecc674366f8
d2dac47b2b85ca35a24a6d83cb59907e
GNU C
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "strings" ]
1422376200
["527", "4573", "1357997531"]
null
PASSED
1,300
standard input
0.5 seconds
The first line contains an odd positive integer nΒ β€” the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes.
["572", "3574", "-1"]
#include<stdio.h> #include<string.h> int main(){ char a[100001]; scanf("%s", a); int i,l,index=-1,temp,flag=0; l = strlen(a); for(i=0;i<l-1;i++){ if(a[i]%2==0) { if(a[i]<a[l-1]) { flag=1; temp = a[i]; a[i] = a[l-1]; a[l-1] = temp; printf("%s",a); break; } else index = i; } } if(flag==0) { if(index>=0) { temp= a[index]; a[index] = a[l-1]; a[l-1] = temp; printf("%s",a); } else printf("-1"); } return 0; }
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer n. Help Anton to determine the exchange rate of currency you all know for tomorrow!
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print  - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.
C
bc375e27bd52f413216aaecc674366f8
eb234fb691fb0246b91833867dca431b
GNU C
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "strings" ]
1422376200
["527", "4573", "1357997531"]
null
PASSED
1,300
standard input
0.5 seconds
The first line contains an odd positive integer nΒ β€” the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes.
["572", "3574", "-1"]
#include<stdio.h> #include<stdlib.h> int main() { char a[100005]; int i,j=0,flag=0,loc,max=47; scanf("%s",a); int x=strlen(a),temp; for(i=0;i<(x-1);i++) { if((a[i]-48)%2==0) { if(a[x-1]>a[i]) { flag=1; max=a[i]; loc=i; break; } } } // printf("%d",flag); if(flag==0) { for(i=x-1;i>=0;i--) { if((a[i]-48)%2==0) { flag=1; max=a[i]; loc=i; break; } } } if(flag==0) printf("-1"); else { temp=a[x-1]; a[x-1]=a[loc]; a[loc]=temp; printf("%s",a); } return 0; }
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer n. Help Anton to determine the exchange rate of currency you all know for tomorrow!
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print  - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.
C
bc375e27bd52f413216aaecc674366f8
63607c73d81384ce2727ee9c8370e3b6
GNU C
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "strings" ]
1422376200
["527", "4573", "1357997531"]
null
PASSED
1,300
standard input
0.5 seconds
The first line contains an odd positive integer nΒ β€” the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes.
["572", "3574", "-1"]
#include<stdio.h> #include<stdlib.h> int main() { char a[100005]; int i,j=0,flag=0,loc,max=47; scanf("%s",a); int x=strlen(a),temp; for(i=0;i<(x-1);i++) { if((a[i]-48)%2==0) { if(a[i]>max&&a[x-1]>a[i]) { flag=1; max=a[i]; loc=i; break; } } } // printf("%d",flag); if(flag==0) { for(i=x-1;i>=0;i--) { if((a[i]-48)%2==0) { flag=1; max=a[i]; loc=i; break; } } } if(flag==0) { if(((a[0]-48)%2)==0) { loc=0; flag=1; } } if(flag==0) printf("-1"); else { temp=a[x-1]; a[x-1]=a[loc]; a[loc]=temp; printf("%s",a); } return 0; }
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer n. Help Anton to determine the exchange rate of currency you all know for tomorrow!
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print  - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.
C
bc375e27bd52f413216aaecc674366f8
b5e043f8dde744a97275fd39756ba67a
GNU C
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "strings" ]
1422376200
["527", "4573", "1357997531"]
null
PASSED
1,300
standard input
0.5 seconds
The first line contains an odd positive integer nΒ β€” the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes.
["572", "3574", "-1"]
#include"stdio.h" int main() { char currency[100001], cu; char temp[100001];int maxi = 0; int i = 0 ,ans = 0 ,j; scanf("%s" , currency); for(i = 0; i < strlen(currency) - 1 ; ++i){ if((currency[i] - '0') % 2 == 0 && currency[strlen(currency) - 1] > currency[i] ){ maxi = 1; strcpy(temp ,currency ); cu = temp[strlen(currency) - 1]; temp[strlen(currency) - 1] = temp[i]; temp[i] = cu; ++ans; } if(maxi)break; } if(ans == 0){ for(i = strlen(currency) - 2; i > -1 ; --i){ if((currency[i] - '0') % 2 == 0 ){ strcpy(temp ,currency ); cu = temp[strlen(currency) - 1]; temp[strlen(currency) - 1] = temp[i]; temp[i] = cu; ++ans; printf("%s" , temp); return 0; } } if(ans==0)printf("-1"); } else{ printf("%s" , temp); } return 0; }
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer n. Help Anton to determine the exchange rate of currency you all know for tomorrow!
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print  - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.
C
bc375e27bd52f413216aaecc674366f8
6c0c27962c65fa056bd1d26de2eb7d30
GNU C
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "strings" ]
1422376200
["527", "4573", "1357997531"]
null
PASSED
1,300
standard input
0.5 seconds
The first line contains an odd positive integer nΒ β€” the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes.
["572", "3574", "-1"]
#include <stdio.h> #include <stdlib.h> int main() { char str[100000]; scanf("%s",str); int temp,ind,t,i,flag=0; int l=strlen(str); int max=0; int monkey,flag2=0; temp=0; int donkey=str[l-1]-48; for(i=l-2;i>=0;i--) { temp=(int)str[i] -48; if(temp%2==0 ) { if(temp<(donkey)) { monkey=i; flag2=1; } } } if(flag2!=1) { for(i=0;i<l-1;i++) { temp=(int)str[i] -48; if(temp%2==0 ) { flag=1; ind=i; } } } if (flag==1) { t=str[l-1]; str[l-1]=str[ind]; str[ind]=t; printf("%s",str); } if (flag2==1) { t=str[l-1]; str[l-1]=str[monkey]; str[monkey]=t; printf("%s",str); } if(flag2!=1 && flag!=1) { printf("-1"); } return 0; }
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer n. Help Anton to determine the exchange rate of currency you all know for tomorrow!
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print  - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.
C
bc375e27bd52f413216aaecc674366f8
da34834685234c79df138da5a67df34d
GNU C
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "strings" ]
1422376200
["527", "4573", "1357997531"]
null
PASSED
1,300
standard input
0.5 seconds
The first line contains an odd positive integer nΒ β€” the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes.
["572", "3574", "-1"]
#include <stdio.h> #include <string.h> int main() { char a[100000],t; int i,l,b=0,c=0; scanf("%s",a); l=strlen(a); for(i=0;i<l-1;i++) { if(a[i]%2==0) { c=1; break; } } if(c==0) printf("-1"); else { for(i=0;i<l-1;i++) { if(a[i]%2==0 && a[i]<a[l-1]) { b=1; t=a[i]; a[i]=a[l-1]; a[l-1]=t; puts(a); break; } } if(b==0) { for(i=l-2;i>=0;i--) { if(a[i]%2==0) { t=a[i]; a[i]=a[l-1]; a[l-1]=t; puts(a); break; } } } } return 0; }
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer n. Help Anton to determine the exchange rate of currency you all know for tomorrow!
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print  - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.
C
bc375e27bd52f413216aaecc674366f8
e2e1ea5e51d5f02a43a78b7956decc40
GNU C
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "strings" ]
1422376200
["527", "4573", "1357997531"]
null
PASSED
1,300
standard input
0.5 seconds
The first line contains an odd positive integer nΒ β€” the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes.
["572", "3574", "-1"]
#include <stdio.h> #include <stdlib.h> #include <string.h> void swap(char *a, char *b){ char temp=*a; *a=*b; *b=temp; } int main () { char num[100005]; gets(num); int i=0; int length=strlen(num); int flag=-1; int is_found=0; int counter=0; for (i=0;i<length;i++){ if (num[i]%2==0){ is_found=1; if (num[length-1]>num[i]){ counter=1; swap(&num[length-1],&num[i]); break; } else flag=i; } } if (counter==0){ swap(&num[length-1],&num[flag]); } if (is_found==1) printf("%s",num); else printf("-1"); return 0; }
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer n. Help Anton to determine the exchange rate of currency you all know for tomorrow!
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print  - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.
C
bc375e27bd52f413216aaecc674366f8
f95011e195c9e93c74665aa21d16c170
GNU C
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "strings" ]
1422376200
["527", "4573", "1357997531"]
null
PASSED
1,300
standard input
0.5 seconds
The first line contains an odd positive integer nΒ β€” the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes.
["572", "3574", "-1"]
#include<stdio.h> #include<string.h> int main(){ int i=0,z,flag=0,even=0; char str[100002],temp; scanf("%s",str); int size=strlen(str); char x=str[size-1]; for(i=0;i<size;i++){ if(str[i]%2==0){ even=1; if(str[i]<x){ flag=1; str[size-1]=str[i]; str[i]=x; break; } else{ z=i; } } } if(i>=size && even==1){ flag=1; str[size-1] = str[z]; str[z] = x; } if(flag==1){ printf("%s",str); } else printf("-1"); return 0; }
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer n. Help Anton to determine the exchange rate of currency you all know for tomorrow!
If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print  - 1. Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.
C
bc375e27bd52f413216aaecc674366f8
48e78f51ba5659d13865b7ea31d912e2
GNU C
standard output
256 megabytes
train_001.jsonl
[ "greedy", "math", "strings" ]
1422376200
["527", "4573", "1357997531"]
null
PASSED
1,300
standard input
0.5 seconds
The first line contains an odd positive integer nΒ β€” the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes.
["572", "3574", "-1"]
#include<stdio.h> #include<string.h> int main() { char a[1000000],c; scanf("%s",a); int n,i,j,t=0,k,f=-1; n=strlen(a); for(i=0;i<n-1;i++){ if(a[i]%2==0){f=i; if(a[i]<a[n-1]){ c=a[n-1];a[n-1]=a[i];a[i]=c;t=1;break;} } }if(f==-1)printf("-1\n"); else{if(t==0){c=a[n-1];a[n-1]=a[f];a[f]=c;} printf("%s\n",a);} return 0; }
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value. If there are multiple valid solutions, output any of them.
C
f710958b96d788a19a1dda436728b9eb
0116b2ef534ca5bcb249f06925b9f19e
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1461515700
["2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8", "3 3 2\n1 2\n3 2 2 5"]
null
PASSED
1,400
standard input
2 seconds
The first line of the input contains three integers n, m and q (1 ≀ n, m ≀ 100, 1 ≀ q ≀ 10 000)Β β€” dimensions of the matrix and the number of turns in the experiment, respectively. Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≀ ti ≀ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≀ ri ≀ n) or ci (1 ≀ ci ≀ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≀ ri ≀ n, 1 ≀ ci ≀ m,  - 109 ≀ xi ≀ 109) are given. Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
["8 2 \n1 8", "0 0 0 \n0 0 5 \n0 0 0"]
/* practice with Dukkha */ #include <stdio.h> #define N 100 #define M 100 #define Q 10000 int main() { static int tt[Q], rr[Q], cc[Q], xx[Q], aa[N][M]; int n, m, q, h, i, j, a; scanf("%d%d%d", &n, &m, &q); for (h = 0; h < q; h++) { scanf("%d", &tt[h]); if (tt[h] == 1) scanf("%d", &rr[h]), rr[h]--; else if (tt[h] == 2) scanf("%d", &cc[h]), cc[h]--; else scanf("%d%d%d", &rr[h], &cc[h], &xx[h]), rr[h]--, cc[h]--; } for (h = q - 1; h >= 0; h--) if (tt[h] == 1) { i = rr[h], a = aa[i][m - 1]; for (j = m - 1; j > 0; j--) aa[i][j] = aa[i][j - 1]; aa[i][0] = a; } else if (tt[h] == 2) { j = cc[h], a = aa[n - 1][j]; for (i = n - 1; i > 0; i--) aa[i][j] = aa[i - 1][j]; aa[0][j] = a; } else { i = rr[h], j = cc[h]; aa[i][j] = xx[h]; } for (i = 0; i < n; i++) { for (j = 0; j < m; j++) printf("%d ", aa[i][j]); printf("\n"); } return 0; }
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value. If there are multiple valid solutions, output any of them.
C
f710958b96d788a19a1dda436728b9eb
20fbfecdbfd7e0f1cc89e5c3ba56240d
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1461515700
["2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8", "3 3 2\n1 2\n3 2 2 5"]
null
PASSED
1,400
standard input
2 seconds
The first line of the input contains three integers n, m and q (1 ≀ n, m ≀ 100, 1 ≀ q ≀ 10 000)Β β€” dimensions of the matrix and the number of turns in the experiment, respectively. Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≀ ti ≀ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≀ ri ≀ n) or ci (1 ≀ ci ≀ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≀ ri ≀ n, 1 ≀ ci ≀ m,  - 109 ≀ xi ≀ 109) are given. Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
["8 2 \n1 8", "0 0 0 \n0 0 5 \n0 0 0"]
/* https://codeforces.com/contest/668/submission/56857696 (rainboy) */ #include <stdio.h> #define N 100 #define M 100 #define Q 10000 int main() { static int tt[Q], rr[Q], cc[Q], xx[Q], aa[N][M]; int n, m, q, h, i, j; scanf("%d%d%d", &n, &m, &q); for (h = 0; h < q; h++) { scanf("%d", &tt[h]); if (tt[h] == 1) scanf("%d", &rr[h]), rr[h]--; else if (tt[h] == 2) scanf("%d", &cc[h]), cc[h]--; else scanf("%d%d%d", &rr[h], &cc[h], &xx[h]), rr[h]--, cc[h]--; } for (h = q - 1; h >= 0; h--) if (tt[h] == 1) { int a; i = rr[h], a = aa[i][m - 1]; for (j = m - 1; j > 0; j--) aa[i][j] = aa[i][j - 1]; aa[i][0] = a; } else if (tt[h] == 2) { int a; j = cc[h], a = aa[n - 1][j]; for (i = n - 1; i > 0; i--) aa[i][j] = aa[i - 1][j]; aa[0][j] = a; } else { i = rr[h], j = cc[h]; aa[i][j] = xx[h]; } for (i = 0; i < n; i++) { for (j = 0; j < m; j++) printf("%d ", aa[i][j]); printf("\n"); } return 0; }
One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as follows: if a customer's shopping cart contains at least one stool, the customer gets a 50% discount on the cheapest item in the cart (that is, it becomes two times cheaper). If there are several items with the same minimum price, the discount is available for only one of them!Polycarpus has k carts, and he wants to buy up all stools and pencils from the supermarket. Help him distribute the stools and the pencils among the shopping carts, so that the items' total price (including the discounts) is the least possible.Polycarpus must use all k carts to purchase the items, no shopping cart can remain empty. Each shopping cart can contain an arbitrary number of stools and/or pencils.
In the first line print a single real number with exactly one decimal place β€” the minimum total price of the items, including the discounts. In the following k lines print the descriptions of the items in the carts. In the i-th line print the description of the i-th cart as "t b1 b2 ... bt" (without the quotes), where t is the number of items in the i-th cart, and the sequence b1, b2, ..., bt (1 ≀ bj ≀ n) gives the indices of items to put in this cart in the optimal distribution. All indices of items in all carts should be pairwise different, each item must belong to exactly one cart. You can print the items in carts and the carts themselves in any order. The items are numbered from 1 to n in the order in which they are specified in the input. If there are multiple optimal distributions, you are allowed to print any of them.
C
06c7834aa4d06d6fcebfa410054f1b8c
f3d6286c94087b45fac6c6a319f019b4
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "sortings", "greedy" ]
1331478300
["3 2\n2 1\n3 2\n3 1", "4 3\n4 1\n1 2\n2 2\n3 2"]
NoteIn the first sample case the first cart should contain the 1st and 2nd items, and the second cart should contain the 3rd item. This way each cart has a stool and each cart has a 50% discount for the cheapest item. The total price of all items will be: 2Β·0.5 + (3 + 3Β·0.5) = 1 + 4.5 = 5.5.
PASSED
1,700
standard input
3 seconds
The first input line contains two integers n and k (1 ≀ k ≀ n ≀ 103) β€” the number of items in the supermarket and the number of carts, correspondingly. Next n lines describe the items as "ci ti" (without the quotes), where ci (1 ≀ ci ≀ 109) is an integer denoting the price of the i-th item, ti (1 ≀ ti ≀ 2) is an integer representing the type of item i (1 for a stool and 2 for a pencil). The numbers in the lines are separated by single spaces.
["5.5\n2 1 2\n1 3", "8.0\n1 1\n2 4 2\n1 3"]
#include <stdio.h> #include <stdlib.h> typedef struct { int c; int i; } item; int cmp(const void *a, const void *b) { return ((item *)a)->c - ((item *)b)->c; } int d[1000][1000]; int main() { int n, k, p = 0, q = 0, i, j; double sum = 0; item a[1000], b[1000]; int c[1000] = {0}; scanf("%d %d", &n, &k); for (i = 0; i < n; i++) { int x, y; scanf("%d %d", &x, &y); if (y == 1) { a[p].c = x; a[p++].i = i + 1; } else { b[q].c = x; b[q++].i = i + 1; } sum += x; } qsort(a, p, sizeof(item), cmp); qsort(b, q, sizeof(item), cmp); for (i = 0; i < p && i < k; i++) { d[i][c[i]++] = a[p - i - 1].i; if (i < k - 1) sum -= a[p - i - 1].c / 2.0; } for (; i < p; i++) { d[k - 1][c[k - 1]++] = a[p - i - 1].i; } for (i = 0; i < q; i++) { if (i < k && c[k - i - 1] == 0) { d[k - i - 1][c[k - i - 1]++] = b[i].i; } else { d[k - 1][c[k - 1]++] = b[i].i; } } if (p >= k) { int m = a[0].c; if (q > 0 && b[0].c < m) m = b[0].c; sum -= m / 2.0; } printf("%.1lf\n", sum); for (i = 0; i < k; i++) { printf("%d", c[i]); for (j = 0; j < c[i]; j++) printf(" %d", d[i][j]); puts(""); } return 0; }
One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as follows: if a customer's shopping cart contains at least one stool, the customer gets a 50% discount on the cheapest item in the cart (that is, it becomes two times cheaper). If there are several items with the same minimum price, the discount is available for only one of them!Polycarpus has k carts, and he wants to buy up all stools and pencils from the supermarket. Help him distribute the stools and the pencils among the shopping carts, so that the items' total price (including the discounts) is the least possible.Polycarpus must use all k carts to purchase the items, no shopping cart can remain empty. Each shopping cart can contain an arbitrary number of stools and/or pencils.
In the first line print a single real number with exactly one decimal place β€” the minimum total price of the items, including the discounts. In the following k lines print the descriptions of the items in the carts. In the i-th line print the description of the i-th cart as "t b1 b2 ... bt" (without the quotes), where t is the number of items in the i-th cart, and the sequence b1, b2, ..., bt (1 ≀ bj ≀ n) gives the indices of items to put in this cart in the optimal distribution. All indices of items in all carts should be pairwise different, each item must belong to exactly one cart. You can print the items in carts and the carts themselves in any order. The items are numbered from 1 to n in the order in which they are specified in the input. If there are multiple optimal distributions, you are allowed to print any of them.
C
06c7834aa4d06d6fcebfa410054f1b8c
6bac4ce80da4529f13b1986336554a24
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "sortings", "greedy" ]
1331478300
["3 2\n2 1\n3 2\n3 1", "4 3\n4 1\n1 2\n2 2\n3 2"]
NoteIn the first sample case the first cart should contain the 1st and 2nd items, and the second cart should contain the 3rd item. This way each cart has a stool and each cart has a 50% discount for the cheapest item. The total price of all items will be: 2Β·0.5 + (3 + 3Β·0.5) = 1 + 4.5 = 5.5.
PASSED
1,700
standard input
3 seconds
The first input line contains two integers n and k (1 ≀ k ≀ n ≀ 103) β€” the number of items in the supermarket and the number of carts, correspondingly. Next n lines describe the items as "ci ti" (without the quotes), where ci (1 ≀ ci ≀ 109) is an integer denoting the price of the i-th item, ti (1 ≀ ti ≀ 2) is an integer representing the type of item i (1 for a stool and 2 for a pencil). The numbers in the lines are separated by single spaces.
["5.5\n2 1 2\n1 3", "8.0\n1 1\n2 4 2\n1 3"]
//problema9 #include <stdio.h> #include <stdlib.h> typedef struct { int c; int i; } item; int cmp(const void *a, const void *b) { return ((item *)a)->c - ((item *)b)->c; } int d[1000][1000]; int main() { int n, k, p = 0, q = 0, i, j; double sum = 0; item a[1000], b[1000]; int c[1000] = {0}; scanf("%d %d", &n, &k); for (i = 0; i < n; i++) { int x, y; scanf("%d %d", &x, &y); if (y == 1) { a[p].c = x; a[p++].i = i + 1; } else { b[q].c = x; b[q++].i = i + 1; } sum += x; } qsort(a, p, sizeof(item), cmp); qsort(b, q, sizeof(item), cmp); for (i = 0; i < p && i < k; i++) { d[i][c[i]++] = a[p - i - 1].i; if (i < k - 1) sum -= a[p - i - 1].c / 2.0; } for (; i < p; i++) { d[k - 1][c[k - 1]++] = a[p - i - 1].i; } for (i = 0; i < q; i++) { if (i < k && c[k - i - 1] == 0) { d[k - i - 1][c[k - i - 1]++] = b[i].i; } else { d[k - 1][c[k - 1]++] = b[i].i; } } if (p >= k) { int m = a[0].c; if (q > 0 && b[0].c < m) m = b[0].c; sum -= m / 2.0; } printf("%.1lf\n", sum); for (i = 0; i < k; i++) { printf("%d", c[i]); for (j = 0; j < c[i]; j++) printf(" %d", d[i][j]); puts(""); } return 0; }
One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as follows: if a customer's shopping cart contains at least one stool, the customer gets a 50% discount on the cheapest item in the cart (that is, it becomes two times cheaper). If there are several items with the same minimum price, the discount is available for only one of them!Polycarpus has k carts, and he wants to buy up all stools and pencils from the supermarket. Help him distribute the stools and the pencils among the shopping carts, so that the items' total price (including the discounts) is the least possible.Polycarpus must use all k carts to purchase the items, no shopping cart can remain empty. Each shopping cart can contain an arbitrary number of stools and/or pencils.
In the first line print a single real number with exactly one decimal place β€” the minimum total price of the items, including the discounts. In the following k lines print the descriptions of the items in the carts. In the i-th line print the description of the i-th cart as "t b1 b2 ... bt" (without the quotes), where t is the number of items in the i-th cart, and the sequence b1, b2, ..., bt (1 ≀ bj ≀ n) gives the indices of items to put in this cart in the optimal distribution. All indices of items in all carts should be pairwise different, each item must belong to exactly one cart. You can print the items in carts and the carts themselves in any order. The items are numbered from 1 to n in the order in which they are specified in the input. If there are multiple optimal distributions, you are allowed to print any of them.
C
06c7834aa4d06d6fcebfa410054f1b8c
978c16b8cca471a4d4b5238c2cc44e43
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "sortings", "greedy" ]
1331478300
["3 2\n2 1\n3 2\n3 1", "4 3\n4 1\n1 2\n2 2\n3 2"]
NoteIn the first sample case the first cart should contain the 1st and 2nd items, and the second cart should contain the 3rd item. This way each cart has a stool and each cart has a 50% discount for the cheapest item. The total price of all items will be: 2Β·0.5 + (3 + 3Β·0.5) = 1 + 4.5 = 5.5.
PASSED
1,700
standard input
3 seconds
The first input line contains two integers n and k (1 ≀ k ≀ n ≀ 103) β€” the number of items in the supermarket and the number of carts, correspondingly. Next n lines describe the items as "ci ti" (without the quotes), where ci (1 ≀ ci ≀ 109) is an integer denoting the price of the i-th item, ti (1 ≀ ti ≀ 2) is an integer representing the type of item i (1 for a stool and 2 for a pencil). The numbers in the lines are separated by single spaces.
["5.5\n2 1 2\n1 3", "8.0\n1 1\n2 4 2\n1 3"]
#include <stdio.h> #include <stdlib.h> typedef struct { int c; int i; } item; int cmp(const void *a, const void *b) { return ((item *)a)->c - ((item *)b)->c; } int d[1000][1000]; int main() { int n, k, p = 0, q = 0, i, j; double sum = 0; item a[1000], b[1000]; int c[1000] = {0}; scanf("%d %d", &n, &k); for (i = 0; i < n; i++) { int x, y; scanf("%d %d", &x, &y); if (y == 1) { a[p].c = x; a[p++].i = i + 1; } else { b[q].c = x; b[q++].i = i + 1; } sum += x; } qsort(a, p, sizeof(item), cmp); qsort(b, q, sizeof(item), cmp); for (i = 0; i < p && i < k; i++) { d[i][c[i]++] = a[p - i - 1].i; if (i < k - 1) sum -= a[p - i - 1].c / 2.0; } for (; i < p; i++) { d[k - 1][c[k - 1]++] = a[p - i - 1].i; } for (i = 0; i < q; i++) { if (i < k && c[k - i - 1] == 0) { d[k - i - 1][c[k - i - 1]++] = b[i].i; } else { d[k - 1][c[k - 1]++] = b[i].i; } } if (p >= k) { int m = a[0].c; if (q > 0 && b[0].c < m) m = b[0].c; sum -= m / 2.0; } printf("%.1lf\n", sum); for (i = 0; i < k; i++) { printf("%d", c[i]); for (j = 0; j < c[i]; j++) printf(" %d", d[i][j]); puts(""); } return 0; }
One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as follows: if a customer's shopping cart contains at least one stool, the customer gets a 50% discount on the cheapest item in the cart (that is, it becomes two times cheaper). If there are several items with the same minimum price, the discount is available for only one of them!Polycarpus has k carts, and he wants to buy up all stools and pencils from the supermarket. Help him distribute the stools and the pencils among the shopping carts, so that the items' total price (including the discounts) is the least possible.Polycarpus must use all k carts to purchase the items, no shopping cart can remain empty. Each shopping cart can contain an arbitrary number of stools and/or pencils.
In the first line print a single real number with exactly one decimal place β€” the minimum total price of the items, including the discounts. In the following k lines print the descriptions of the items in the carts. In the i-th line print the description of the i-th cart as "t b1 b2 ... bt" (without the quotes), where t is the number of items in the i-th cart, and the sequence b1, b2, ..., bt (1 ≀ bj ≀ n) gives the indices of items to put in this cart in the optimal distribution. All indices of items in all carts should be pairwise different, each item must belong to exactly one cart. You can print the items in carts and the carts themselves in any order. The items are numbered from 1 to n in the order in which they are specified in the input. If there are multiple optimal distributions, you are allowed to print any of them.
C
06c7834aa4d06d6fcebfa410054f1b8c
1116498108f9db651f35e8f0c62909f7
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "sortings", "greedy" ]
1331478300
["3 2\n2 1\n3 2\n3 1", "4 3\n4 1\n1 2\n2 2\n3 2"]
NoteIn the first sample case the first cart should contain the 1st and 2nd items, and the second cart should contain the 3rd item. This way each cart has a stool and each cart has a 50% discount for the cheapest item. The total price of all items will be: 2Β·0.5 + (3 + 3Β·0.5) = 1 + 4.5 = 5.5.
PASSED
1,700
standard input
3 seconds
The first input line contains two integers n and k (1 ≀ k ≀ n ≀ 103) β€” the number of items in the supermarket and the number of carts, correspondingly. Next n lines describe the items as "ci ti" (without the quotes), where ci (1 ≀ ci ≀ 109) is an integer denoting the price of the i-th item, ti (1 ≀ ti ≀ 2) is an integer representing the type of item i (1 for a stool and 2 for a pencil). The numbers in the lines are separated by single spaces.
["5.5\n2 1 2\n1 3", "8.0\n1 1\n2 4 2\n1 3"]
#include <stdio.h> #include <stdlib.h> typedef struct { int c; int i; } item; int cmp(const void *a, const void *b) { return ((item *)a)->c - ((item *)b)->c; } int d[1000][1000]; int main() { int n, k, p, q, i, j; p = 0; q = 0; double sum = 0; item a[1000], b[1000]; int c[1000] = {0}; scanf("%d %d", &n, &k); for (i = 0; i < n; i++) { int x, y; scanf("%d %d", &x, &y); if (y == 1) { a[p].c = x; a[p++].i = i + 1; } else { b[q].c = x; b[q++].i = i + 1; } sum += x; } qsort(a, p, sizeof(item), cmp); qsort(b, q, sizeof(item), cmp); for (i = 0; i < p && i < k; i++) { d[i][c[i]++] = a[p - i - 1].i; if (i < k - 1) sum -= a[p - i - 1].c / 2.0; } for (; i < p; i++) { d[k - 1][c[k - 1]++] = a[p - i - 1].i; } for (i = 0; i < q; i++) { if (i < k && c[k - i - 1] == 0) { d[k - i - 1][c[k - i - 1]++] = b[i].i; } else { d[k - 1][c[k - 1]++] = b[i].i; } } if (p >= k) { int m = a[0].c; if (q > 0 && b[0].c < m) m = b[0].c; sum -= m / 2.0; } printf("%.1lf\n", sum); for (i = 0; i < k; i++) { printf("%d", c[i]); for (j = 0; j < c[i]; j++) printf(" %d", d[i][j]); puts(""); } return 0; }
One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as follows: if a customer's shopping cart contains at least one stool, the customer gets a 50% discount on the cheapest item in the cart (that is, it becomes two times cheaper). If there are several items with the same minimum price, the discount is available for only one of them!Polycarpus has k carts, and he wants to buy up all stools and pencils from the supermarket. Help him distribute the stools and the pencils among the shopping carts, so that the items' total price (including the discounts) is the least possible.Polycarpus must use all k carts to purchase the items, no shopping cart can remain empty. Each shopping cart can contain an arbitrary number of stools and/or pencils.
In the first line print a single real number with exactly one decimal place β€” the minimum total price of the items, including the discounts. In the following k lines print the descriptions of the items in the carts. In the i-th line print the description of the i-th cart as "t b1 b2 ... bt" (without the quotes), where t is the number of items in the i-th cart, and the sequence b1, b2, ..., bt (1 ≀ bj ≀ n) gives the indices of items to put in this cart in the optimal distribution. All indices of items in all carts should be pairwise different, each item must belong to exactly one cart. You can print the items in carts and the carts themselves in any order. The items are numbered from 1 to n in the order in which they are specified in the input. If there are multiple optimal distributions, you are allowed to print any of them.
C
06c7834aa4d06d6fcebfa410054f1b8c
b4c6cec97481efc83dbb032aef41752b
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "sortings", "greedy" ]
1331478300
["3 2\n2 1\n3 2\n3 1", "4 3\n4 1\n1 2\n2 2\n3 2"]
NoteIn the first sample case the first cart should contain the 1st and 2nd items, and the second cart should contain the 3rd item. This way each cart has a stool and each cart has a 50% discount for the cheapest item. The total price of all items will be: 2Β·0.5 + (3 + 3Β·0.5) = 1 + 4.5 = 5.5.
PASSED
1,700
standard input
3 seconds
The first input line contains two integers n and k (1 ≀ k ≀ n ≀ 103) β€” the number of items in the supermarket and the number of carts, correspondingly. Next n lines describe the items as "ci ti" (without the quotes), where ci (1 ≀ ci ≀ 109) is an integer denoting the price of the i-th item, ti (1 ≀ ti ≀ 2) is an integer representing the type of item i (1 for a stool and 2 for a pencil). The numbers in the lines are separated by single spaces.
["5.5\n2 1 2\n1 3", "8.0\n1 1\n2 4 2\n1 3"]
#include<stdio.h> #include<math.h> struct item{ long int precio; int tipo; int entrada; }; typedef struct item item; void quicksort(item v[], int pri, int ult); void bubble(item v[],int n); int cargar(int k, int i); int main(){ int n,i,k,j,col,z; long int menor; double precioDes; scanf("%d",&n); scanf("%d",&k); item v[n]; col=n-k+2; item carrito[k][col]; for(i=0;i<n;i++){ scanf("%d",&v[i].precio); scanf("%d",&v[i].tipo); v[i].entrada=i+1; } quicksort(v, 0, n-1); bubble(v,n); for(i=0;i<k;i++){ for(j=0;j<col;j++){ carrito[i][j].entrada=0; } } z=0; for(i=0;i<k;i++){ carrito[i][1]=v[i]; } z=k; for(i=2;i<col;i++){ for(j=0;j<k;j++){ if(z<n){ if(cargar(k,j)){ carrito[j][i]=v[z]; z++; } } } } for(j=0;j<k;j++){ for(i=1;i<col;i++){ if(carrito[j][i].entrada!=0){ carrito[j][0].entrada++; } } } precioDes=0; for(j=0;j<k;j++){ menor=carrito[j][1].precio; for(i=1;i<col;i++){ if(carrito[j][i].entrada!=0){ if(carrito[j][1].tipo==1){ if(carrito[j][i].precio<=menor){ menor=carrito[j][i].precio; } } precioDes=precioDes+carrito[j][i].precio; } } if(carrito[j][1].tipo==1){ precioDes=precioDes-menor/2.0; } } printf("%.1f\n",precioDes); for(j=0;j<k;j++){ for(i=0;i<col;i++){ if(carrito[j][i].entrada!=0){ printf("%d ",carrito[j][i].entrada); } } printf("\n"); } return 0; } int cargar(int k, int i){ int ban; if(i!=k-1){ ban=0; }else{ ban=1; } return ban; } void quicksort(item v[], int pri, int ult){ int i, j, central,pivote; item aux; central=(pri+ult)/2; pivote=v[central].precio; i=pri; j=ult; do{ while((v[i].precio)>pivote) i++; while((v[j].precio)<pivote) j--; if(i<=j){ aux=v[i]; v[i]=v[j]; v[j]=aux; i++; j--; } }while(i <= j); if(pri<j) quicksort(v,pri,j); if(i<ult) quicksort(v,i,ult); } void bubble(item v[], int n){ int i,j,ban; item aux; ban=1; while(ban>0){ ban=0; for(j=0; j<n-1 ;j++){ if(v[j+1].tipo < v[j].tipo){ aux=v[j]; v[j]=v[j+1]; v[j+1]=aux; ban=1; } } } }
One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as follows: if a customer's shopping cart contains at least one stool, the customer gets a 50% discount on the cheapest item in the cart (that is, it becomes two times cheaper). If there are several items with the same minimum price, the discount is available for only one of them!Polycarpus has k carts, and he wants to buy up all stools and pencils from the supermarket. Help him distribute the stools and the pencils among the shopping carts, so that the items' total price (including the discounts) is the least possible.Polycarpus must use all k carts to purchase the items, no shopping cart can remain empty. Each shopping cart can contain an arbitrary number of stools and/or pencils.
In the first line print a single real number with exactly one decimal place β€” the minimum total price of the items, including the discounts. In the following k lines print the descriptions of the items in the carts. In the i-th line print the description of the i-th cart as "t b1 b2 ... bt" (without the quotes), where t is the number of items in the i-th cart, and the sequence b1, b2, ..., bt (1 ≀ bj ≀ n) gives the indices of items to put in this cart in the optimal distribution. All indices of items in all carts should be pairwise different, each item must belong to exactly one cart. You can print the items in carts and the carts themselves in any order. The items are numbered from 1 to n in the order in which they are specified in the input. If there are multiple optimal distributions, you are allowed to print any of them.
C
06c7834aa4d06d6fcebfa410054f1b8c
7ad67451b80c25d981bc457bc9c884ba
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "sortings", "greedy" ]
1331478300
["3 2\n2 1\n3 2\n3 1", "4 3\n4 1\n1 2\n2 2\n3 2"]
NoteIn the first sample case the first cart should contain the 1st and 2nd items, and the second cart should contain the 3rd item. This way each cart has a stool and each cart has a 50% discount for the cheapest item. The total price of all items will be: 2Β·0.5 + (3 + 3Β·0.5) = 1 + 4.5 = 5.5.
PASSED
1,700
standard input
3 seconds
The first input line contains two integers n and k (1 ≀ k ≀ n ≀ 103) β€” the number of items in the supermarket and the number of carts, correspondingly. Next n lines describe the items as "ci ti" (without the quotes), where ci (1 ≀ ci ≀ 109) is an integer denoting the price of the i-th item, ti (1 ≀ ti ≀ 2) is an integer representing the type of item i (1 for a stool and 2 for a pencil). The numbers in the lines are separated by single spaces.
["5.5\n2 1 2\n1 3", "8.0\n1 1\n2 4 2\n1 3"]
//problema9 #include <stdio.h> #include <stdlib.h> typedef struct { int c; int i; } item; int cmp(const void *a, const void *b) { return ((item *)a)->c - ((item *)b)->c; } int d[1000][1000]; int main() { int n, k, p = 0, q = 0, i, j; double sum = 0; item a[1000], b[1000]; int c[1000] = {0}; scanf("%d %d", &n, &k); for (i = 0; i < n; i++) { int x, y; scanf("%d %d", &x, &y); if (y == 1) { a[p].c = x; a[p++].i = i + 1; } else { b[q].c = x; b[q++].i = i + 1; } sum += x; } qsort(a, p, sizeof(item), cmp); qsort(b, q, sizeof(item), cmp); for (i = 0; i < p && i < k; i++) { d[i][c[i]++] = a[p - i - 1].i; if (i < k - 1) sum -= a[p - i - 1].c / 2.0; } for (; i < p; i++) { d[k - 1][c[k - 1]++] = a[p - i - 1].i; } for (i = 0; i < q; i++) { if (i < k && c[k - i - 1] == 0) { d[k - i - 1][c[k - i - 1]++] = b[i].i; } else { d[k - 1][c[k - 1]++] = b[i].i; } } if (p >= k) { int m = a[0].c; if (q > 0 && b[0].c < m) m = b[0].c; sum -= m / 2.0; } printf("%.1lf\n", sum); for (i = 0; i < k; i++) { printf("%d", c[i]); for (j = 0; j < c[i]; j++) printf(" %d", d[i][j]); puts(""); } return 0; }
One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as follows: if a customer's shopping cart contains at least one stool, the customer gets a 50% discount on the cheapest item in the cart (that is, it becomes two times cheaper). If there are several items with the same minimum price, the discount is available for only one of them!Polycarpus has k carts, and he wants to buy up all stools and pencils from the supermarket. Help him distribute the stools and the pencils among the shopping carts, so that the items' total price (including the discounts) is the least possible.Polycarpus must use all k carts to purchase the items, no shopping cart can remain empty. Each shopping cart can contain an arbitrary number of stools and/or pencils.
In the first line print a single real number with exactly one decimal place β€” the minimum total price of the items, including the discounts. In the following k lines print the descriptions of the items in the carts. In the i-th line print the description of the i-th cart as "t b1 b2 ... bt" (without the quotes), where t is the number of items in the i-th cart, and the sequence b1, b2, ..., bt (1 ≀ bj ≀ n) gives the indices of items to put in this cart in the optimal distribution. All indices of items in all carts should be pairwise different, each item must belong to exactly one cart. You can print the items in carts and the carts themselves in any order. The items are numbered from 1 to n in the order in which they are specified in the input. If there are multiple optimal distributions, you are allowed to print any of them.
C
06c7834aa4d06d6fcebfa410054f1b8c
25f9b3dce2dc6691d771b7dc22de1165
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "sortings", "greedy" ]
1331478300
["3 2\n2 1\n3 2\n3 1", "4 3\n4 1\n1 2\n2 2\n3 2"]
NoteIn the first sample case the first cart should contain the 1st and 2nd items, and the second cart should contain the 3rd item. This way each cart has a stool and each cart has a 50% discount for the cheapest item. The total price of all items will be: 2Β·0.5 + (3 + 3Β·0.5) = 1 + 4.5 = 5.5.
PASSED
1,700
standard input
3 seconds
The first input line contains two integers n and k (1 ≀ k ≀ n ≀ 103) β€” the number of items in the supermarket and the number of carts, correspondingly. Next n lines describe the items as "ci ti" (without the quotes), where ci (1 ≀ ci ≀ 109) is an integer denoting the price of the i-th item, ti (1 ≀ ti ≀ 2) is an integer representing the type of item i (1 for a stool and 2 for a pencil). The numbers in the lines are separated by single spaces.
["5.5\n2 1 2\n1 3", "8.0\n1 1\n2 4 2\n1 3"]
#include <stdio.h> typedef struct art{ int pos; int p; int t; }art; void intercambiar(art * arti1 , art * arti2); void quicksort(art * articulo,int ini,int fin); int main(){ int n,k,x,j; int limite=0,totalc; double s=0; scanf("%d %d",&n,&k); totalc = k; art v[n],aux; for(x=0 ; x<n ; x++){ scanf("%d%d",&v[x].p,&v[x].t); v[x].pos = x+1; } for(x=0;x<n;x++){ if(v[x].t==1){ aux = v[x]; v[x] = v[limite]; v[limite] = aux; limite++; } } quicksort(&v[0],0,limite-1); for(x=0 ; x<n ; x++){ if(v[x].t == 1 && totalc>1){ s = s + (v[x].p*0.5); totalc--; }else if(v[x].t == 1 && totalc == 1){ quicksort(&v[0],x,n-1); s = s + (v[n-1].p*0.5); v[n-1].p = 0; s = s + v[x].p; totalc--; } else{ s = s + v[x].p; } } printf("%.1f\n",s); for(x=0 ; x<n ; x++){ if(k-x == 1){ printf("%d",n-x); for(x=x ; x<n ; x++){ printf(" %d",v[x].pos); } }else{ printf("1 %d\n",v[x].pos); } } return 0; } void quicksort(art * v,int ini,int fin){ int izq,der,piv; piv = v[(ini+fin)/2].p; izq = ini; der = fin; art aux; do{ while(v[izq].p > piv && izq<fin){ izq++; } while(v[der].p < piv && der>ini){ der--; } if(izq<=der){ aux = v[izq]; v[izq] = v[der]; v[der] = aux; izq++; der--; } }while(izq<=der); if(ini < der){ quicksort(v,ini,der); } if(izq<fin){ quicksort(v,izq,fin); } }