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
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well — the one who moves first or the one who moves second.
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
C
bbf2dbdea6dd3aa45250ab5a86833558
7f52f0504484869e4014050a3d46bc5d
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "greedy", "games" ]
1361719800
["aba", "abca"]
null
PASSED
1,300
standard input
2 seconds
The input contains a single line, containing string s (1 ≤ |s|  ≤  103). String s consists of lowercase English letters.
["First", "Second"]
#include<stdio.h> #include<string.h> int no_of_odds(int s[26]); int main() { char str[10001]; scanf("%s",str); int s[26]; for(int i=0;i<26;i++)s[i]=0; int count; int n=strlen(str); for(int i=0;i<n;i++) s[str[i]-'a']+=1; int number=no_of_odds(s); count=0; while(1>0) { if(number==0 && n%2==0) { count%2==0?printf("First"):printf("Second");return 0; } if(number==1 && n%2!=0) { count%2==0?printf("First"):printf("Second");return 0; } for(int i=0;i<26;i++) { if(s[i]%2!=0) { count++; s[i]-=1; n--;number--;break; } } } } int no_of_odds(int s[26]) { int count=0; for(int i=0;i<26;i++) { if(s[i]%2!=0) count++; } return count; }
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well — the one who moves first or the one who moves second.
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
C
bbf2dbdea6dd3aa45250ab5a86833558
fcc809af5172e9741996915b75fde0df
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "greedy", "games" ]
1361719800
["aba", "abca"]
null
PASSED
1,300
standard input
2 seconds
The input contains a single line, containing string s (1 ≤ |s|  ≤  103). String s consists of lowercase English letters.
["First", "Second"]
#include<stdio.h> int main() { char s[1001]={'\0'}; scanf("%s",s); int n=strlen(s),ar[26]={0},even=0,odd=0; for(int i=0;i<n;i++) ar[s[i]-'a']++; for(int i=0;i<26;i++) { if(ar[i]%2==0) even++; else odd++; } if(odd%2!=0||odd==0) printf("First"); else printf("Second"); return 0; }
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well — the one who moves first or the one who moves second.
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
C
bbf2dbdea6dd3aa45250ab5a86833558
606bfb805214eedd1a66076dbcec2dd7
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "greedy", "games" ]
1361719800
["aba", "abca"]
null
PASSED
1,300
standard input
2 seconds
The input contains a single line, containing string s (1 ≤ |s|  ≤  103). String s consists of lowercase English letters.
["First", "Second"]
#include <stdio.h> #include <string.h> #define sz 1001 int a[130],b[130]; int main () { char s[sz]; int i,j,len,count=0; scanf("%s",s); len=strlen(s); for (i=0; i<len; i++) a[s[i]]++; int sum; while (1) { sum=0; count++; for (i='a'; i<='z'; i++) { b[i]=a[i]%2; sum=sum+b[i]; } if (len%2==1 && sum==1) break; if (len%2==0 && sum==0) break; int f=1; for (i='a'; i<='z'; i++) { if (a[i]%2==1) { f=0; a[i]--; break; } } len--; } if (count%2) printf("First\n"); else printf("Second\n"); return 0; }
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well — the one who moves first or the one who moves second.
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
C
bbf2dbdea6dd3aa45250ab5a86833558
4c7c0434f299ad11e79a9520e17e3a1b
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "greedy", "games" ]
1361719800
["aba", "abca"]
null
PASSED
1,300
standard input
2 seconds
The input contains a single line, containing string s (1 ≤ |s|  ≤  103). String s consists of lowercase English letters.
["First", "Second"]
#include <stdio.h> #include <string.h> #define sz 1001 int a[130],b[130]; int main () { char s[sz]; int i,j,len,count=0; scanf("%s",s); len=strlen(s); for (i=0; i<len; i++) a[s[i]]++; int sum=0; for (i='a'; i<='z'; i++) sum+=(a[i]%2); if (sum==0 || sum%2) printf("First\n"); else printf("Second\n"); return 0; }
The Little Girl loves problems on games very much. Here's one of them.Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: The players move in turns; In one move the player can remove an arbitrary letter from string s. If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't. Determine which player will win, provided that both sides play optimally well — the one who moves first or the one who moves second.
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
C
bbf2dbdea6dd3aa45250ab5a86833558
d9407b0831f37f97f8ad66093d8fa60a
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "greedy", "games" ]
1361719800
["aba", "abca"]
null
PASSED
1,300
standard input
2 seconds
The input contains a single line, containing string s (1 ≤ |s|  ≤  103). String s consists of lowercase English letters.
["First", "Second"]
#include<stdio.h> #include<string.h> int main() { int no,ii,sum=0,a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0; int q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0,y=0,z=0; char S[1001]; scanf("%s",&S); no=strlen(S); for(ii=0; ii<no; ii++) { if(S[ii]=='a') { a++; } else if(S[ii]=='b') { b++; } else if(S[ii]=='c') { c++; } else if(S[ii]=='d') { d++; } else if(S[ii]=='e') { e++; } else if(S[ii]=='f') { f++; } else if(S[ii]=='g') { g++; } else if(S[ii]=='h') { h++; } else if(S[ii]=='i') { i++; } else if(S[ii]=='j') { j++; } else if(S[ii]=='k') { k++; } else if(S[ii]=='l') { l++; } else if(S[ii]=='m') { m++; } else if(S[ii]=='n') { n++; } else if(S[ii]=='o') { o++; } else if(S[ii]=='p') { p++; } else if(S[ii]=='q') { q++; } else if(S[ii]=='r') { r++; } else if(S[ii]=='s') { s++; } else if(S[ii]=='t') { t++; } else if(S[ii]=='u') { u++; } else if(S[ii]=='v') { v++; } else if(S[ii]=='w') { w++; } else if(S[ii]=='x') { x++; } else if(S[ii]=='y') { y++; } else if(S[ii]=='z') { z++; } } if(a%2==1) { sum++; } if(b%2==1) { sum++; } if(c%2==1) { sum++; } if(d%2==1) { sum++; } if(e%2==1) { sum++; } if(f%2==1) { sum++; } if(g%2==1) { sum++; } if(h%2==1) { sum++; } if(i%2==1) { sum++; } if(j%2==1) { sum++; } if(k%2==1) { sum++; } if(l%2==1) { sum++; } if(m%2==1) { sum++; } if(n%2==1) { sum++; } if(o%2==1) { sum++; } if(p%2==1) { sum++; } if(q%2==1) { sum++; } if(r%2==1) { sum++; } if(s%2==1) { sum++; } if(t%2==1) { sum++; } if(u%2==1) { sum++; } if(v%2==1) { sum++; } if(w%2==1) { sum++; } if(x%2==1) { sum++; } if(y%2==1) { sum++; } if(z%2==1) { sum++; } if(sum==0||sum%2==1) { printf("First\n"); } else { printf("Second\n"); } return 0; }
Polycarpus got hold of a family relationship tree. The tree describes family relationships of n people, numbered 1 through n. Each person in the tree has no more than one parent.Let's call person a a 1-ancestor of person b, if a is the parent of b.Let's call person a a k-ancestor (k &gt; 1) of person b, if person b has a 1-ancestor, and a is a (k - 1)-ancestor of b's 1-ancestor. Family relationships don't form cycles in the found tree. In other words, there is no person who is his own ancestor, directly or indirectly (that is, who is an x-ancestor for himself, for some x, x &gt; 0).Let's call two people x and y (x ≠ y) p-th cousins (p &gt; 0), if there is person z, who is a p-ancestor of x and a p-ancestor of y.Polycarpus wonders how many counsins and what kinds of them everybody has. He took a piece of paper and wrote m pairs of integers vi, pi. Help him to calculate the number of pi-th cousins that person vi has, for each pair vi, pi.
Print m space-separated integers — the answers to Polycarpus' queries. Print the answers to the queries in the order, in which the queries occur in the input.
C
ce58d35343d66b962fb23b9963783acf
83772871bebf306963d1801c5c80c36b
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "data structures", "binary search", "dfs and similar", "trees" ]
1343057400
["6\n0 1 1 0 4 4\n7\n1 1\n1 2\n2 1\n2 2\n4 1\n5 1\n6 1"]
null
PASSED
2,100
standard input
2 seconds
The first input line contains a single integer n (1 ≤ n ≤ 105) — the number of people in the tree. The next line contains n space-separated integers r1, r2, ..., rn, where ri (1 ≤ ri ≤ n) is the number of person i's parent or 0, if person i has no parent. It is guaranteed that family relationships don't form cycles. The third line contains a single number m (1 ≤ m ≤ 105) — the number of family relationship queries Polycarus has. Next m lines contain pairs of space-separated integers. The i-th line contains numbers vi, pi (1 ≤ vi, pi ≤ n).
["0 0 1 0 0 1 1"]
/* practice with Dukkha */ #include <stdio.h> #include <stdlib.h> #include <sys/time.h> #define N 100000 #define LN 16 /* LN = floor(log2(N - 1)) */ 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 next[1 + N - 1], jj[1 + N - 1]; int link(int l, int j) { static int _ = 1; next[_] = l; jj[_] = j; return _++; } int ao[N], dd[N], pp[LN + 1][N], ll[N], rr[N]; void dfs(int i, int d) { static int time; int h, l; ll[i] = time++; dd[i] = d; for (h = 1; 1 << h <= d; h++) pp[h][i] = pp[h - 1][pp[h - 1][i]]; for (l = ao[i]; l; l = next[l]) { int j = jj[l]; dfs(j, d + 1); } rr[i] = time; } int compare(const void *a, const void *b) { int i = *(int *) a; int j = *(int *) b; return dd[i] != dd[j] ? dd[i] - dd[j] : ll[i] - ll[j]; } void sort(int *aa, int n) { int i; for (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 ii[N]; int find(int d, int l, int n) { int lower = -1, upper = n; while (upper - lower > 1) { int i = (lower + upper) / 2; int i_ = ii[i]; if (dd[i_] < d || dd[i_] == d && ll[i_] < l) lower = i; else upper = i; } return lower; } int main() { int n, m, i; srand_(); scanf("%d", &n); for (i = 0; i < n; i++) { int p; scanf("%d", &p), p--; pp[0][i] = p; if (p != -1) ao[p] = link(ao[p], i); ii[i] = i; } for (i = 0; i < n; i++) if (pp[0][i] == -1) dfs(i, 0); sort(ii, n); scanf("%d", &m); while (m--) { int d, d_, ans; scanf("%d%d", &i, &d), i--; ans = 0; d_ = dd[i]; if (d_ >= d) { int h; for (h = LN; h >= 0; h--) if (1 << h <= d) { i = pp[h][i]; d -= 1 << h; } ans = find(d_, rr[i], n) - find(d_, ll[i], n) - 1; } printf("%d ", ans); } printf("\n"); return 0; }
You are given two polynomials: P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm. Calculate limit .
If the limit equals  + ∞, print "Infinity" (without quotes). If the limit equals  - ∞, print "-Infinity" (without the quotes). If the value of the limit equals zero, print "0/1" (without the quotes). Otherwise, print an irreducible fraction — the value of limit , in the format "p/q" (without the quotes), where p is the — numerator, q (q &gt; 0) is the denominator of the fraction.
C
37cf6edce77238db53d9658bc92b2cab
daf77a2b0e594e59c3ae3bcb16463124
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1339506000
["2 1\n1 1 1\n2 5", "1 0\n-1 3\n2", "0 1\n1\n1 0", "2 2\n2 1 6\n4 5 -7", "1 1\n9 0\n-5 2"]
NoteLet's consider all samples: You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function
PASSED
1,400
standard input
2 seconds
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly. The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0). The third line contains m + 1 space-separated integers — the factors of polynomial Q(x): b0, b1, ..., bm - 1, bm ( - 100 ≤ bi ≤ 100, b0 ≠ 0).
["Infinity", "-Infinity", "0/1", "1/2", "-9/5"]
/* #include <stdio.h> int main() { int n, m, i; scanf("%d%d", &n, &m); int ara1[n+1], ara2[m+1]; for(i = 0;i <n+1; i++){ scanf("%d", &ara1[i]); } for(i = 0; i <m+1; i++){ scanf("%d", &ara2[i]); } if(n>m && n*m>=0){ printf("Infinity"); } else if(n>m && n*m<0){ printf("-Infinity"); } else if(m>n){ printf("0/1"); } if(m==n){ for(i = 1; ) } } */ #include <stdio.h> int main () { int i,n,m,j,a[200],b[200],min,flag=0; scanf("%d %d",&n,&m); for(i=0;i<=n;i++) { scanf("%d",&a[i]); } for(i=0;i<=m;i++) { scanf("%d",&b[i]); } if(n>m) { if(a[0]*b[0]<1) { printf("-Infinity\n"); } else{ printf("Infinity\n"); } return 0; } else if(n<m) { printf("0/1\n"); return 0; } if(a[0]*b[0]<0) { flag=1; } a[0]=abs(a[0]); b[0]=abs(b[0]); if(a[0]>b[0]){ min=b[0]; } else{ min=a[0]; } for(i=min,j=1;i>=1;j++) { i=min/j; if(i<1) { break; } if(a[0]%i==0 && b[0]%i==0) { if(flag==1) { printf("-%d/%d\n",a[0]/i,b[0]/i); break; } printf("%d/%d\n",a[0]/i,b[0]/i); break; } } return 0; }
You are given two polynomials: P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm. Calculate limit .
If the limit equals  + ∞, print "Infinity" (without quotes). If the limit equals  - ∞, print "-Infinity" (without the quotes). If the value of the limit equals zero, print "0/1" (without the quotes). Otherwise, print an irreducible fraction — the value of limit , in the format "p/q" (without the quotes), where p is the — numerator, q (q &gt; 0) is the denominator of the fraction.
C
37cf6edce77238db53d9658bc92b2cab
905d214df4e7ac99b6a3bbdd03d5fab3
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1339506000
["2 1\n1 1 1\n2 5", "1 0\n-1 3\n2", "0 1\n1\n1 0", "2 2\n2 1 6\n4 5 -7", "1 1\n9 0\n-5 2"]
NoteLet's consider all samples: You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function
PASSED
1,400
standard input
2 seconds
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly. The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0). The third line contains m + 1 space-separated integers — the factors of polynomial Q(x): b0, b1, ..., bm - 1, bm ( - 100 ≤ bi ≤ 100, b0 ≠ 0).
["Infinity", "-Infinity", "0/1", "1/2", "-9/5"]
#include <stdio.h> #include <math.h> int main() { int n,m,min,u,y; scanf("%d %d",&n,&m); int a[n+1]; int i,j,k,l; for(i=1;i<=(n+1);i++) { scanf("%d",&a[i]); } int b[m+1]; for(i=1;i<=(m+1);i++) scanf("%d",&b[i]); if(n>m) { if((a[1]<0 && b[1]>0) ||(b[1]<0 && a[1]>0)) printf("-Infinity"); else printf("Infinity"); } else if(n<m) { printf("0/1"); } else { j=abs(a[1]); k=abs(b[1]); if(j<k) min=k; else min=j; for(u=1;u<=min;u++) { if(j%u==0 && k%u==0) { y=u; } } j/=y; k/=y; if((a[1]>0 && b[1]>0)|| (a[1]<0 && b[1]<0)) { printf("%d/%d",j,k); } else printf("-%d/%d",j,k); } }
You are given two polynomials: P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm. Calculate limit .
If the limit equals  + ∞, print "Infinity" (without quotes). If the limit equals  - ∞, print "-Infinity" (without the quotes). If the value of the limit equals zero, print "0/1" (without the quotes). Otherwise, print an irreducible fraction — the value of limit , in the format "p/q" (without the quotes), where p is the — numerator, q (q &gt; 0) is the denominator of the fraction.
C
37cf6edce77238db53d9658bc92b2cab
d223ab0e3e452b889cbc383280e042e6
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1339506000
["2 1\n1 1 1\n2 5", "1 0\n-1 3\n2", "0 1\n1\n1 0", "2 2\n2 1 6\n4 5 -7", "1 1\n9 0\n-5 2"]
NoteLet's consider all samples: You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function
PASSED
1,400
standard input
2 seconds
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly. The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0). The third line contains m + 1 space-separated integers — the factors of polynomial Q(x): b0, b1, ..., bm - 1, bm ( - 100 ≤ bi ≤ 100, b0 ≠ 0).
["Infinity", "-Infinity", "0/1", "1/2", "-9/5"]
#include<stdio.h> main() { int n,m,s1,s2,flag=0; scanf("%d %d",&n, &m); int a[n+1], b[m+1],i; for(i=0; i<=n; i++) { scanf("%d",&a[i]); } for(i=0; i<=m; i++) { scanf("%d",&b[i]); } if(n>m) { if((a[0]<0 && b[0]<0) || (a[0]>=0 && b[0]>=0)) printf("Infinity"); else printf("-Infinity"); } else if(m>n) printf("0/1"); else { if(a[0]<0 && b[0]<0) { flag=0; a[0]=abs(a[0]); b[0]=abs(b[0]); } else if(a[0]<0 || b[0]<0) { flag=1; a[0]=abs(a[0]); b[0]=abs(b[0]); } s1=a[0]; s2=b[0]; if(n!=m) { while(n>0) { s1=s1*n; n--; } while(m>0) { s2=s2*m; m--; } } if(s1>s2) { i=2; while(i<=s2) { if(s2%i==0 && s1%i==0) { s2/=i; s1/=i; i=2; } else i++; } } else if(s2>s1) { i=2; while(i<=s1) { if(s2%i==0 && s1%i==0) { s2/=i; s1/=i; i=2; } else i++; } } else { s1=1; s2=1; } if(flag==1) printf("-"); printf("%d/%d",s1,s2); } }
You are given two polynomials: P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm. Calculate limit .
If the limit equals  + ∞, print "Infinity" (without quotes). If the limit equals  - ∞, print "-Infinity" (without the quotes). If the value of the limit equals zero, print "0/1" (without the quotes). Otherwise, print an irreducible fraction — the value of limit , in the format "p/q" (without the quotes), where p is the — numerator, q (q &gt; 0) is the denominator of the fraction.
C
37cf6edce77238db53d9658bc92b2cab
ff8b6986a96cb3a195def9c990869f73
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1339506000
["2 1\n1 1 1\n2 5", "1 0\n-1 3\n2", "0 1\n1\n1 0", "2 2\n2 1 6\n4 5 -7", "1 1\n9 0\n-5 2"]
NoteLet's consider all samples: You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function
PASSED
1,400
standard input
2 seconds
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly. The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0). The third line contains m + 1 space-separated integers — the factors of polynomial Q(x): b0, b1, ..., bm - 1, bm ( - 100 ≤ bi ≤ 100, b0 ≠ 0).
["Infinity", "-Infinity", "0/1", "1/2", "-9/5"]
#include <stdio.h> #include <math.h> int gcd(int e,int f){ e=e>0?e:(-1)*e; f=f>0?f:(-1)*f; while(e!=f){ if (e<f){ f-=e; } else { e-=f; } } return e; } int main() { int n,m,a,b,x,y,i,e,f,g; scanf("%d%d",&n,&m); for (i=0;i<=n;i++){ scanf("%d",&a); if (i==0){ x=a; } } for (i=0;i<=n;i++){ scanf("%d",&b); if (i==0){ y=b; } } if (n==m){ g=gcd(x,y); if (x*y>0){ printf ("%d/%d",abs(x/g),abs(y/g)); } else { printf ("-%d/%d",abs(x/g),abs(y/g)); } } else if (n>m){ if (x*y>0){ printf ("Infinity"); } else { printf ("-Infinity"); } } else { printf ("0/1"); } return 0; }
You are given two polynomials: P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm. Calculate limit .
If the limit equals  + ∞, print "Infinity" (without quotes). If the limit equals  - ∞, print "-Infinity" (without the quotes). If the value of the limit equals zero, print "0/1" (without the quotes). Otherwise, print an irreducible fraction — the value of limit , in the format "p/q" (without the quotes), where p is the — numerator, q (q &gt; 0) is the denominator of the fraction.
C
37cf6edce77238db53d9658bc92b2cab
84e16c325d4ac2fcb8c4522347ba4b4e
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1339506000
["2 1\n1 1 1\n2 5", "1 0\n-1 3\n2", "0 1\n1\n1 0", "2 2\n2 1 6\n4 5 -7", "1 1\n9 0\n-5 2"]
NoteLet's consider all samples: You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function
PASSED
1,400
standard input
2 seconds
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly. The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0). The third line contains m + 1 space-separated integers — the factors of polynomial Q(x): b0, b1, ..., bm - 1, bm ( - 100 ≤ bi ≤ 100, b0 ≠ 0).
["Infinity", "-Infinity", "0/1", "1/2", "-9/5"]
#include <stdio.h> int gcd(int big, int small) { int tmp = 1; while(tmp > 0) { tmp = big % small; big = small, small = tmp; } return big; } int abs(int x) { if(x > 0) return x; return -x; } int main() { int n, m; scanf("%d%d", &n, &m); int a, b, tmp; scanf("%d", &a); for(int i = 1; i <= n; i++) scanf("%d", &tmp); scanf("%d", &b); for(int i = 1; i <= m; i++) scanf("%d", &tmp); if(n > m) { if(a*b > 0) puts("Infinity"); else puts("-Infinity"); return 0; } else if(n < m) { puts("0/1"); return 0; } int x; if(abs(a) > abs(b)) x = gcd(abs(a), abs(b)); else x = gcd(abs(b), abs(a)); printf("%c%d/%d\n", (a*b<0)?'-':' ', abs(a) / x, abs(b) / x); }
You are given two polynomials: P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm. Calculate limit .
If the limit equals  + ∞, print "Infinity" (without quotes). If the limit equals  - ∞, print "-Infinity" (without the quotes). If the value of the limit equals zero, print "0/1" (without the quotes). Otherwise, print an irreducible fraction — the value of limit , in the format "p/q" (without the quotes), where p is the — numerator, q (q &gt; 0) is the denominator of the fraction.
C
37cf6edce77238db53d9658bc92b2cab
32f1007889a2515adac5a91d68f3a6d6
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1339506000
["2 1\n1 1 1\n2 5", "1 0\n-1 3\n2", "0 1\n1\n1 0", "2 2\n2 1 6\n4 5 -7", "1 1\n9 0\n-5 2"]
NoteLet's consider all samples: You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function
PASSED
1,400
standard input
2 seconds
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly. The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0). The third line contains m + 1 space-separated integers — the factors of polynomial Q(x): b0, b1, ..., bm - 1, bm ( - 100 ≤ bi ≤ 100, b0 ≠ 0).
["Infinity", "-Infinity", "0/1", "1/2", "-9/5"]
#include <stdio.h> #include <stdlib.h> #include <string.h> int gcd(int a, int b) { int r; while(b) { r=a%b; a=b; b=r; } return a; } int main() { int d1, d2, f1, f2, x; scanf("%d%d",&d1,&d2); for(int i=0;i<=d1;i++) { scanf("%d",&x); if(!i) f1=x; } for(int i=0;i<=d2;i++) { scanf("%d",&x); if(!i) f2=x; } if(d1>d2) { if(f1*f2>0) printf("Infinity"); else printf("-Infinity"); } else if(d1<d2) printf("0/1"); else { if(f1*f2<0) printf("-"); f1=abs(f1); f2=abs(f2); int common=gcd(f1,f2); printf("%d/%d",f1/common,f2/common); } return 0; }
You are given two polynomials: P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm. Calculate limit .
If the limit equals  + ∞, print "Infinity" (without quotes). If the limit equals  - ∞, print "-Infinity" (without the quotes). If the value of the limit equals zero, print "0/1" (without the quotes). Otherwise, print an irreducible fraction — the value of limit , in the format "p/q" (without the quotes), where p is the — numerator, q (q &gt; 0) is the denominator of the fraction.
C
37cf6edce77238db53d9658bc92b2cab
44f6218606e5e8a413c1963ead1c8338
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1339506000
["2 1\n1 1 1\n2 5", "1 0\n-1 3\n2", "0 1\n1\n1 0", "2 2\n2 1 6\n4 5 -7", "1 1\n9 0\n-5 2"]
NoteLet's consider all samples: You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function
PASSED
1,400
standard input
2 seconds
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly. The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0). The third line contains m + 1 space-separated integers — the factors of polynomial Q(x): b0, b1, ..., bm - 1, bm ( - 100 ≤ bi ≤ 100, b0 ≠ 0).
["Infinity", "-Infinity", "0/1", "1/2", "-9/5"]
#include <stdio.h> #include <stdlib.h> int gcd(int a, int b) { int r; while(b != 0) { r = a % b; a = b; b = r; } return a; } int main() { int n, m; int deg1, deg2; scanf("%d %d", &n, &m); for(int i = 0, a; i <= n; i++) { scanf("%d", &a); if(i == 0) deg1 = a; } for(int i = 0, a; i <= m; i++) { scanf("%d", &a); if(i == 0) deg2 = a; } if(n > m) { if(deg1 > 0 && deg2 > 0 || (deg1 < 0 && deg2 < 0)) printf("Infinity"); else printf("-Infinity"); } else if(m > n) printf("0/1"); else { while(gcd(deg1, deg2) != 1) { int r = gcd(deg1, deg2); deg1 /= r; deg2 /= r; } if(deg1 < 0 && deg2 < 0 || (deg1 > 0 && deg2 > 0)) printf("%d/%d", deg1, deg2); else printf("-%d/%d", abs(deg1), abs(deg2)); } return 0; }
You are given two polynomials: P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm. Calculate limit .
If the limit equals  + ∞, print "Infinity" (without quotes). If the limit equals  - ∞, print "-Infinity" (without the quotes). If the value of the limit equals zero, print "0/1" (without the quotes). Otherwise, print an irreducible fraction — the value of limit , in the format "p/q" (without the quotes), where p is the — numerator, q (q &gt; 0) is the denominator of the fraction.
C
37cf6edce77238db53d9658bc92b2cab
641566cc4a88675f4f56e9d899101c2c
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1339506000
["2 1\n1 1 1\n2 5", "1 0\n-1 3\n2", "0 1\n1\n1 0", "2 2\n2 1 6\n4 5 -7", "1 1\n9 0\n-5 2"]
NoteLet's consider all samples: You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function
PASSED
1,400
standard input
2 seconds
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly. The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0). The third line contains m + 1 space-separated integers — the factors of polynomial Q(x): b0, b1, ..., bm - 1, bm ( - 100 ≤ bi ≤ 100, b0 ≠ 0).
["Infinity", "-Infinity", "0/1", "1/2", "-9/5"]
#include <stdio.h> #include <math.h> int main() { int m,n,i,c; int a[110],b[110]; scanf("%d%d",&m,&n); for(i=0;i<=m;i++) { scanf("%d",&a[i]); } for(i=0;i<=n;i++) { scanf("%d",&b[i]); } if(m<n) printf("0/1\n"); else if(m>n) { if(a[0]>0&&b[0]>0||a[0]<0&&b[0]<0) printf("Infinity\n"); else printf("-Infinity\n"); } else { c=abs(a[0])>abs(b[0])?abs(b[0]):abs(a[0]); for(i=2;i<=c;i++) { if(a[0]%i==0&&b[0]%i==0) { a[0]/=i; b[0]/=i; i=1; c=abs(a[0])>abs(b[0])?abs(b[0]):abs(a[0]); } } if(a[0]>0&&b[0]>0) printf("%d/%d",a[0],b[0]); else if(a[0]<0&&b[0]<0) printf("%d/%d",a[0]*-1,b[0]*-1); else if(a[0]>0&&b[0]<0) printf("-%d/%d",a[0],b[0]*-1); else printf("%d/%d",a[0],b[0]); } return 0; }
You are given two polynomials: P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm. Calculate limit .
If the limit equals  + ∞, print "Infinity" (without quotes). If the limit equals  - ∞, print "-Infinity" (without the quotes). If the value of the limit equals zero, print "0/1" (without the quotes). Otherwise, print an irreducible fraction — the value of limit , in the format "p/q" (without the quotes), where p is the — numerator, q (q &gt; 0) is the denominator of the fraction.
C
37cf6edce77238db53d9658bc92b2cab
5cb7d9ea201c635749a434948b976d53
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1339506000
["2 1\n1 1 1\n2 5", "1 0\n-1 3\n2", "0 1\n1\n1 0", "2 2\n2 1 6\n4 5 -7", "1 1\n9 0\n-5 2"]
NoteLet's consider all samples: You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function
PASSED
1,400
standard input
2 seconds
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly. The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0). The third line contains m + 1 space-separated integers — the factors of polynomial Q(x): b0, b1, ..., bm - 1, bm ( - 100 ≤ bi ≤ 100, b0 ≠ 0).
["Infinity", "-Infinity", "0/1", "1/2", "-9/5"]
#include <stdio.h> #include <math.h> int main() { int m,n,i,c,d,y; int a[110],b[110]; scanf("%d%d",&m,&n); for(i=0;i<=m;i++) { scanf("%d",&a[i]); } for(i=0;i<=n;i++) { scanf("%d",&b[i]); } if(m>n) { if(b[0]<0&&a[0]>0||a[0]<0&&b[0]>0) printf("-Infinity"); else printf("Infinity"); } else if(m<n) { printf("0/1"); } else if(m==n) { c=a[0]; d=b[0]; if(a[0]<0) a[0]*=-1; if(b[0]<0) b[0]*=-1; y=a[0]<b[0]?a[0]:b[0]; for(i=2;i<=y;i++) { if(a[0]%i==0&&b[0]%i==0) { a[0]=a[0]/i; b[0]=b[0]/i; y=a[0]<b[0]?a[0]:b[0]; i=1; } } if(c<0&&d>0||c>0&&d<0) printf("-%d/%d",a[0],b[0]); else printf("%d/%d",a[0],b[0]); } return 0; }
You are given two polynomials: P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm. Calculate limit .
If the limit equals  + ∞, print "Infinity" (without quotes). If the limit equals  - ∞, print "-Infinity" (without the quotes). If the value of the limit equals zero, print "0/1" (without the quotes). Otherwise, print an irreducible fraction — the value of limit , in the format "p/q" (without the quotes), where p is the — numerator, q (q &gt; 0) is the denominator of the fraction.
C
37cf6edce77238db53d9658bc92b2cab
6f04436b01f8497b8580788c531489a8
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1339506000
["2 1\n1 1 1\n2 5", "1 0\n-1 3\n2", "0 1\n1\n1 0", "2 2\n2 1 6\n4 5 -7", "1 1\n9 0\n-5 2"]
NoteLet's consider all samples: You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function
PASSED
1,400
standard input
2 seconds
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly. The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0). The third line contains m + 1 space-separated integers — the factors of polynomial Q(x): b0, b1, ..., bm - 1, bm ( - 100 ≤ bi ≤ 100, b0 ≠ 0).
["Infinity", "-Infinity", "0/1", "1/2", "-9/5"]
#include <stdio.h> #include <stdlib.h> int n,m,p[101],q[101],i,cmmd; int cmmdc(int x,int y) { int r; while(y!=0) { r=x%y; x=y; y=r; } return x; } int main() { scanf("%d %d",&n,&m); for(i=0;i<=n;i++) scanf("%d",&p[i]); for(i=0;i<=m;i++) scanf("%d",&q[i]); if(n>m) { if(p[0]<0 && q[0]>0 || p[0]>0 && q[0]<0 ) printf("-Infinity"); else printf("Infinity"); } else if(n<m) printf("0/1"); else { if(p[0]>0 && q[0]>0 || p[0]<0 && q[0]<0) { cmmd=cmmdc(p[0],q[0]); p[0]=p[0]/cmmd; q[0]=q[0]/cmmd; printf("%d/%d",p[0],q[0]); } else { if(p[0]<0) p[0]=p[0]*(-1); if(q[0]<0) q[0]=q[0]*(-1); cmmd=cmmdc(p[0],q[0]); p[0]=p[0]/cmmd; q[0]=q[0]/cmmd; printf("-%d/%d",p[0],q[0]); } } }
There are $$$n$$$ products in the shop. The price of the $$$i$$$-th product is $$$a_i$$$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.In fact, the owner of the shop can change the price of some product $$$i$$$ in such a way that the difference between the old price of this product $$$a_i$$$ and the new price $$$b_i$$$ is at most $$$k$$$. In other words, the condition $$$|a_i - b_i| \le k$$$ should be satisfied ($$$|x|$$$ is the absolute value of $$$x$$$).He can change the price for each product not more than once. Note that he can leave the old prices for some products. The new price $$$b_i$$$ of each product $$$i$$$ should be positive (i.e. $$$b_i &gt; 0$$$ should be satisfied for all $$$i$$$ from $$$1$$$ to $$$n$$$).Your task is to find out the maximum possible equal price $$$B$$$ of all productts with the restriction that for all products the condiion $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the same new price of all products) or report that it is impossible to find such price $$$B$$$.Note that the chosen price $$$B$$$ should be integer.You should answer $$$q$$$ independent queries.
Print $$$q$$$ integers, where the $$$i$$$-th integer is the answer $$$B$$$ on the $$$i$$$-th query. If it is impossible to equalize prices of all given products with restriction that for all products the condition $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the new equal price of all products), print -1. Otherwise print the maximum possible equal price of all products.
C
3b158306d335459ff55dcf29e46010e8
b2e62aacb6734f613c16b19bedd48295
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1561559700
["4\n5 1\n1 1 2 3 1\n4 2\n6 4 8 5\n2 2\n1 6\n3 5\n5 2 5"]
NoteIn the first example query you can choose the price $$$B=2$$$. It is easy to see that the difference between each old price and each new price $$$B=2$$$ is no more than $$$1$$$.In the second example query you can choose the price $$$B=6$$$ and then all the differences between old and new price $$$B=6$$$ will be no more than $$$2$$$.In the third example query you cannot choose any suitable price $$$B$$$. For any value $$$B$$$ at least one condition out of two will be violated: $$$|1-B| \le 2$$$, $$$|6-B| \le 2$$$.In the fourth example query all values $$$B$$$ between $$$1$$$ and $$$7$$$ are valid. But the maximum is $$$7$$$, so it's the answer.
PASSED
900
standard input
1 second
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is presented by two lines. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100, 1 \le k \le 10^8$$$) — the number of products and the value $$$k$$$. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^8$$$), where $$$a_i$$$ is the price of the $$$i$$$-th product.
["2\n6\n-1\n7"]
#include <stdio.h> int main() {int T,m; scanf("%d",&T); for(m=0;m<T;m++){ int N,k,i,j,l,min,max,price; scanf("%d%d",&N,&k); int A[N]; for(i=0;i<N;i++) { scanf("%d",&A[i]); } min=A[0]; for(j=1;j<N;j++) { if(A[j]<min) { min=A[j]; } } max=A[N-1]; for(l=(N-1);l>=0;l--) { if(A[l]>max) { max=A[l]; } } //now i have min and max price=min+k; if(price>=max-k) { printf("%d\n",price); } else printf("-1\n"); } }
There are $$$n$$$ products in the shop. The price of the $$$i$$$-th product is $$$a_i$$$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.In fact, the owner of the shop can change the price of some product $$$i$$$ in such a way that the difference between the old price of this product $$$a_i$$$ and the new price $$$b_i$$$ is at most $$$k$$$. In other words, the condition $$$|a_i - b_i| \le k$$$ should be satisfied ($$$|x|$$$ is the absolute value of $$$x$$$).He can change the price for each product not more than once. Note that he can leave the old prices for some products. The new price $$$b_i$$$ of each product $$$i$$$ should be positive (i.e. $$$b_i &gt; 0$$$ should be satisfied for all $$$i$$$ from $$$1$$$ to $$$n$$$).Your task is to find out the maximum possible equal price $$$B$$$ of all productts with the restriction that for all products the condiion $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the same new price of all products) or report that it is impossible to find such price $$$B$$$.Note that the chosen price $$$B$$$ should be integer.You should answer $$$q$$$ independent queries.
Print $$$q$$$ integers, where the $$$i$$$-th integer is the answer $$$B$$$ on the $$$i$$$-th query. If it is impossible to equalize prices of all given products with restriction that for all products the condition $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the new equal price of all products), print -1. Otherwise print the maximum possible equal price of all products.
C
3b158306d335459ff55dcf29e46010e8
9e3c956b715973de8d610918ebc1fe26
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1561559700
["4\n5 1\n1 1 2 3 1\n4 2\n6 4 8 5\n2 2\n1 6\n3 5\n5 2 5"]
NoteIn the first example query you can choose the price $$$B=2$$$. It is easy to see that the difference between each old price and each new price $$$B=2$$$ is no more than $$$1$$$.In the second example query you can choose the price $$$B=6$$$ and then all the differences between old and new price $$$B=6$$$ will be no more than $$$2$$$.In the third example query you cannot choose any suitable price $$$B$$$. For any value $$$B$$$ at least one condition out of two will be violated: $$$|1-B| \le 2$$$, $$$|6-B| \le 2$$$.In the fourth example query all values $$$B$$$ between $$$1$$$ and $$$7$$$ are valid. But the maximum is $$$7$$$, so it's the answer.
PASSED
900
standard input
1 second
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is presented by two lines. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100, 1 \le k \le 10^8$$$) — the number of products and the value $$$k$$$. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^8$$$), where $$$a_i$$$ is the price of the $$$i$$$-th product.
["2\n6\n-1\n7"]
#include<stdio.h> int main() { int t,n,k,i,max=0,a,min=100000001; scanf("%d",&t); while(t!=0) {max=0;min=100000001; scanf("%d%d",&n,&k); for(i=0; i<n; i++) { scanf("%d",&a); if(a>max) max=a; if(a<min) min=a; } if(min+k>=max-k) printf("%d\n",min+k); else printf("-1\n"); t--;} }
There are $$$n$$$ products in the shop. The price of the $$$i$$$-th product is $$$a_i$$$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.In fact, the owner of the shop can change the price of some product $$$i$$$ in such a way that the difference between the old price of this product $$$a_i$$$ and the new price $$$b_i$$$ is at most $$$k$$$. In other words, the condition $$$|a_i - b_i| \le k$$$ should be satisfied ($$$|x|$$$ is the absolute value of $$$x$$$).He can change the price for each product not more than once. Note that he can leave the old prices for some products. The new price $$$b_i$$$ of each product $$$i$$$ should be positive (i.e. $$$b_i &gt; 0$$$ should be satisfied for all $$$i$$$ from $$$1$$$ to $$$n$$$).Your task is to find out the maximum possible equal price $$$B$$$ of all productts with the restriction that for all products the condiion $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the same new price of all products) or report that it is impossible to find such price $$$B$$$.Note that the chosen price $$$B$$$ should be integer.You should answer $$$q$$$ independent queries.
Print $$$q$$$ integers, where the $$$i$$$-th integer is the answer $$$B$$$ on the $$$i$$$-th query. If it is impossible to equalize prices of all given products with restriction that for all products the condition $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the new equal price of all products), print -1. Otherwise print the maximum possible equal price of all products.
C
3b158306d335459ff55dcf29e46010e8
62d7eb68a2860e2199398630a8c45aae
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1561559700
["4\n5 1\n1 1 2 3 1\n4 2\n6 4 8 5\n2 2\n1 6\n3 5\n5 2 5"]
NoteIn the first example query you can choose the price $$$B=2$$$. It is easy to see that the difference between each old price and each new price $$$B=2$$$ is no more than $$$1$$$.In the second example query you can choose the price $$$B=6$$$ and then all the differences between old and new price $$$B=6$$$ will be no more than $$$2$$$.In the third example query you cannot choose any suitable price $$$B$$$. For any value $$$B$$$ at least one condition out of two will be violated: $$$|1-B| \le 2$$$, $$$|6-B| \le 2$$$.In the fourth example query all values $$$B$$$ between $$$1$$$ and $$$7$$$ are valid. But the maximum is $$$7$$$, so it's the answer.
PASSED
900
standard input
1 second
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is presented by two lines. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100, 1 \le k \le 10^8$$$) — the number of products and the value $$$k$$$. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^8$$$), where $$$a_i$$$ is the price of the $$$i$$$-th product.
["2\n6\n-1\n7"]
#include<stdio.h> int main() { int t, m; scanf("%d",&t); m=t-1; int arr[t]; while(t--) { int n,k,min=1e8,max=0; scanf("%d%d",&n,&k); int ar; for(int i=0;i<n;i++) { scanf("%d",&ar); if(ar>max) max=ar; if(ar<min) min=ar; } if(max-min>(2*k)) arr[t]=-1; else arr[t]=min+k; } for(int i=m;i>=0;i--) printf("%d\n",arr[i]); return 0; }
There are $$$n$$$ products in the shop. The price of the $$$i$$$-th product is $$$a_i$$$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.In fact, the owner of the shop can change the price of some product $$$i$$$ in such a way that the difference between the old price of this product $$$a_i$$$ and the new price $$$b_i$$$ is at most $$$k$$$. In other words, the condition $$$|a_i - b_i| \le k$$$ should be satisfied ($$$|x|$$$ is the absolute value of $$$x$$$).He can change the price for each product not more than once. Note that he can leave the old prices for some products. The new price $$$b_i$$$ of each product $$$i$$$ should be positive (i.e. $$$b_i &gt; 0$$$ should be satisfied for all $$$i$$$ from $$$1$$$ to $$$n$$$).Your task is to find out the maximum possible equal price $$$B$$$ of all productts with the restriction that for all products the condiion $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the same new price of all products) or report that it is impossible to find such price $$$B$$$.Note that the chosen price $$$B$$$ should be integer.You should answer $$$q$$$ independent queries.
Print $$$q$$$ integers, where the $$$i$$$-th integer is the answer $$$B$$$ on the $$$i$$$-th query. If it is impossible to equalize prices of all given products with restriction that for all products the condition $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the new equal price of all products), print -1. Otherwise print the maximum possible equal price of all products.
C
3b158306d335459ff55dcf29e46010e8
462218ab43b3b24d7c92b9e148785f19
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1561559700
["4\n5 1\n1 1 2 3 1\n4 2\n6 4 8 5\n2 2\n1 6\n3 5\n5 2 5"]
NoteIn the first example query you can choose the price $$$B=2$$$. It is easy to see that the difference between each old price and each new price $$$B=2$$$ is no more than $$$1$$$.In the second example query you can choose the price $$$B=6$$$ and then all the differences between old and new price $$$B=6$$$ will be no more than $$$2$$$.In the third example query you cannot choose any suitable price $$$B$$$. For any value $$$B$$$ at least one condition out of two will be violated: $$$|1-B| \le 2$$$, $$$|6-B| \le 2$$$.In the fourth example query all values $$$B$$$ between $$$1$$$ and $$$7$$$ are valid. But the maximum is $$$7$$$, so it's the answer.
PASSED
900
standard input
1 second
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is presented by two lines. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100, 1 \le k \le 10^8$$$) — the number of products and the value $$$k$$$. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^8$$$), where $$$a_i$$$ is the price of the $$$i$$$-th product.
["2\n6\n-1\n7"]
#include <stdio.h> int q, n, k, a[102]; int main(){ scanf("%d", &q); while (q != 0){ int i; scanf("%d%d", &n, &k); for (i = 0; i < n; i++) scanf("%d", &a[i]); int min = a[0] + k, max = a[0] - k; for (i = 1; i < n; i ++){ if (a[i] + k < min) min = a[i] + k; if (a[i] - k > max) max = a[i] - k; } if (min < max) printf("-1\n"); else printf("%d\n", min); q --; } }
There are $$$n$$$ products in the shop. The price of the $$$i$$$-th product is $$$a_i$$$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.In fact, the owner of the shop can change the price of some product $$$i$$$ in such a way that the difference between the old price of this product $$$a_i$$$ and the new price $$$b_i$$$ is at most $$$k$$$. In other words, the condition $$$|a_i - b_i| \le k$$$ should be satisfied ($$$|x|$$$ is the absolute value of $$$x$$$).He can change the price for each product not more than once. Note that he can leave the old prices for some products. The new price $$$b_i$$$ of each product $$$i$$$ should be positive (i.e. $$$b_i &gt; 0$$$ should be satisfied for all $$$i$$$ from $$$1$$$ to $$$n$$$).Your task is to find out the maximum possible equal price $$$B$$$ of all productts with the restriction that for all products the condiion $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the same new price of all products) or report that it is impossible to find such price $$$B$$$.Note that the chosen price $$$B$$$ should be integer.You should answer $$$q$$$ independent queries.
Print $$$q$$$ integers, where the $$$i$$$-th integer is the answer $$$B$$$ on the $$$i$$$-th query. If it is impossible to equalize prices of all given products with restriction that for all products the condition $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the new equal price of all products), print -1. Otherwise print the maximum possible equal price of all products.
C
3b158306d335459ff55dcf29e46010e8
31993798aee6393d9e0edfabc03d7b3e
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1561559700
["4\n5 1\n1 1 2 3 1\n4 2\n6 4 8 5\n2 2\n1 6\n3 5\n5 2 5"]
NoteIn the first example query you can choose the price $$$B=2$$$. It is easy to see that the difference between each old price and each new price $$$B=2$$$ is no more than $$$1$$$.In the second example query you can choose the price $$$B=6$$$ and then all the differences between old and new price $$$B=6$$$ will be no more than $$$2$$$.In the third example query you cannot choose any suitable price $$$B$$$. For any value $$$B$$$ at least one condition out of two will be violated: $$$|1-B| \le 2$$$, $$$|6-B| \le 2$$$.In the fourth example query all values $$$B$$$ between $$$1$$$ and $$$7$$$ are valid. But the maximum is $$$7$$$, so it's the answer.
PASSED
900
standard input
1 second
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is presented by two lines. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100, 1 \le k \le 10^8$$$) — the number of products and the value $$$k$$$. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^8$$$), where $$$a_i$$$ is the price of the $$$i$$$-th product.
["2\n6\n-1\n7"]
#include<stdio.h> #include<math.h> int main() { long long int T,N,K,i,j,l,k,f,min; scanf("%lld",&T); for(i=0;i<T;i++) { f=0; min=0; scanf("%lld %lld",&N,&K); long long int ar[N]; scanf("%lld",&ar[0]); min=ar[0]; // printf("min=%lld",min); for(j=1;j<N;j++) { scanf("%lld",&ar[j]); if(min>ar[j]) min=ar[j]; } min=min+K; // printf("value %lld\n",min); for(k=0;k<N;k++) { if(abs(ar[k]-min)>K) { f=1; break; } } if(f==1) printf("-1\n"); else printf("%lld\n",min); } }
There are $$$n$$$ products in the shop. The price of the $$$i$$$-th product is $$$a_i$$$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.In fact, the owner of the shop can change the price of some product $$$i$$$ in such a way that the difference between the old price of this product $$$a_i$$$ and the new price $$$b_i$$$ is at most $$$k$$$. In other words, the condition $$$|a_i - b_i| \le k$$$ should be satisfied ($$$|x|$$$ is the absolute value of $$$x$$$).He can change the price for each product not more than once. Note that he can leave the old prices for some products. The new price $$$b_i$$$ of each product $$$i$$$ should be positive (i.e. $$$b_i &gt; 0$$$ should be satisfied for all $$$i$$$ from $$$1$$$ to $$$n$$$).Your task is to find out the maximum possible equal price $$$B$$$ of all productts with the restriction that for all products the condiion $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the same new price of all products) or report that it is impossible to find such price $$$B$$$.Note that the chosen price $$$B$$$ should be integer.You should answer $$$q$$$ independent queries.
Print $$$q$$$ integers, where the $$$i$$$-th integer is the answer $$$B$$$ on the $$$i$$$-th query. If it is impossible to equalize prices of all given products with restriction that for all products the condition $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the new equal price of all products), print -1. Otherwise print the maximum possible equal price of all products.
C
3b158306d335459ff55dcf29e46010e8
2c58e91a2f3bda6e5cc4669490ade2e7
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1561559700
["4\n5 1\n1 1 2 3 1\n4 2\n6 4 8 5\n2 2\n1 6\n3 5\n5 2 5"]
NoteIn the first example query you can choose the price $$$B=2$$$. It is easy to see that the difference between each old price and each new price $$$B=2$$$ is no more than $$$1$$$.In the second example query you can choose the price $$$B=6$$$ and then all the differences between old and new price $$$B=6$$$ will be no more than $$$2$$$.In the third example query you cannot choose any suitable price $$$B$$$. For any value $$$B$$$ at least one condition out of two will be violated: $$$|1-B| \le 2$$$, $$$|6-B| \le 2$$$.In the fourth example query all values $$$B$$$ between $$$1$$$ and $$$7$$$ are valid. But the maximum is $$$7$$$, so it's the answer.
PASSED
900
standard input
1 second
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is presented by two lines. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100, 1 \le k \le 10^8$$$) — the number of products and the value $$$k$$$. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^8$$$), where $$$a_i$$$ is the price of the $$$i$$$-th product.
["2\n6\n-1\n7"]
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> typedef long long ll; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define max(l,r) ((l)>(r)?l:r) #define min(l,r) ((l)<(r)?l:r) #define swap(l,r) {ll tp=l;l=r;r=tp;} const ll MOD = 1000000007; const int INF = (1<<30); // > 10^9 const ll LINF = (1LL<<60); // > 10^18 int upcmpll(const void *a, const void *b){return(*(ll*)a==*(ll*)b?0:(*(ll*)a>*(ll*)b?1:-1));} void sort_u(ll*a, ll n){qsort(a,n,sizeof(ll),upcmpll);} char s[202020]; ll a[202020]; int n,t,k; ll armax(ll *a, ll n){ ll tmx = a[0]; for (ll i = 1; i < n; i++) if(a[i] > tmx) tmx = a[i]; return tmx; } ll armin(ll *a, ll n){ ll tmn = a[0]; for (ll i = 1; i < n; i++) if(a[i] < tmn) tmn = a[i]; return tmn; } ll solve(){ ll ans = 0; ll mx = armax(a,n), mn = armin(a,n); if(mx-mn > 2*k){ ans = -1; }else{ ans = mn+k; } return ans; } //for q-testcase int main(){ scanf("%d", &t); rep(tes,t){ scanf("%d%d", &n,&k); rep(i, n) scanf("%lld", a+i); printf("%lld\n", solve()); } }
There are $$$n$$$ products in the shop. The price of the $$$i$$$-th product is $$$a_i$$$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.In fact, the owner of the shop can change the price of some product $$$i$$$ in such a way that the difference between the old price of this product $$$a_i$$$ and the new price $$$b_i$$$ is at most $$$k$$$. In other words, the condition $$$|a_i - b_i| \le k$$$ should be satisfied ($$$|x|$$$ is the absolute value of $$$x$$$).He can change the price for each product not more than once. Note that he can leave the old prices for some products. The new price $$$b_i$$$ of each product $$$i$$$ should be positive (i.e. $$$b_i &gt; 0$$$ should be satisfied for all $$$i$$$ from $$$1$$$ to $$$n$$$).Your task is to find out the maximum possible equal price $$$B$$$ of all productts with the restriction that for all products the condiion $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the same new price of all products) or report that it is impossible to find such price $$$B$$$.Note that the chosen price $$$B$$$ should be integer.You should answer $$$q$$$ independent queries.
Print $$$q$$$ integers, where the $$$i$$$-th integer is the answer $$$B$$$ on the $$$i$$$-th query. If it is impossible to equalize prices of all given products with restriction that for all products the condition $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the new equal price of all products), print -1. Otherwise print the maximum possible equal price of all products.
C
3b158306d335459ff55dcf29e46010e8
4b3a9f48c13acf1124bb5838de422762
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1561559700
["4\n5 1\n1 1 2 3 1\n4 2\n6 4 8 5\n2 2\n1 6\n3 5\n5 2 5"]
NoteIn the first example query you can choose the price $$$B=2$$$. It is easy to see that the difference between each old price and each new price $$$B=2$$$ is no more than $$$1$$$.In the second example query you can choose the price $$$B=6$$$ and then all the differences between old and new price $$$B=6$$$ will be no more than $$$2$$$.In the third example query you cannot choose any suitable price $$$B$$$. For any value $$$B$$$ at least one condition out of two will be violated: $$$|1-B| \le 2$$$, $$$|6-B| \le 2$$$.In the fourth example query all values $$$B$$$ between $$$1$$$ and $$$7$$$ are valid. But the maximum is $$$7$$$, so it's the answer.
PASSED
900
standard input
1 second
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is presented by two lines. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100, 1 \le k \le 10^8$$$) — the number of products and the value $$$k$$$. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^8$$$), where $$$a_i$$$ is the price of the $$$i$$$-th product.
["2\n6\n-1\n7"]
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> typedef long long ll; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define max(l,r) ((l)>(r)?l:r) #define min(l,r) ((l)<(r)?l:r) #define swap(l,r) {ll tp=l;l=r;r=tp;} const ll MOD = 1000000007; const int INF = (1<<30); // > 10^9 const ll LINF = (1LL<<60); // > 10^18 ll gcd(ll a,ll b){if(b==0) return llabs(a); return gcd(b,a%b);} ll lcm(ll a,ll b){if(a==b&&a==0) return 0; return a/gcd(a,b)*b;} int upcmpll(const void *a, const void *b){return(*(ll*)a==*(ll*)b?0:(*(ll*)a>*(ll*)b?1:-1));} void sort_u(ll*a, int n){qsort(a,n,sizeof(ll),upcmpll);} char s[202020]; ll a[202020]; int n,t,k; ll solve(){ ll ans = 0; sort_u(a,n); ans = a[0] + k; rep(i,n){ if(a[i] > ans && a[i] - ans > k){ ans = -1; break; } } return ans; } //for q-testcase int main(){ scanf("%d", &t); rep(tes,t){ scanf("%d%d", &n,&k); rep(i, n) scanf("%lld", a+i); printf("%lld\n", solve()); } }
There are $$$n$$$ products in the shop. The price of the $$$i$$$-th product is $$$a_i$$$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.In fact, the owner of the shop can change the price of some product $$$i$$$ in such a way that the difference between the old price of this product $$$a_i$$$ and the new price $$$b_i$$$ is at most $$$k$$$. In other words, the condition $$$|a_i - b_i| \le k$$$ should be satisfied ($$$|x|$$$ is the absolute value of $$$x$$$).He can change the price for each product not more than once. Note that he can leave the old prices for some products. The new price $$$b_i$$$ of each product $$$i$$$ should be positive (i.e. $$$b_i &gt; 0$$$ should be satisfied for all $$$i$$$ from $$$1$$$ to $$$n$$$).Your task is to find out the maximum possible equal price $$$B$$$ of all productts with the restriction that for all products the condiion $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the same new price of all products) or report that it is impossible to find such price $$$B$$$.Note that the chosen price $$$B$$$ should be integer.You should answer $$$q$$$ independent queries.
Print $$$q$$$ integers, where the $$$i$$$-th integer is the answer $$$B$$$ on the $$$i$$$-th query. If it is impossible to equalize prices of all given products with restriction that for all products the condition $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the new equal price of all products), print -1. Otherwise print the maximum possible equal price of all products.
C
3b158306d335459ff55dcf29e46010e8
ec936d4af6ef05c078c90c2236fab5b4
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1561559700
["4\n5 1\n1 1 2 3 1\n4 2\n6 4 8 5\n2 2\n1 6\n3 5\n5 2 5"]
NoteIn the first example query you can choose the price $$$B=2$$$. It is easy to see that the difference between each old price and each new price $$$B=2$$$ is no more than $$$1$$$.In the second example query you can choose the price $$$B=6$$$ and then all the differences between old and new price $$$B=6$$$ will be no more than $$$2$$$.In the third example query you cannot choose any suitable price $$$B$$$. For any value $$$B$$$ at least one condition out of two will be violated: $$$|1-B| \le 2$$$, $$$|6-B| \le 2$$$.In the fourth example query all values $$$B$$$ between $$$1$$$ and $$$7$$$ are valid. But the maximum is $$$7$$$, so it's the answer.
PASSED
900
standard input
1 second
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is presented by two lines. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100, 1 \le k \le 10^8$$$) — the number of products and the value $$$k$$$. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^8$$$), where $$$a_i$$$ is the price of the $$$i$$$-th product.
["2\n6\n-1\n7"]
#include <stdio.h> void solve(){ int n, k; scanf("%d%d", &n, &k); int mx = 0, mn = 1e8 + 1; for(int i = 0; i < n; i++){ int a; scanf("%d", &a); if(mx < a) mx = a; if(mn > a) mn = a; } if(mn + 2 * k < mx) printf("-1\n"); else printf("%d\n", mn + k); } int main(){ int T; scanf("%d", &T); while(T--){ solve(); } }
There are $$$n$$$ products in the shop. The price of the $$$i$$$-th product is $$$a_i$$$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.In fact, the owner of the shop can change the price of some product $$$i$$$ in such a way that the difference between the old price of this product $$$a_i$$$ and the new price $$$b_i$$$ is at most $$$k$$$. In other words, the condition $$$|a_i - b_i| \le k$$$ should be satisfied ($$$|x|$$$ is the absolute value of $$$x$$$).He can change the price for each product not more than once. Note that he can leave the old prices for some products. The new price $$$b_i$$$ of each product $$$i$$$ should be positive (i.e. $$$b_i &gt; 0$$$ should be satisfied for all $$$i$$$ from $$$1$$$ to $$$n$$$).Your task is to find out the maximum possible equal price $$$B$$$ of all productts with the restriction that for all products the condiion $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the same new price of all products) or report that it is impossible to find such price $$$B$$$.Note that the chosen price $$$B$$$ should be integer.You should answer $$$q$$$ independent queries.
Print $$$q$$$ integers, where the $$$i$$$-th integer is the answer $$$B$$$ on the $$$i$$$-th query. If it is impossible to equalize prices of all given products with restriction that for all products the condition $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the new equal price of all products), print -1. Otherwise print the maximum possible equal price of all products.
C
3b158306d335459ff55dcf29e46010e8
c7484d3919c2df0aa62cff892106c590
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1561559700
["4\n5 1\n1 1 2 3 1\n4 2\n6 4 8 5\n2 2\n1 6\n3 5\n5 2 5"]
NoteIn the first example query you can choose the price $$$B=2$$$. It is easy to see that the difference between each old price and each new price $$$B=2$$$ is no more than $$$1$$$.In the second example query you can choose the price $$$B=6$$$ and then all the differences between old and new price $$$B=6$$$ will be no more than $$$2$$$.In the third example query you cannot choose any suitable price $$$B$$$. For any value $$$B$$$ at least one condition out of two will be violated: $$$|1-B| \le 2$$$, $$$|6-B| \le 2$$$.In the fourth example query all values $$$B$$$ between $$$1$$$ and $$$7$$$ are valid. But the maximum is $$$7$$$, so it's the answer.
PASSED
900
standard input
1 second
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is presented by two lines. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100, 1 \le k \le 10^8$$$) — the number of products and the value $$$k$$$. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^8$$$), where $$$a_i$$$ is the price of the $$$i$$$-th product.
["2\n6\n-1\n7"]
#include <stdio.h> int a[200]; void swap(int *a, int *b){ int tmp; tmp = *a; *a = *b; *b = tmp; } void bubble_sort(int *a, int sz){ for(int i = 0; i < sz - 1; i++){ for(int j = i + 1; j < sz; j++){ if(a[i] > a[j]) swap(&a[i], &a[j]); } } } void solve(){ int n, k; scanf("%d%d", &n, &k); for(int i = 0; i < n; i++) scanf("%d", &a[i]); bubble_sort(a, n); if(a[n - 1] - a[0] > 2 * k) printf("-1\n"); else printf("%d\n", a[0] + k); } int main(){ int T; scanf("%d", &T); while(T--){ solve(); } }
There are $$$n$$$ products in the shop. The price of the $$$i$$$-th product is $$$a_i$$$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.In fact, the owner of the shop can change the price of some product $$$i$$$ in such a way that the difference between the old price of this product $$$a_i$$$ and the new price $$$b_i$$$ is at most $$$k$$$. In other words, the condition $$$|a_i - b_i| \le k$$$ should be satisfied ($$$|x|$$$ is the absolute value of $$$x$$$).He can change the price for each product not more than once. Note that he can leave the old prices for some products. The new price $$$b_i$$$ of each product $$$i$$$ should be positive (i.e. $$$b_i &gt; 0$$$ should be satisfied for all $$$i$$$ from $$$1$$$ to $$$n$$$).Your task is to find out the maximum possible equal price $$$B$$$ of all productts with the restriction that for all products the condiion $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the same new price of all products) or report that it is impossible to find such price $$$B$$$.Note that the chosen price $$$B$$$ should be integer.You should answer $$$q$$$ independent queries.
Print $$$q$$$ integers, where the $$$i$$$-th integer is the answer $$$B$$$ on the $$$i$$$-th query. If it is impossible to equalize prices of all given products with restriction that for all products the condition $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the new equal price of all products), print -1. Otherwise print the maximum possible equal price of all products.
C
3b158306d335459ff55dcf29e46010e8
1283433b81e1ef45e67948c715a5c526
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1561559700
["4\n5 1\n1 1 2 3 1\n4 2\n6 4 8 5\n2 2\n1 6\n3 5\n5 2 5"]
NoteIn the first example query you can choose the price $$$B=2$$$. It is easy to see that the difference between each old price and each new price $$$B=2$$$ is no more than $$$1$$$.In the second example query you can choose the price $$$B=6$$$ and then all the differences between old and new price $$$B=6$$$ will be no more than $$$2$$$.In the third example query you cannot choose any suitable price $$$B$$$. For any value $$$B$$$ at least one condition out of two will be violated: $$$|1-B| \le 2$$$, $$$|6-B| \le 2$$$.In the fourth example query all values $$$B$$$ between $$$1$$$ and $$$7$$$ are valid. But the maximum is $$$7$$$, so it's the answer.
PASSED
900
standard input
1 second
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is presented by two lines. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100, 1 \le k \le 10^8$$$) — the number of products and the value $$$k$$$. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^8$$$), where $$$a_i$$$ is the price of the $$$i$$$-th product.
["2\n6\n-1\n7"]
#include <stdio.h> int a[150]; void solve(){ int n, k; int mx = 0, mn = 1e8 + 1; scanf("%d%d", &n, &k); for(int i = 0; i < n; i++){ int x; scanf("%d", &x); if(mx < x) mx = x; if(mn > x) mn = x; } if(mx - mn > 2 * k) printf("-1\n"); else printf("%d\n", mn + k); } int main(){ int t; scanf("%d", &t); while(t--){ solve(); } }
There are $$$n$$$ products in the shop. The price of the $$$i$$$-th product is $$$a_i$$$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.In fact, the owner of the shop can change the price of some product $$$i$$$ in such a way that the difference between the old price of this product $$$a_i$$$ and the new price $$$b_i$$$ is at most $$$k$$$. In other words, the condition $$$|a_i - b_i| \le k$$$ should be satisfied ($$$|x|$$$ is the absolute value of $$$x$$$).He can change the price for each product not more than once. Note that he can leave the old prices for some products. The new price $$$b_i$$$ of each product $$$i$$$ should be positive (i.e. $$$b_i &gt; 0$$$ should be satisfied for all $$$i$$$ from $$$1$$$ to $$$n$$$).Your task is to find out the maximum possible equal price $$$B$$$ of all productts with the restriction that for all products the condiion $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the same new price of all products) or report that it is impossible to find such price $$$B$$$.Note that the chosen price $$$B$$$ should be integer.You should answer $$$q$$$ independent queries.
Print $$$q$$$ integers, where the $$$i$$$-th integer is the answer $$$B$$$ on the $$$i$$$-th query. If it is impossible to equalize prices of all given products with restriction that for all products the condition $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the new equal price of all products), print -1. Otherwise print the maximum possible equal price of all products.
C
3b158306d335459ff55dcf29e46010e8
070c778ad6d179dfae89b10f0a596587
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1561559700
["4\n5 1\n1 1 2 3 1\n4 2\n6 4 8 5\n2 2\n1 6\n3 5\n5 2 5"]
NoteIn the first example query you can choose the price $$$B=2$$$. It is easy to see that the difference between each old price and each new price $$$B=2$$$ is no more than $$$1$$$.In the second example query you can choose the price $$$B=6$$$ and then all the differences between old and new price $$$B=6$$$ will be no more than $$$2$$$.In the third example query you cannot choose any suitable price $$$B$$$. For any value $$$B$$$ at least one condition out of two will be violated: $$$|1-B| \le 2$$$, $$$|6-B| \le 2$$$.In the fourth example query all values $$$B$$$ between $$$1$$$ and $$$7$$$ are valid. But the maximum is $$$7$$$, so it's the answer.
PASSED
900
standard input
1 second
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is presented by two lines. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100, 1 \le k \le 10^8$$$) — the number of products and the value $$$k$$$. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^8$$$), where $$$a_i$$$ is the price of the $$$i$$$-th product.
["2\n6\n-1\n7"]
#include <stdio.h> int solve () { int min, max, x, n, k, i = 0; scanf("%d %d", &n, &k); for (; i < n; i++) { scanf("%d", &x); if (i == 0) { min = x; max = x; } if (x < min) min = x; if (x > max) max = x; } if (min + k < max - k) return -1; return min + k; } int main () { int q, i = 0; scanf("%d", &q); for (; i < q; i++) { printf("%d\n", solve()); } }
There are $$$n$$$ products in the shop. The price of the $$$i$$$-th product is $$$a_i$$$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.In fact, the owner of the shop can change the price of some product $$$i$$$ in such a way that the difference between the old price of this product $$$a_i$$$ and the new price $$$b_i$$$ is at most $$$k$$$. In other words, the condition $$$|a_i - b_i| \le k$$$ should be satisfied ($$$|x|$$$ is the absolute value of $$$x$$$).He can change the price for each product not more than once. Note that he can leave the old prices for some products. The new price $$$b_i$$$ of each product $$$i$$$ should be positive (i.e. $$$b_i &gt; 0$$$ should be satisfied for all $$$i$$$ from $$$1$$$ to $$$n$$$).Your task is to find out the maximum possible equal price $$$B$$$ of all productts with the restriction that for all products the condiion $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the same new price of all products) or report that it is impossible to find such price $$$B$$$.Note that the chosen price $$$B$$$ should be integer.You should answer $$$q$$$ independent queries.
Print $$$q$$$ integers, where the $$$i$$$-th integer is the answer $$$B$$$ on the $$$i$$$-th query. If it is impossible to equalize prices of all given products with restriction that for all products the condition $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the new equal price of all products), print -1. Otherwise print the maximum possible equal price of all products.
C
3b158306d335459ff55dcf29e46010e8
415a631bfcc9e2dd023903d763c46d3f
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1561559700
["4\n5 1\n1 1 2 3 1\n4 2\n6 4 8 5\n2 2\n1 6\n3 5\n5 2 5"]
NoteIn the first example query you can choose the price $$$B=2$$$. It is easy to see that the difference between each old price and each new price $$$B=2$$$ is no more than $$$1$$$.In the second example query you can choose the price $$$B=6$$$ and then all the differences between old and new price $$$B=6$$$ will be no more than $$$2$$$.In the third example query you cannot choose any suitable price $$$B$$$. For any value $$$B$$$ at least one condition out of two will be violated: $$$|1-B| \le 2$$$, $$$|6-B| \le 2$$$.In the fourth example query all values $$$B$$$ between $$$1$$$ and $$$7$$$ are valid. But the maximum is $$$7$$$, so it's the answer.
PASSED
900
standard input
1 second
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is presented by two lines. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100, 1 \le k \le 10^8$$$) — the number of products and the value $$$k$$$. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^8$$$), where $$$a_i$$$ is the price of the $$$i$$$-th product.
["2\n6\n-1\n7"]
#include <stdio.h> int abs(int x); int main(){ int queryNum; scanf("%d", &queryNum); for (int i = 0; i < queryNum; i++){ int max = 0, min = 100000000, n, k, a; scanf("%d %d", &n, &k); for (int i = 0; i < n; i++){ scanf("%d", &a); if (a > max) max = a; if (a < min) min = a; } if (max - k > min + k) printf("-1\n"); else printf("%d\n", min + k); } } int abs(int x){ if (x < 0) return x * -1; else return x; }
There are $$$n$$$ products in the shop. The price of the $$$i$$$-th product is $$$a_i$$$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.In fact, the owner of the shop can change the price of some product $$$i$$$ in such a way that the difference between the old price of this product $$$a_i$$$ and the new price $$$b_i$$$ is at most $$$k$$$. In other words, the condition $$$|a_i - b_i| \le k$$$ should be satisfied ($$$|x|$$$ is the absolute value of $$$x$$$).He can change the price for each product not more than once. Note that he can leave the old prices for some products. The new price $$$b_i$$$ of each product $$$i$$$ should be positive (i.e. $$$b_i &gt; 0$$$ should be satisfied for all $$$i$$$ from $$$1$$$ to $$$n$$$).Your task is to find out the maximum possible equal price $$$B$$$ of all productts with the restriction that for all products the condiion $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the same new price of all products) or report that it is impossible to find such price $$$B$$$.Note that the chosen price $$$B$$$ should be integer.You should answer $$$q$$$ independent queries.
Print $$$q$$$ integers, where the $$$i$$$-th integer is the answer $$$B$$$ on the $$$i$$$-th query. If it is impossible to equalize prices of all given products with restriction that for all products the condition $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the new equal price of all products), print -1. Otherwise print the maximum possible equal price of all products.
C
3b158306d335459ff55dcf29e46010e8
3f1555cb4d11cea3e93d7602643cef18
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1561559700
["4\n5 1\n1 1 2 3 1\n4 2\n6 4 8 5\n2 2\n1 6\n3 5\n5 2 5"]
NoteIn the first example query you can choose the price $$$B=2$$$. It is easy to see that the difference between each old price and each new price $$$B=2$$$ is no more than $$$1$$$.In the second example query you can choose the price $$$B=6$$$ and then all the differences between old and new price $$$B=6$$$ will be no more than $$$2$$$.In the third example query you cannot choose any suitable price $$$B$$$. For any value $$$B$$$ at least one condition out of two will be violated: $$$|1-B| \le 2$$$, $$$|6-B| \le 2$$$.In the fourth example query all values $$$B$$$ between $$$1$$$ and $$$7$$$ are valid. But the maximum is $$$7$$$, so it's the answer.
PASSED
900
standard input
1 second
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is presented by two lines. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100, 1 \le k \le 10^8$$$) — the number of products and the value $$$k$$$. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^8$$$), where $$$a_i$$$ is the price of the $$$i$$$-th product.
["2\n6\n-1\n7"]
#include <stdio.h> int main() { int t, n, k, i, maxx, minn; int a[105]; scanf("%d", &t); while(t--) { scanf("%d %d", &n, &k); for(i=0;i<n;i++) { scanf("%d", &a[i]); if(i==0||a[i]>maxx) maxx = a[i]; if(i==0||a[i]<minn) minn = a[i]; } if(minn + k < maxx - k) printf("%d\n", -1); else printf("%d\n", minn+k); } return 0; }
There are $$$n$$$ products in the shop. The price of the $$$i$$$-th product is $$$a_i$$$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.In fact, the owner of the shop can change the price of some product $$$i$$$ in such a way that the difference between the old price of this product $$$a_i$$$ and the new price $$$b_i$$$ is at most $$$k$$$. In other words, the condition $$$|a_i - b_i| \le k$$$ should be satisfied ($$$|x|$$$ is the absolute value of $$$x$$$).He can change the price for each product not more than once. Note that he can leave the old prices for some products. The new price $$$b_i$$$ of each product $$$i$$$ should be positive (i.e. $$$b_i &gt; 0$$$ should be satisfied for all $$$i$$$ from $$$1$$$ to $$$n$$$).Your task is to find out the maximum possible equal price $$$B$$$ of all productts with the restriction that for all products the condiion $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the same new price of all products) or report that it is impossible to find such price $$$B$$$.Note that the chosen price $$$B$$$ should be integer.You should answer $$$q$$$ independent queries.
Print $$$q$$$ integers, where the $$$i$$$-th integer is the answer $$$B$$$ on the $$$i$$$-th query. If it is impossible to equalize prices of all given products with restriction that for all products the condition $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the new equal price of all products), print -1. Otherwise print the maximum possible equal price of all products.
C
3b158306d335459ff55dcf29e46010e8
2cb4d28cd2085be4724eb03d573df8d3
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1561559700
["4\n5 1\n1 1 2 3 1\n4 2\n6 4 8 5\n2 2\n1 6\n3 5\n5 2 5"]
NoteIn the first example query you can choose the price $$$B=2$$$. It is easy to see that the difference between each old price and each new price $$$B=2$$$ is no more than $$$1$$$.In the second example query you can choose the price $$$B=6$$$ and then all the differences between old and new price $$$B=6$$$ will be no more than $$$2$$$.In the third example query you cannot choose any suitable price $$$B$$$. For any value $$$B$$$ at least one condition out of two will be violated: $$$|1-B| \le 2$$$, $$$|6-B| \le 2$$$.In the fourth example query all values $$$B$$$ between $$$1$$$ and $$$7$$$ are valid. But the maximum is $$$7$$$, so it's the answer.
PASSED
900
standard input
1 second
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is presented by two lines. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100, 1 \le k \le 10^8$$$) — the number of products and the value $$$k$$$. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^8$$$), where $$$a_i$$$ is the price of the $$$i$$$-th product.
["2\n6\n-1\n7"]
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> int valid(int ar[],int n,int k,int mid){ int i; int flag = 0; for(i=0;i<n;i++){ if(mid>=ar[i]){ if((k+ar[i])<mid){ flag = 1; break; } } else if(mid<ar[i]){ if((ar[i]-k)>mid){ flag = 0; break; } } } if(flag){ return 0; } else{ return 1; } } int main(){ int j,q; scanf("%d",&q); for(j=0;j<q;j++){ int i,n,k; scanf("%d %d",&n,&k); int ar[n]; for(i=0;i<n;i++){ scanf("%d",&ar[i]); } int mi = ar[0]; int ma = ar[0]; for(i=1;i<n;i++){ if(ar[i]>ma){ ma = ar[i]; } } for(i=1;i<n;i++){ if(ar[i]<mi){ mi = ar[i]; } } int lo = mi; int hi = ma + k; int mid,ans=-1; while(lo<=hi){ mid = (lo+hi)/2; if(valid(ar,n,k,mid)){ ans = mid; lo = mid+1; } else{ hi = mid-1; } } if((ma-mi)>2*k){ printf("-1\n"); } else{ printf("%d\n",ans); } } return 0; }
There are $$$n$$$ products in the shop. The price of the $$$i$$$-th product is $$$a_i$$$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.In fact, the owner of the shop can change the price of some product $$$i$$$ in such a way that the difference between the old price of this product $$$a_i$$$ and the new price $$$b_i$$$ is at most $$$k$$$. In other words, the condition $$$|a_i - b_i| \le k$$$ should be satisfied ($$$|x|$$$ is the absolute value of $$$x$$$).He can change the price for each product not more than once. Note that he can leave the old prices for some products. The new price $$$b_i$$$ of each product $$$i$$$ should be positive (i.e. $$$b_i &gt; 0$$$ should be satisfied for all $$$i$$$ from $$$1$$$ to $$$n$$$).Your task is to find out the maximum possible equal price $$$B$$$ of all productts with the restriction that for all products the condiion $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the same new price of all products) or report that it is impossible to find such price $$$B$$$.Note that the chosen price $$$B$$$ should be integer.You should answer $$$q$$$ independent queries.
Print $$$q$$$ integers, where the $$$i$$$-th integer is the answer $$$B$$$ on the $$$i$$$-th query. If it is impossible to equalize prices of all given products with restriction that for all products the condition $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the new equal price of all products), print -1. Otherwise print the maximum possible equal price of all products.
C
3b158306d335459ff55dcf29e46010e8
549d8b73a566169a74321d942916f862
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1561559700
["4\n5 1\n1 1 2 3 1\n4 2\n6 4 8 5\n2 2\n1 6\n3 5\n5 2 5"]
NoteIn the first example query you can choose the price $$$B=2$$$. It is easy to see that the difference between each old price and each new price $$$B=2$$$ is no more than $$$1$$$.In the second example query you can choose the price $$$B=6$$$ and then all the differences between old and new price $$$B=6$$$ will be no more than $$$2$$$.In the third example query you cannot choose any suitable price $$$B$$$. For any value $$$B$$$ at least one condition out of two will be violated: $$$|1-B| \le 2$$$, $$$|6-B| \le 2$$$.In the fourth example query all values $$$B$$$ between $$$1$$$ and $$$7$$$ are valid. But the maximum is $$$7$$$, so it's the answer.
PASSED
900
standard input
1 second
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is presented by two lines. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100, 1 \le k \le 10^8$$$) — the number of products and the value $$$k$$$. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^8$$$), where $$$a_i$$$ is the price of the $$$i$$$-th product.
["2\n6\n-1\n7"]
#include<stdio.h> int main() { long long int t,i,n,k,max,min,j,a,b,s; scanf("%lld",&t); for(i=0;i<t;i++) { scanf("%lld %lld",&n,&k); max=0; min=100000001; for(j=0;j<n;j++) { scanf("%lld",&a); if(a>max) { max=a; } if(a<min) { min=a; } } b=min+k; s=b-max; if(s<0) { s=-s; } if(s<=k) { printf("%lld\n",b); } else { printf("-1\n"); } } return 0; }
There are $$$n$$$ products in the shop. The price of the $$$i$$$-th product is $$$a_i$$$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.In fact, the owner of the shop can change the price of some product $$$i$$$ in such a way that the difference between the old price of this product $$$a_i$$$ and the new price $$$b_i$$$ is at most $$$k$$$. In other words, the condition $$$|a_i - b_i| \le k$$$ should be satisfied ($$$|x|$$$ is the absolute value of $$$x$$$).He can change the price for each product not more than once. Note that he can leave the old prices for some products. The new price $$$b_i$$$ of each product $$$i$$$ should be positive (i.e. $$$b_i &gt; 0$$$ should be satisfied for all $$$i$$$ from $$$1$$$ to $$$n$$$).Your task is to find out the maximum possible equal price $$$B$$$ of all productts with the restriction that for all products the condiion $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the same new price of all products) or report that it is impossible to find such price $$$B$$$.Note that the chosen price $$$B$$$ should be integer.You should answer $$$q$$$ independent queries.
Print $$$q$$$ integers, where the $$$i$$$-th integer is the answer $$$B$$$ on the $$$i$$$-th query. If it is impossible to equalize prices of all given products with restriction that for all products the condition $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the new equal price of all products), print -1. Otherwise print the maximum possible equal price of all products.
C
3b158306d335459ff55dcf29e46010e8
dab351b9f50ff007e625d52b353d759f
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1561559700
["4\n5 1\n1 1 2 3 1\n4 2\n6 4 8 5\n2 2\n1 6\n3 5\n5 2 5"]
NoteIn the first example query you can choose the price $$$B=2$$$. It is easy to see that the difference between each old price and each new price $$$B=2$$$ is no more than $$$1$$$.In the second example query you can choose the price $$$B=6$$$ and then all the differences between old and new price $$$B=6$$$ will be no more than $$$2$$$.In the third example query you cannot choose any suitable price $$$B$$$. For any value $$$B$$$ at least one condition out of two will be violated: $$$|1-B| \le 2$$$, $$$|6-B| \le 2$$$.In the fourth example query all values $$$B$$$ between $$$1$$$ and $$$7$$$ are valid. But the maximum is $$$7$$$, so it's the answer.
PASSED
900
standard input
1 second
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is presented by two lines. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100, 1 \le k \le 10^8$$$) — the number of products and the value $$$k$$$. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^8$$$), where $$$a_i$$$ is the price of the $$$i$$$-th product.
["2\n6\n-1\n7"]
#include <stdio.h> #include <stdlib.h> int main() { int q,i,min,max; scanf("%d",&q); int answ[q],n,k; for(int j=0;j<q;j++){ scanf("%d%d",&n,&k); int a[n]; scanf("%d",&a[0]); min=max=a[0]; for(i=1;i<n;i++){ scanf("%d",&a[i]); if(min>a[i])min=a[i]; if(max<a[i])max=a[i]; } if((max-min)>2*k)answ[j]=-1; else answ[j]=min+k; } for(i=0;i<q;i++)printf("%d\n",answ[i]); return 0; }
There are $$$n$$$ products in the shop. The price of the $$$i$$$-th product is $$$a_i$$$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.In fact, the owner of the shop can change the price of some product $$$i$$$ in such a way that the difference between the old price of this product $$$a_i$$$ and the new price $$$b_i$$$ is at most $$$k$$$. In other words, the condition $$$|a_i - b_i| \le k$$$ should be satisfied ($$$|x|$$$ is the absolute value of $$$x$$$).He can change the price for each product not more than once. Note that he can leave the old prices for some products. The new price $$$b_i$$$ of each product $$$i$$$ should be positive (i.e. $$$b_i &gt; 0$$$ should be satisfied for all $$$i$$$ from $$$1$$$ to $$$n$$$).Your task is to find out the maximum possible equal price $$$B$$$ of all productts with the restriction that for all products the condiion $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the same new price of all products) or report that it is impossible to find such price $$$B$$$.Note that the chosen price $$$B$$$ should be integer.You should answer $$$q$$$ independent queries.
Print $$$q$$$ integers, where the $$$i$$$-th integer is the answer $$$B$$$ on the $$$i$$$-th query. If it is impossible to equalize prices of all given products with restriction that for all products the condition $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the new equal price of all products), print -1. Otherwise print the maximum possible equal price of all products.
C
3b158306d335459ff55dcf29e46010e8
5b0eb9c68749ef1f71ebdb198219666b
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1561559700
["4\n5 1\n1 1 2 3 1\n4 2\n6 4 8 5\n2 2\n1 6\n3 5\n5 2 5"]
NoteIn the first example query you can choose the price $$$B=2$$$. It is easy to see that the difference between each old price and each new price $$$B=2$$$ is no more than $$$1$$$.In the second example query you can choose the price $$$B=6$$$ and then all the differences between old and new price $$$B=6$$$ will be no more than $$$2$$$.In the third example query you cannot choose any suitable price $$$B$$$. For any value $$$B$$$ at least one condition out of two will be violated: $$$|1-B| \le 2$$$, $$$|6-B| \le 2$$$.In the fourth example query all values $$$B$$$ between $$$1$$$ and $$$7$$$ are valid. But the maximum is $$$7$$$, so it's the answer.
PASSED
900
standard input
1 second
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is presented by two lines. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100, 1 \le k \le 10^8$$$) — the number of products and the value $$$k$$$. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^8$$$), where $$$a_i$$$ is the price of the $$$i$$$-th product.
["2\n6\n-1\n7"]
#include<stdio.h> #include<malloc.h> void swap(int*x,int*y) { int temp; temp=*x; *x=*y; *y=temp; } void bubblesort(int arr[],int num) { int i,j; for(i=0;i<num-1;i++) { for(j=0;j<num-1-i;j++) { if(arr[j]>arr[j+1]) swap(&arr[j],&arr[j+1]); } } /*for(i=0;i<num;i++) printf("%d ",arr[i]); printf("\n");*/ } int main() { int n,k,cases,i,j; int *arr; scanf("%d",&cases); for(i=0;i<cases;i++) { scanf("%d%d",&n,&k); arr=(int*)malloc(n*sizeof(int)); for(j=0;j<n;j++) scanf("%d",&arr[j]); bubblesort(arr,n); //printf("k=%d\t%d\t%d\n",k,arr[0]+2*k,arr[n-1]); if((arr[0]+2*k)>=arr[n-1]) { //if((arr[0]+2*k)>arr[n-1]) printf("%d\n",arr[0]+k); //else //printf("%d\n",arr[n-1]-k); } else printf("-1\n"); } }
There are $$$n$$$ products in the shop. The price of the $$$i$$$-th product is $$$a_i$$$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.In fact, the owner of the shop can change the price of some product $$$i$$$ in such a way that the difference between the old price of this product $$$a_i$$$ and the new price $$$b_i$$$ is at most $$$k$$$. In other words, the condition $$$|a_i - b_i| \le k$$$ should be satisfied ($$$|x|$$$ is the absolute value of $$$x$$$).He can change the price for each product not more than once. Note that he can leave the old prices for some products. The new price $$$b_i$$$ of each product $$$i$$$ should be positive (i.e. $$$b_i &gt; 0$$$ should be satisfied for all $$$i$$$ from $$$1$$$ to $$$n$$$).Your task is to find out the maximum possible equal price $$$B$$$ of all productts with the restriction that for all products the condiion $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the same new price of all products) or report that it is impossible to find such price $$$B$$$.Note that the chosen price $$$B$$$ should be integer.You should answer $$$q$$$ independent queries.
Print $$$q$$$ integers, where the $$$i$$$-th integer is the answer $$$B$$$ on the $$$i$$$-th query. If it is impossible to equalize prices of all given products with restriction that for all products the condition $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the new equal price of all products), print -1. Otherwise print the maximum possible equal price of all products.
C
3b158306d335459ff55dcf29e46010e8
9a3ed271366e45d421e078433a07e2c1
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1561559700
["4\n5 1\n1 1 2 3 1\n4 2\n6 4 8 5\n2 2\n1 6\n3 5\n5 2 5"]
NoteIn the first example query you can choose the price $$$B=2$$$. It is easy to see that the difference between each old price and each new price $$$B=2$$$ is no more than $$$1$$$.In the second example query you can choose the price $$$B=6$$$ and then all the differences between old and new price $$$B=6$$$ will be no more than $$$2$$$.In the third example query you cannot choose any suitable price $$$B$$$. For any value $$$B$$$ at least one condition out of two will be violated: $$$|1-B| \le 2$$$, $$$|6-B| \le 2$$$.In the fourth example query all values $$$B$$$ between $$$1$$$ and $$$7$$$ are valid. But the maximum is $$$7$$$, so it's the answer.
PASSED
900
standard input
1 second
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is presented by two lines. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100, 1 \le k \le 10^8$$$) — the number of products and the value $$$k$$$. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^8$$$), where $$$a_i$$$ is the price of the $$$i$$$-th product.
["2\n6\n-1\n7"]
#include<stdio.h> #include<malloc.h> void swap(int*x,int*y) { int temp; temp=*x; *x=*y; *y=temp; } void bubblesort(int arr[],int num) { int i,j; for(i=0;i<num-1;i++) { for(j=0;j<num-1-i;j++) { if(arr[j]>arr[j+1]) swap(&arr[j],&arr[j+1]); } } /*for(i=0;i<num;i++) printf("%d ",arr[i]); printf("\n");*/ } int main() { int n,k,cases,i,j; int *arr; scanf("%d",&cases); for(i=0;i<cases;i++) { scanf("%d%d",&n,&k); arr=(int*)malloc(n*sizeof(int)); for(j=0;j<n;j++) scanf("%d",&arr[j]); bubblesort(arr,n); //printf("k=%d\t%d\t%d\n",k,arr[0]+2*k,arr[n-1]); if((arr[0]+2*k)>=arr[n-1]) { if((arr[0]+2*k)>arr[n-1]) printf("%d\n",arr[0]+k); else printf("%d\n",arr[n-1]-k); } else printf("-1\n"); } }
There are $$$n$$$ products in the shop. The price of the $$$i$$$-th product is $$$a_i$$$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.In fact, the owner of the shop can change the price of some product $$$i$$$ in such a way that the difference between the old price of this product $$$a_i$$$ and the new price $$$b_i$$$ is at most $$$k$$$. In other words, the condition $$$|a_i - b_i| \le k$$$ should be satisfied ($$$|x|$$$ is the absolute value of $$$x$$$).He can change the price for each product not more than once. Note that he can leave the old prices for some products. The new price $$$b_i$$$ of each product $$$i$$$ should be positive (i.e. $$$b_i &gt; 0$$$ should be satisfied for all $$$i$$$ from $$$1$$$ to $$$n$$$).Your task is to find out the maximum possible equal price $$$B$$$ of all productts with the restriction that for all products the condiion $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the same new price of all products) or report that it is impossible to find such price $$$B$$$.Note that the chosen price $$$B$$$ should be integer.You should answer $$$q$$$ independent queries.
Print $$$q$$$ integers, where the $$$i$$$-th integer is the answer $$$B$$$ on the $$$i$$$-th query. If it is impossible to equalize prices of all given products with restriction that for all products the condition $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the new equal price of all products), print -1. Otherwise print the maximum possible equal price of all products.
C
3b158306d335459ff55dcf29e46010e8
cf21c0c761bf5a93d24caef6836d4a36
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1561559700
["4\n5 1\n1 1 2 3 1\n4 2\n6 4 8 5\n2 2\n1 6\n3 5\n5 2 5"]
NoteIn the first example query you can choose the price $$$B=2$$$. It is easy to see that the difference between each old price and each new price $$$B=2$$$ is no more than $$$1$$$.In the second example query you can choose the price $$$B=6$$$ and then all the differences between old and new price $$$B=6$$$ will be no more than $$$2$$$.In the third example query you cannot choose any suitable price $$$B$$$. For any value $$$B$$$ at least one condition out of two will be violated: $$$|1-B| \le 2$$$, $$$|6-B| \le 2$$$.In the fourth example query all values $$$B$$$ between $$$1$$$ and $$$7$$$ are valid. But the maximum is $$$7$$$, so it's the answer.
PASSED
900
standard input
1 second
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is presented by two lines. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100, 1 \le k \le 10^8$$$) — the number of products and the value $$$k$$$. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^8$$$), where $$$a_i$$$ is the price of the $$$i$$$-th product.
["2\n6\n-1\n7"]
#include<stdio.h> int main() { int t,i; scanf("%d",&t); for(i=0;i<t;i++) { long int n,k; scanf("%ld %ld",&n,&k); long int a[n],j,l; for(j=0;j<n;j++) { scanf("%ld",&a[j]); } long int min=a[0],max=a[1]; for(l=0;l<n;l++) { if(a[l]>max) max=a[l]; else max=max+1-1; if(a[l]<min) min=a[l]; else min=min+1-1; } if(n==1) printf("%ld\n",a[0]+k); else { if(min+k>=max-k) printf("%ld\n",min+k); else printf("-1\n");} } return 0; }
There are $$$n$$$ products in the shop. The price of the $$$i$$$-th product is $$$a_i$$$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.In fact, the owner of the shop can change the price of some product $$$i$$$ in such a way that the difference between the old price of this product $$$a_i$$$ and the new price $$$b_i$$$ is at most $$$k$$$. In other words, the condition $$$|a_i - b_i| \le k$$$ should be satisfied ($$$|x|$$$ is the absolute value of $$$x$$$).He can change the price for each product not more than once. Note that he can leave the old prices for some products. The new price $$$b_i$$$ of each product $$$i$$$ should be positive (i.e. $$$b_i &gt; 0$$$ should be satisfied for all $$$i$$$ from $$$1$$$ to $$$n$$$).Your task is to find out the maximum possible equal price $$$B$$$ of all productts with the restriction that for all products the condiion $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the same new price of all products) or report that it is impossible to find such price $$$B$$$.Note that the chosen price $$$B$$$ should be integer.You should answer $$$q$$$ independent queries.
Print $$$q$$$ integers, where the $$$i$$$-th integer is the answer $$$B$$$ on the $$$i$$$-th query. If it is impossible to equalize prices of all given products with restriction that for all products the condition $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the new equal price of all products), print -1. Otherwise print the maximum possible equal price of all products.
C
3b158306d335459ff55dcf29e46010e8
0492e5b7992dbfe7fb213312f317021a
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1561559700
["4\n5 1\n1 1 2 3 1\n4 2\n6 4 8 5\n2 2\n1 6\n3 5\n5 2 5"]
NoteIn the first example query you can choose the price $$$B=2$$$. It is easy to see that the difference between each old price and each new price $$$B=2$$$ is no more than $$$1$$$.In the second example query you can choose the price $$$B=6$$$ and then all the differences between old and new price $$$B=6$$$ will be no more than $$$2$$$.In the third example query you cannot choose any suitable price $$$B$$$. For any value $$$B$$$ at least one condition out of two will be violated: $$$|1-B| \le 2$$$, $$$|6-B| \le 2$$$.In the fourth example query all values $$$B$$$ between $$$1$$$ and $$$7$$$ are valid. But the maximum is $$$7$$$, so it's the answer.
PASSED
900
standard input
1 second
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is presented by two lines. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100, 1 \le k \le 10^8$$$) — the number of products and the value $$$k$$$. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^8$$$), where $$$a_i$$$ is the price of the $$$i$$$-th product.
["2\n6\n-1\n7"]
#include<stdio.h> int main(void) { int i,j,n,q; scanf("%d",&q); long int a,k,min,max; for(i=0;i<q;i++) { scanf("%d %ld",&n,&k); for(j=0,max=-1;j<n;j++) { scanf("%ld",&a); if(!j) min=a; else min=min>a?a:min; max=max<a?a:max; } if(max-min>2*k) printf("%ld\n",-1); else { if(min==max) printf("%ld\n",min+k); else if(min+k==max) printf("%ld\n",max); else if(min+k<max) printf("%ld\n",min+k); else if(min+k>max) printf("%ld\n",min+k); } } return 0; }
There are $$$n$$$ products in the shop. The price of the $$$i$$$-th product is $$$a_i$$$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.In fact, the owner of the shop can change the price of some product $$$i$$$ in such a way that the difference between the old price of this product $$$a_i$$$ and the new price $$$b_i$$$ is at most $$$k$$$. In other words, the condition $$$|a_i - b_i| \le k$$$ should be satisfied ($$$|x|$$$ is the absolute value of $$$x$$$).He can change the price for each product not more than once. Note that he can leave the old prices for some products. The new price $$$b_i$$$ of each product $$$i$$$ should be positive (i.e. $$$b_i &gt; 0$$$ should be satisfied for all $$$i$$$ from $$$1$$$ to $$$n$$$).Your task is to find out the maximum possible equal price $$$B$$$ of all productts with the restriction that for all products the condiion $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the same new price of all products) or report that it is impossible to find such price $$$B$$$.Note that the chosen price $$$B$$$ should be integer.You should answer $$$q$$$ independent queries.
Print $$$q$$$ integers, where the $$$i$$$-th integer is the answer $$$B$$$ on the $$$i$$$-th query. If it is impossible to equalize prices of all given products with restriction that for all products the condition $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the new equal price of all products), print -1. Otherwise print the maximum possible equal price of all products.
C
3b158306d335459ff55dcf29e46010e8
1b8683603f9c1a3337859a043497f14d
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "math" ]
1561559700
["4\n5 1\n1 1 2 3 1\n4 2\n6 4 8 5\n2 2\n1 6\n3 5\n5 2 5"]
NoteIn the first example query you can choose the price $$$B=2$$$. It is easy to see that the difference between each old price and each new price $$$B=2$$$ is no more than $$$1$$$.In the second example query you can choose the price $$$B=6$$$ and then all the differences between old and new price $$$B=6$$$ will be no more than $$$2$$$.In the third example query you cannot choose any suitable price $$$B$$$. For any value $$$B$$$ at least one condition out of two will be violated: $$$|1-B| \le 2$$$, $$$|6-B| \le 2$$$.In the fourth example query all values $$$B$$$ between $$$1$$$ and $$$7$$$ are valid. But the maximum is $$$7$$$, so it's the answer.
PASSED
900
standard input
1 second
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is presented by two lines. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100, 1 \le k \le 10^8$$$) — the number of products and the value $$$k$$$. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^8$$$), where $$$a_i$$$ is the price of the $$$i$$$-th product.
["2\n6\n-1\n7"]
#include <stdio.h> int main() { int q; scanf("%d", &q); for(int i=0; i<q; i++){ int n; long long int min, max; scanf("%d", &n); long long int k, ara[n]; scanf("%I64d", &k); for(int j=0; j<n; j++){ scanf("%I64d", &ara[j]); } min = max = ara[0]; for(int j=0; j<n; j++){ if(min>ara[j]){ min = ara[j]; } if(max<ara[j]){ max = ara[j]; } } if((min+k)>=(max-k)){ printf("%I64d\n", min+k); } else{ printf("-1\n"); } } return 0; }
Pavel has several sticks with lengths equal to powers of two.He has $$$a_0$$$ sticks of length $$$2^0 = 1$$$, $$$a_1$$$ sticks of length $$$2^1 = 2$$$, ..., $$$a_{n-1}$$$ sticks of length $$$2^{n-1}$$$. Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.It is forbidden to break sticks, and each triangle should consist of exactly three sticks.Find the maximum possible number of triangles.
Print a single integer — the maximum possible number of non-degenerate triangles that Pavel can make.
C
a8f3e94845cb15a483ce8f774779efac
9a13216aa625a7e00b9eda8f3b04381e
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "dp", "greedy", "fft", "ternary search", "brute force" ]
1554550500
["5\n1 2 2 2 2", "3\n1 1 1", "3\n3 3 3"]
NoteIn the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): $$$(2^0, 2^4, 2^4)$$$, $$$(2^1, 2^3, 2^3)$$$, $$$(2^1, 2^2, 2^2)$$$.In the second example, Pavel cannot make a single triangle.In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): $$$(2^0, 2^0, 2^0)$$$, $$$(2^1, 2^1, 2^1)$$$, $$$(2^2, 2^2, 2^2)$$$.
PASSED
1,900
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$) — the number of different lengths of sticks. The second line contains $$$n$$$ integers $$$a_0$$$, $$$a_1$$$, ..., $$$a_{n-1}$$$ ($$$1 \leq a_i \leq 10^9$$$), where $$$a_i$$$ is the number of sticks with the length equal to $$$2^i$$$.
["3", "0", "3"]
#include<stdio.h> #define ll long long int main() { long long int n; scanf("%lld",&n); ll cnt=0,cnt1=0,temp; for(int i=0;i<n;i++) { scanf("%lld",&temp); if(temp==1) cnt1++; else if(temp==2) { if(cnt1>0) { cnt1--; cnt++; } else cnt1+=2; } else { while(temp>=2&&cnt1) { cnt++; cnt1--; temp-=2; } cnt+=temp/3; cnt1+=temp%3; } } printf("%lld",cnt); return 0; }
Pavel has several sticks with lengths equal to powers of two.He has $$$a_0$$$ sticks of length $$$2^0 = 1$$$, $$$a_1$$$ sticks of length $$$2^1 = 2$$$, ..., $$$a_{n-1}$$$ sticks of length $$$2^{n-1}$$$. Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.It is forbidden to break sticks, and each triangle should consist of exactly three sticks.Find the maximum possible number of triangles.
Print a single integer — the maximum possible number of non-degenerate triangles that Pavel can make.
C
a8f3e94845cb15a483ce8f774779efac
a100fe7b2e217df5488c86a0e1fb3d3d
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "dp", "greedy", "fft", "ternary search", "brute force" ]
1554550500
["5\n1 2 2 2 2", "3\n1 1 1", "3\n3 3 3"]
NoteIn the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): $$$(2^0, 2^4, 2^4)$$$, $$$(2^1, 2^3, 2^3)$$$, $$$(2^1, 2^2, 2^2)$$$.In the second example, Pavel cannot make a single triangle.In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): $$$(2^0, 2^0, 2^0)$$$, $$$(2^1, 2^1, 2^1)$$$, $$$(2^2, 2^2, 2^2)$$$.
PASSED
1,900
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$) — the number of different lengths of sticks. The second line contains $$$n$$$ integers $$$a_0$$$, $$$a_1$$$, ..., $$$a_{n-1}$$$ ($$$1 \leq a_i \leq 10^9$$$), where $$$a_i$$$ is the number of sticks with the length equal to $$$2^i$$$.
["3", "0", "3"]
#include<stdio.h> int main(void){ unsigned long n,p;unsigned long long g=0;int count=0; scanf("%lu\n",&n); while(n>0){ scanf("%lu",&p); while(p>1){ if(count!=0){ count--; g++; p=p-2; } else{ g=g+p/3; if((p%3)==1) count++; else if((p%3)==2) count=count+2; p=0; } } if((p==1) && (n!=1)) count++; n--; } printf("%I64u\n",g); return 0; }
Pavel has several sticks with lengths equal to powers of two.He has $$$a_0$$$ sticks of length $$$2^0 = 1$$$, $$$a_1$$$ sticks of length $$$2^1 = 2$$$, ..., $$$a_{n-1}$$$ sticks of length $$$2^{n-1}$$$. Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.It is forbidden to break sticks, and each triangle should consist of exactly three sticks.Find the maximum possible number of triangles.
Print a single integer — the maximum possible number of non-degenerate triangles that Pavel can make.
C
a8f3e94845cb15a483ce8f774779efac
c261af7304e6af20abfb823cd39d89dd
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "dp", "greedy", "fft", "ternary search", "brute force" ]
1554550500
["5\n1 2 2 2 2", "3\n1 1 1", "3\n3 3 3"]
NoteIn the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): $$$(2^0, 2^4, 2^4)$$$, $$$(2^1, 2^3, 2^3)$$$, $$$(2^1, 2^2, 2^2)$$$.In the second example, Pavel cannot make a single triangle.In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): $$$(2^0, 2^0, 2^0)$$$, $$$(2^1, 2^1, 2^1)$$$, $$$(2^2, 2^2, 2^2)$$$.
PASSED
1,900
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$) — the number of different lengths of sticks. The second line contains $$$n$$$ integers $$$a_0$$$, $$$a_1$$$, ..., $$$a_{n-1}$$$ ($$$1 \leq a_i \leq 10^9$$$), where $$$a_i$$$ is the number of sticks with the length equal to $$$2^i$$$.
["3", "0", "3"]
#include<stdio.h> int main() { long long int n,basket=0,c=0,pair,a; scanf("%lld", &n); for(int i=1;i<=n;i++) { scanf("%lld", &a); pair=a/2; if (basket<(a/2)) pair=basket; basket-=pair; a-=2*pair; c+=pair+a/3; basket+=a%3; } printf("%lld", c); return 0; }
Pavel has several sticks with lengths equal to powers of two.He has $$$a_0$$$ sticks of length $$$2^0 = 1$$$, $$$a_1$$$ sticks of length $$$2^1 = 2$$$, ..., $$$a_{n-1}$$$ sticks of length $$$2^{n-1}$$$. Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.It is forbidden to break sticks, and each triangle should consist of exactly three sticks.Find the maximum possible number of triangles.
Print a single integer — the maximum possible number of non-degenerate triangles that Pavel can make.
C
a8f3e94845cb15a483ce8f774779efac
309811e127444cb4573c451d296f33c9
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "dp", "greedy", "fft", "ternary search", "brute force" ]
1554550500
["5\n1 2 2 2 2", "3\n1 1 1", "3\n3 3 3"]
NoteIn the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): $$$(2^0, 2^4, 2^4)$$$, $$$(2^1, 2^3, 2^3)$$$, $$$(2^1, 2^2, 2^2)$$$.In the second example, Pavel cannot make a single triangle.In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): $$$(2^0, 2^0, 2^0)$$$, $$$(2^1, 2^1, 2^1)$$$, $$$(2^2, 2^2, 2^2)$$$.
PASSED
1,900
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$) — the number of different lengths of sticks. The second line contains $$$n$$$ integers $$$a_0$$$, $$$a_1$$$, ..., $$$a_{n-1}$$$ ($$$1 \leq a_i \leq 10^9$$$), where $$$a_i$$$ is the number of sticks with the length equal to $$$2^i$$$.
["3", "0", "3"]
#include<stdio.h> int main() { long long N, count=0; long long int carry=0; scanf("%lli", &N); long long int curr; while (N>0) { scanf("%lli", &curr); while (carry>0 && curr>1) { carry--; curr=curr-2; count++; } count=count+(curr/3); carry=carry+(curr%3); N--; } printf("%lli", count); return 0; }
Pavel has several sticks with lengths equal to powers of two.He has $$$a_0$$$ sticks of length $$$2^0 = 1$$$, $$$a_1$$$ sticks of length $$$2^1 = 2$$$, ..., $$$a_{n-1}$$$ sticks of length $$$2^{n-1}$$$. Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.It is forbidden to break sticks, and each triangle should consist of exactly three sticks.Find the maximum possible number of triangles.
Print a single integer — the maximum possible number of non-degenerate triangles that Pavel can make.
C
a8f3e94845cb15a483ce8f774779efac
6b5b3a1f21519b84fe5c903fef053cc2
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "dp", "greedy", "fft", "ternary search", "brute force" ]
1554550500
["5\n1 2 2 2 2", "3\n1 1 1", "3\n3 3 3"]
NoteIn the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): $$$(2^0, 2^4, 2^4)$$$, $$$(2^1, 2^3, 2^3)$$$, $$$(2^1, 2^2, 2^2)$$$.In the second example, Pavel cannot make a single triangle.In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): $$$(2^0, 2^0, 2^0)$$$, $$$(2^1, 2^1, 2^1)$$$, $$$(2^2, 2^2, 2^2)$$$.
PASSED
1,900
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$) — the number of different lengths of sticks. The second line contains $$$n$$$ integers $$$a_0$$$, $$$a_1$$$, ..., $$$a_{n-1}$$$ ($$$1 \leq a_i \leq 10^9$$$), where $$$a_i$$$ is the number of sticks with the length equal to $$$2^i$$$.
["3", "0", "3"]
#include<stdio.h> int main() { unsigned long long N, count=0; long long int carry=0; scanf("%I64u", &N); long long int curr; while (N>0) { scanf("%I64d", &curr); while (carry>0 && curr>1) { carry--; curr=curr-2; count++; } count=count+(curr/3); carry=carry+(curr%3); N--; } printf("%I64u", count); return 0; }
Pavel has several sticks with lengths equal to powers of two.He has $$$a_0$$$ sticks of length $$$2^0 = 1$$$, $$$a_1$$$ sticks of length $$$2^1 = 2$$$, ..., $$$a_{n-1}$$$ sticks of length $$$2^{n-1}$$$. Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.It is forbidden to break sticks, and each triangle should consist of exactly three sticks.Find the maximum possible number of triangles.
Print a single integer — the maximum possible number of non-degenerate triangles that Pavel can make.
C
a8f3e94845cb15a483ce8f774779efac
b7947f91f0361cd6d5349f83abc44a69
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "dp", "greedy", "fft", "ternary search", "brute force" ]
1554550500
["5\n1 2 2 2 2", "3\n1 1 1", "3\n3 3 3"]
NoteIn the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): $$$(2^0, 2^4, 2^4)$$$, $$$(2^1, 2^3, 2^3)$$$, $$$(2^1, 2^2, 2^2)$$$.In the second example, Pavel cannot make a single triangle.In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): $$$(2^0, 2^0, 2^0)$$$, $$$(2^1, 2^1, 2^1)$$$, $$$(2^2, 2^2, 2^2)$$$.
PASSED
1,900
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$) — the number of different lengths of sticks. The second line contains $$$n$$$ integers $$$a_0$$$, $$$a_1$$$, ..., $$$a_{n-1}$$$ ($$$1 \leq a_i \leq 10^9$$$), where $$$a_i$$$ is the number of sticks with the length equal to $$$2^i$$$.
["3", "0", "3"]
#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;} void run (void) { const i32 n = read_int(); i32 *a = (i32 *) calloc (n, sizeof (i32)); for (i32 i = 0; i < n; ++i) { a[i] = read_int(); } i64 ans = 0; i64 remain = 0; for (i32 i = 0; i < n; ++i) { while (remain > 0 && a[i] >= 2) { ans++; remain--; a[i] -= 2; } ans += a[i] / 3; remain += a[i] % 3; } print_int (ans); puts(""); } int main (void) { run (); return 0; }
Pavel has several sticks with lengths equal to powers of two.He has $$$a_0$$$ sticks of length $$$2^0 = 1$$$, $$$a_1$$$ sticks of length $$$2^1 = 2$$$, ..., $$$a_{n-1}$$$ sticks of length $$$2^{n-1}$$$. Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.It is forbidden to break sticks, and each triangle should consist of exactly three sticks.Find the maximum possible number of triangles.
Print a single integer — the maximum possible number of non-degenerate triangles that Pavel can make.
C
a8f3e94845cb15a483ce8f774779efac
4a8e31be5fc4ab7c7cafcbcd6527e28b
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "dp", "greedy", "fft", "ternary search", "brute force" ]
1554550500
["5\n1 2 2 2 2", "3\n1 1 1", "3\n3 3 3"]
NoteIn the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): $$$(2^0, 2^4, 2^4)$$$, $$$(2^1, 2^3, 2^3)$$$, $$$(2^1, 2^2, 2^2)$$$.In the second example, Pavel cannot make a single triangle.In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): $$$(2^0, 2^0, 2^0)$$$, $$$(2^1, 2^1, 2^1)$$$, $$$(2^2, 2^2, 2^2)$$$.
PASSED
1,900
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$) — the number of different lengths of sticks. The second line contains $$$n$$$ integers $$$a_0$$$, $$$a_1$$$, ..., $$$a_{n-1}$$$ ($$$1 \leq a_i \leq 10^9$$$), where $$$a_i$$$ is the number of sticks with the length equal to $$$2^i$$$.
["3", "0", "3"]
#include<stdio.h> long long n,a[300000],l=0,mg=0; int main() { scanf("%lld",&n); for(long long i=0;i<n;i++) { scanf("%lld",&a[i]); } for(long long i =0;i<n;i++) { if (l<=a[i]/2) { mg+=l; a[i]=a[i]-2*l; l=0; } else { mg+=a[i]/2; l=l-a[i]/2; a[i]%=2; } mg+=a[i]/3; a[i]%=3; l+=a[i]; } printf("%lld\n", mg); return 0; }
Pavel has several sticks with lengths equal to powers of two.He has $$$a_0$$$ sticks of length $$$2^0 = 1$$$, $$$a_1$$$ sticks of length $$$2^1 = 2$$$, ..., $$$a_{n-1}$$$ sticks of length $$$2^{n-1}$$$. Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.It is forbidden to break sticks, and each triangle should consist of exactly three sticks.Find the maximum possible number of triangles.
Print a single integer — the maximum possible number of non-degenerate triangles that Pavel can make.
C
a8f3e94845cb15a483ce8f774779efac
7a7c511e02065d76be4c5f28a58c8566
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "dp", "greedy", "fft", "ternary search", "brute force" ]
1554550500
["5\n1 2 2 2 2", "3\n1 1 1", "3\n3 3 3"]
NoteIn the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): $$$(2^0, 2^4, 2^4)$$$, $$$(2^1, 2^3, 2^3)$$$, $$$(2^1, 2^2, 2^2)$$$.In the second example, Pavel cannot make a single triangle.In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): $$$(2^0, 2^0, 2^0)$$$, $$$(2^1, 2^1, 2^1)$$$, $$$(2^2, 2^2, 2^2)$$$.
PASSED
1,900
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$) — the number of different lengths of sticks. The second line contains $$$n$$$ integers $$$a_0$$$, $$$a_1$$$, ..., $$$a_{n-1}$$$ ($$$1 \leq a_i \leq 10^9$$$), where $$$a_i$$$ is the number of sticks with the length equal to $$$2^i$$$.
["3", "0", "3"]
#include<stdio.h> #define ll long long ll min(ll a, ll b) { return a<b?a:b; } int main() { ll mi,n,a,one=0,set=0; scanf("%lld",&n); //n=300000; for(ll i=0; i<n; i++) { scanf("%lld",&a); // a=1000000000; mi= min(one,a/2); set+= mi; one-= mi; a-= 2*mi; set+= a/3; a= a%3; one+=a; } printf("%lld\n",set); return 0; }
Pavel has several sticks with lengths equal to powers of two.He has $$$a_0$$$ sticks of length $$$2^0 = 1$$$, $$$a_1$$$ sticks of length $$$2^1 = 2$$$, ..., $$$a_{n-1}$$$ sticks of length $$$2^{n-1}$$$. Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.It is forbidden to break sticks, and each triangle should consist of exactly three sticks.Find the maximum possible number of triangles.
Print a single integer — the maximum possible number of non-degenerate triangles that Pavel can make.
C
a8f3e94845cb15a483ce8f774779efac
88ce42878c283de74fdf255b61ce6191
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "dp", "greedy", "fft", "ternary search", "brute force" ]
1554550500
["5\n1 2 2 2 2", "3\n1 1 1", "3\n3 3 3"]
NoteIn the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): $$$(2^0, 2^4, 2^4)$$$, $$$(2^1, 2^3, 2^3)$$$, $$$(2^1, 2^2, 2^2)$$$.In the second example, Pavel cannot make a single triangle.In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): $$$(2^0, 2^0, 2^0)$$$, $$$(2^1, 2^1, 2^1)$$$, $$$(2^2, 2^2, 2^2)$$$.
PASSED
1,900
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$) — the number of different lengths of sticks. The second line contains $$$n$$$ integers $$$a_0$$$, $$$a_1$$$, ..., $$$a_{n-1}$$$ ($$$1 \leq a_i \leq 10^9$$$), where $$$a_i$$$ is the number of sticks with the length equal to $$$2^i$$$.
["3", "0", "3"]
#include<stdio.h> #define ll long long long long arr[300005]; #define min(a,b) (a>b)?b:a int n; long long solve() { // for(int i=0;i<n;i++) // printf("%lld ",arr[i]); long long c2=0,c4=0; long long ans=0; for(long long i=0;i<n;i++) { if(arr[i]==0 || arr[i]==1) continue; long long p1=arr[i]%3; if(p1==1) { ans+=((arr[i]-4)/3); arr[i]=4; } else if(p1==2) { ans+=((arr[i]-2)/3); arr[i]=2; } else { ans+=(arr[i]/3); arr[i]=0; } } // for(int i=0;i<n;i++)/ // printf("%lld ",arr[i]); for(long long i=0;i<n;i++) { if(arr[i]==2) c2++; else if(arr[i]==4) { c4++; } } // printf("\n%lld\n",min(c2,c4)); ll mn=min(c2,c4); ans+=(mn*2); // printf("ans= %lld\n",ans); if(c2 < c4) { ans+=(((c4-c2)*4)/3); } else { ans+=(((c2-c4)*2)/3); } return ans; } int main() { long long ans=0; scanf("%d",&n); for(long long i=0;i<n;i++) scanf("%lld",&arr[i]); long long c=1,p1=0; while(p1 < n && arr[p1]!=1) p1++; if(p1==n) { ans+=solve(); } else { for(long long i=p1+1;i<n;i++) { if(arr[i]!=1) { long long pr=min((arr[i]/2),c); arr[i]-=2*pr; ans+=pr; c-=pr; if(arr[i]==1) c++; } else c++; } ans+=solve(); } printf("%lld\n",ans); return 0; }
Pavel has several sticks with lengths equal to powers of two.He has $$$a_0$$$ sticks of length $$$2^0 = 1$$$, $$$a_1$$$ sticks of length $$$2^1 = 2$$$, ..., $$$a_{n-1}$$$ sticks of length $$$2^{n-1}$$$. Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.It is forbidden to break sticks, and each triangle should consist of exactly three sticks.Find the maximum possible number of triangles.
Print a single integer — the maximum possible number of non-degenerate triangles that Pavel can make.
C
a8f3e94845cb15a483ce8f774779efac
4576c021aad26d2947bac5f2d1d3b22e
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "dp", "greedy", "fft", "ternary search", "brute force" ]
1554550500
["5\n1 2 2 2 2", "3\n1 1 1", "3\n3 3 3"]
NoteIn the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): $$$(2^0, 2^4, 2^4)$$$, $$$(2^1, 2^3, 2^3)$$$, $$$(2^1, 2^2, 2^2)$$$.In the second example, Pavel cannot make a single triangle.In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): $$$(2^0, 2^0, 2^0)$$$, $$$(2^1, 2^1, 2^1)$$$, $$$(2^2, 2^2, 2^2)$$$.
PASSED
1,900
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$) — the number of different lengths of sticks. The second line contains $$$n$$$ integers $$$a_0$$$, $$$a_1$$$, ..., $$$a_{n-1}$$$ ($$$1 \leq a_i \leq 10^9$$$), where $$$a_i$$$ is the number of sticks with the length equal to $$$2^i$$$.
["3", "0", "3"]
#include<stdio.h> int main() { long long int N,i, gr=0, rem=0; scanf("%lld", &N); long long int ar[N]; for(i=0;i<N;i++) { scanf("%lld", &ar[i]); } for(i=0;i<N;i++) { if(ar[i]>=2) { if(rem==0) { gr+=ar[i]/3; rem+=ar[i]%3; } else if(rem!=0) { while((ar[i]>1)&&(rem>0)) { ar[i]-=2; rem--; gr++; } gr+=ar[i]/3; rem+=ar[i]%3; } } else { rem=rem+ar[i]%3; } } printf("%lld\n",gr); return 0; }
Pavel has several sticks with lengths equal to powers of two.He has $$$a_0$$$ sticks of length $$$2^0 = 1$$$, $$$a_1$$$ sticks of length $$$2^1 = 2$$$, ..., $$$a_{n-1}$$$ sticks of length $$$2^{n-1}$$$. Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.It is forbidden to break sticks, and each triangle should consist of exactly three sticks.Find the maximum possible number of triangles.
Print a single integer — the maximum possible number of non-degenerate triangles that Pavel can make.
C
a8f3e94845cb15a483ce8f774779efac
376f2e65b67d050b308298d1e49141c6
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "dp", "greedy", "fft", "ternary search", "brute force" ]
1554550500
["5\n1 2 2 2 2", "3\n1 1 1", "3\n3 3 3"]
NoteIn the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): $$$(2^0, 2^4, 2^4)$$$, $$$(2^1, 2^3, 2^3)$$$, $$$(2^1, 2^2, 2^2)$$$.In the second example, Pavel cannot make a single triangle.In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): $$$(2^0, 2^0, 2^0)$$$, $$$(2^1, 2^1, 2^1)$$$, $$$(2^2, 2^2, 2^2)$$$.
PASSED
1,900
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$) — the number of different lengths of sticks. The second line contains $$$n$$$ integers $$$a_0$$$, $$$a_1$$$, ..., $$$a_{n-1}$$$ ($$$1 \leq a_i \leq 10^9$$$), where $$$a_i$$$ is the number of sticks with the length equal to $$$2^i$$$.
["3", "0", "3"]
#include<stdio.h> #include<stdlib.h> int read() { int x=0; char ch = getchar(); while( ch<'0' || ch>'9' ) ch = getchar(); while( ch>='0' && ch<='9' ){ x = (x<<3) + (x<<1) + ch - 48; ch = getchar(); } return x; } int a[300005]={}; int main() { int n; long long pair=0, ans=0; //见祖宗警告 n = read(); for( int i=0; i<n; i++ ) a[i] = read(); for( int i=n-1; i>=0; i-- ){ //只可能搭出等边和等腰三角形 pair += a[i]>>1; // 2^i 有 a[i]/2 对 if( a[i]%2 && pair ){ //如果pair大于0 就抽出一个pair和多出来的 2^i 边 凑成等腰或等边 pair--; //一个pair等于两条大于等于 2^i 边 可以凑成等腰或等边 ans++; } } ans += 2*pair/3; //剩下总共 2*pair 条边 任意两条目前最长边加一条最短边可以凑成一个三角形(凑完后把边个数删去) printf("%lld\n", ans); //system("pause"); return 0; }
Pavel has several sticks with lengths equal to powers of two.He has $$$a_0$$$ sticks of length $$$2^0 = 1$$$, $$$a_1$$$ sticks of length $$$2^1 = 2$$$, ..., $$$a_{n-1}$$$ sticks of length $$$2^{n-1}$$$. Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle.It is forbidden to break sticks, and each triangle should consist of exactly three sticks.Find the maximum possible number of triangles.
Print a single integer — the maximum possible number of non-degenerate triangles that Pavel can make.
C
a8f3e94845cb15a483ce8f774779efac
85fd3392c55513afe4e53bd087d1259a
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "dp", "greedy", "fft", "ternary search", "brute force" ]
1554550500
["5\n1 2 2 2 2", "3\n1 1 1", "3\n3 3 3"]
NoteIn the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): $$$(2^0, 2^4, 2^4)$$$, $$$(2^1, 2^3, 2^3)$$$, $$$(2^1, 2^2, 2^2)$$$.In the second example, Pavel cannot make a single triangle.In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): $$$(2^0, 2^0, 2^0)$$$, $$$(2^1, 2^1, 2^1)$$$, $$$(2^2, 2^2, 2^2)$$$.
PASSED
1,900
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 300\,000$$$) — the number of different lengths of sticks. The second line contains $$$n$$$ integers $$$a_0$$$, $$$a_1$$$, ..., $$$a_{n-1}$$$ ($$$1 \leq a_i \leq 10^9$$$), where $$$a_i$$$ is the number of sticks with the length equal to $$$2^i$$$.
["3", "0", "3"]
#include<stdio.h> int a[300010]; long long s,t; int ans,n,i; int main() { scanf("%d",&n); for(i=0;i<n;i++)scanf("%d",&a[i]); t=0;ans=0; for(i=n-1;i>=0;i--) { s+=a[i]; if(a[i]==0)continue; if(a[i]%2==0)t=t+a[i]/2; if(a[i]==1) { if(t>0)t--;else ans++; } else t+=(a[i]-3)/2; } printf("%I64d",(s-ans)/3); }
Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.Bob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.For example, if Bob came up with the string $$$a$$$="abac", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: "ab", "ba", "ac". Therefore, the string $$$b$$$="abbaac".You are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.
C
ac77e2e6c86b5528b401debe9f68fc8e
1e4a43ef962e80ed64885ed27c3d08db
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1592318100
["4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz"]
NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of string $$$a$$$ are: "bc", "cd", "da", "af", so the string $$$b$$$="bccddaaf".
PASSED
800
standard input
2 seconds
The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$) — the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.
["abac\nac\nbcdaf\nzzzzzz"]
#include<stdio.h> #include<string.h> int main() { int t,i,j,l; char s[1000][1000]; scanf("%d",&t); for(i=0;i<t;i++) { scanf("%s",s[i]); } for(i=0;i<t;i++) { l = strlen(s[i]); for(j=0;j<l;j = j+2) { printf("%c",s[i][j]); } if(l%2==0) { printf("%c",s[i][l-1]); } printf("\n"); } return 0; }
Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.Bob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.For example, if Bob came up with the string $$$a$$$="abac", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: "ab", "ba", "ac". Therefore, the string $$$b$$$="abbaac".You are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.
C
ac77e2e6c86b5528b401debe9f68fc8e
4662c80d6aaca2aa9e8dab32173b74fc
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1592318100
["4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz"]
NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of string $$$a$$$ are: "bc", "cd", "da", "af", so the string $$$b$$$="bccddaaf".
PASSED
800
standard input
2 seconds
The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$) — the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.
["abac\nac\nbcdaf\nzzzzzz"]
#include<stdio.h> #include<string.h> int main() { int t,i,a,b; char string[100]; scanf("%d",&t); for(i=1;i<=t;i++) { scanf("%s",string); a=strlen(string); printf("%c",string[0]); for(b=1;b<a-1;b=b+2) { printf("%c",string[b]); } printf("%c\n",string[a-1]); } return 0; }
Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.Bob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.For example, if Bob came up with the string $$$a$$$="abac", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: "ab", "ba", "ac". Therefore, the string $$$b$$$="abbaac".You are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.
C
ac77e2e6c86b5528b401debe9f68fc8e
ca28a905c7ece727a19ff4c6f3867bde
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1592318100
["4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz"]
NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of string $$$a$$$ are: "bc", "cd", "da", "af", so the string $$$b$$$="bccddaaf".
PASSED
800
standard input
2 seconds
The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$) — the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.
["abac\nac\nbcdaf\nzzzzzz"]
#include<stdio.h> #include<string.h> int main() { int t,i,a,b; char string[100]; scanf("%d",&t); for(i=1;i<=t;i++) { scanf("%s",string); a=strlen(string); printf("%c",string[0]); for(b=1;b<a-1;b=b+2) { printf("%c",string[b]); } printf("%c\n",string[a-1]); } return 0; }
Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.Bob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.For example, if Bob came up with the string $$$a$$$="abac", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: "ab", "ba", "ac". Therefore, the string $$$b$$$="abbaac".You are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.
C
ac77e2e6c86b5528b401debe9f68fc8e
81f551abfe4c988d84bc3986d943c028
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1592318100
["4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz"]
NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of string $$$a$$$ are: "bc", "cd", "da", "af", so the string $$$b$$$="bccddaaf".
PASSED
800
standard input
2 seconds
The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$) — the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.
["abac\nac\nbcdaf\nzzzzzz"]
#include<stdio.h> #include<string.h> int main(){ int n; scanf("%d",&n); while(n--){ char a[101]; int c; scanf("%s",&a); c=strlen(a); for(int i=0;i<c;){ if(a[i]==a[i+1]){ printf("%c",a[i]); if(i==(c-2)){ printf("%c",a[i+1]); } i=i+2; } else{ printf("%c",a[i]); i=i+1; } } printf("\n"); } return 0; }
Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.Bob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.For example, if Bob came up with the string $$$a$$$="abac", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: "ab", "ba", "ac". Therefore, the string $$$b$$$="abbaac".You are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.
C
ac77e2e6c86b5528b401debe9f68fc8e
da856ee23dd3141aac010c44939a624f
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1592318100
["4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz"]
NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of string $$$a$$$ are: "bc", "cd", "da", "af", so the string $$$b$$$="bccddaaf".
PASSED
800
standard input
2 seconds
The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$) — the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.
["abac\nac\nbcdaf\nzzzzzz"]
#include <stdio.h> #include <string.h> int t, i, j, n, k; char a[101], b[101]; int main() { scanf("%d", &t); for(i=0; i<t; i++) { scanf("%s", &b); n=strlen(b); if(n==2) printf("%s\n", b); else { a[0]=b[0]; k=1; for(j=1; j<n-2; j=j+2) { a[k]=b[j]; k++; } a[k]=b[n-1]; for(j=0; j<=k; j++) printf("%c", a[j]); printf("\n"); } } }
Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.Bob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.For example, if Bob came up with the string $$$a$$$="abac", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: "ab", "ba", "ac". Therefore, the string $$$b$$$="abbaac".You are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.
C
ac77e2e6c86b5528b401debe9f68fc8e
37be7b3b35427fa20ca8b634056072fe
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1592318100
["4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz"]
NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of string $$$a$$$ are: "bc", "cd", "da", "af", so the string $$$b$$$="bccddaaf".
PASSED
800
standard input
2 seconds
The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$) — the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.
["abac\nac\nbcdaf\nzzzzzz"]
#include<stdio.h> #include<string.h> int main(){ char a[100]; int i,t,l; scanf("%d",&t); while(t!=0){ scanf("%s",a); l=strlen(a); for(i=0;i<l;i++){ if(i%2==1||i==0){ printf("%c",a[i]); } } printf("\n"); t--; } }
Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.Bob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.For example, if Bob came up with the string $$$a$$$="abac", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: "ab", "ba", "ac". Therefore, the string $$$b$$$="abbaac".You are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.
C
ac77e2e6c86b5528b401debe9f68fc8e
450002142b6bb0d13f88c225db16a503
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1592318100
["4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz"]
NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of string $$$a$$$ are: "bc", "cd", "da", "af", so the string $$$b$$$="bccddaaf".
PASSED
800
standard input
2 seconds
The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$) — the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.
["abac\nac\nbcdaf\nzzzzzz"]
#include<stdio.h> #include<stdlib.h> #include<string.h> struct arry { char *ch; }; char *original(char *arr,int l) { int i,k=0; char *c=(char *)malloc(100*sizeof(char)); for(i=0;arr[i]!='\0';i+=2) { c[k++]=arr[i]; } c[k++]=arr[l-1]; c[k++]='\0'; return c; free(c); } int main() { int t; scanf("%d",&t); struct arry o[t]; int i; for(i=0;i<t;i++) { char *b=(char *)malloc(100*sizeof(char)); scanf("%s",b); int l=strlen(b); if(l<=2) o[i].ch=b; else o[i].ch=original(b,l); } for(i=0;i<t;i++) printf("%s\n",o[i].ch); return 0; }
Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.Bob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.For example, if Bob came up with the string $$$a$$$="abac", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: "ab", "ba", "ac". Therefore, the string $$$b$$$="abbaac".You are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.
C
ac77e2e6c86b5528b401debe9f68fc8e
eabbbcb73adba64bf0348eedccd81276
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1592318100
["4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz"]
NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of string $$$a$$$ are: "bc", "cd", "da", "af", so the string $$$b$$$="bccddaaf".
PASSED
800
standard input
2 seconds
The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$) — the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.
["abac\nac\nbcdaf\nzzzzzz"]
#include<stdio.h> int main() { int n; scanf("%d",&n); while(n--) { int l; char s[100]; scanf("%s",s); l=strlen(s); printf("%c",s[0]); for(int i=0;i<l-1;i++) { i=i+1; printf("%c",s[i]); } printf("\n"); } }
Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.Bob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.For example, if Bob came up with the string $$$a$$$="abac", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: "ab", "ba", "ac". Therefore, the string $$$b$$$="abbaac".You are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.
C
ac77e2e6c86b5528b401debe9f68fc8e
ac6d9eb734fa2b412f7b14142da9bea6
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1592318100
["4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz"]
NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of string $$$a$$$ are: "bc", "cd", "da", "af", so the string $$$b$$$="bccddaaf".
PASSED
800
standard input
2 seconds
The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$) — the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.
["abac\nac\nbcdaf\nzzzzzz"]
#include<stdio.h> #include<string.h> main() { int i,l,n,j; scanf("%d",&n); char s[100],t[100]; for(i=0;i<n;i++){ scanf("%s",&s); l = strlen(s); for(j=0;j<l-2;j++){ if(j%2==0){ printf("%c",s[j]); } } printf("%c%c\n",s[l-2],s[l-1]); } return 0; }
Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.Bob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.For example, if Bob came up with the string $$$a$$$="abac", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: "ab", "ba", "ac". Therefore, the string $$$b$$$="abbaac".You are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.
C
ac77e2e6c86b5528b401debe9f68fc8e
74470386fc9f111db5926502f2a6a561
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1592318100
["4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz"]
NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of string $$$a$$$ are: "bc", "cd", "da", "af", so the string $$$b$$$="bccddaaf".
PASSED
800
standard input
2 seconds
The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$) — the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.
["abac\nac\nbcdaf\nzzzzzz"]
#include<stdio.h> #include<string.h> main() { int i,l,n,j; scanf("%d",&n); getchar(); char s[100],t[100]; for(i=0;i<n;i++){ scanf("%s",&s); getchar(); l = strlen(s); for(j=0;j<l-2;j++){ if(j%2==0){ printf("%c",s[j]); } } printf("%c%c\n",s[l-2],s[l-1]); } return 0; }
Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.Bob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.For example, if Bob came up with the string $$$a$$$="abac", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: "ab", "ba", "ac". Therefore, the string $$$b$$$="abbaac".You are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.
C
ac77e2e6c86b5528b401debe9f68fc8e
e34bf192e962c2df8d873d3146381970
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1592318100
["4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz"]
NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of string $$$a$$$ are: "bc", "cd", "da", "af", so the string $$$b$$$="bccddaaf".
PASSED
800
standard input
2 seconds
The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$) — the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.
["abac\nac\nbcdaf\nzzzzzz"]
#include<stdio.h> int main() { int t; scanf("%d",&t); while(t--) { char ch[100],i,flag=0,j; scanf("%s",ch); for(i=0;ch[i]!='\0';i++) { flag++; } if(flag<=2) { printf("%s\n",ch); } else { for(j=0;j<flag-1;j=j+2) { printf("%c",ch[j]); } printf("%c\n",ch[flag-1]); } } return 0; }
Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.Bob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.For example, if Bob came up with the string $$$a$$$="abac", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: "ab", "ba", "ac". Therefore, the string $$$b$$$="abbaac".You are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.
C
ac77e2e6c86b5528b401debe9f68fc8e
0e7c1349c45410b0c348c137dad69813
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1592318100
["4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz"]
NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of string $$$a$$$ are: "bc", "cd", "da", "af", so the string $$$b$$$="bccddaaf".
PASSED
800
standard input
2 seconds
The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$) — the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.
["abac\nac\nbcdaf\nzzzzzz"]
#include<stdio.h> #include<stdio.h> int main(){ int t; scanf("%d",&t); while(t--){ char s[100]; scanf("%s",s); int i; printf("%c",s[0]); printf("%c",s[1]); if(strlen(s) == 2){ printf("\n"); } else { for(i = 3; s[i] != '\0';i++){ if(i % 2 != 0){ printf("%c",s[i]); } } } printf("\n"); } return 0; }
Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.Bob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.For example, if Bob came up with the string $$$a$$$="abac", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: "ab", "ba", "ac". Therefore, the string $$$b$$$="abbaac".You are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.
C
ac77e2e6c86b5528b401debe9f68fc8e
a022d467c5de8a436aaaa98debf6ec2f
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1592318100
["4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz"]
NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of string $$$a$$$ are: "bc", "cd", "da", "af", so the string $$$b$$$="bccddaaf".
PASSED
800
standard input
2 seconds
The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$) — the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.
["abac\nac\nbcdaf\nzzzzzz"]
#include <stdio.h> #include <string.h> int main() { int t,i; char b[100]; scanf("%d",&t); for(int x=0;x<t;x++) { char a[100]={}; int j=1; scanf("%s",b); if(strlen(b)==2) printf("%s",b); else { a[0]=b[0]; for(i=1;i<strlen(b)-2;i=i+2) { a[j]=b[i]; j++; } a[j]=b[strlen(b)-1]; printf("%s",a); } printf("\n"); } return 0; }
Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.Bob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.For example, if Bob came up with the string $$$a$$$="abac", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: "ab", "ba", "ac". Therefore, the string $$$b$$$="abbaac".You are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.
C
ac77e2e6c86b5528b401debe9f68fc8e
7e11270777d5cfffc9d0c8499ba2e48c
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1592318100
["4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz"]
NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of string $$$a$$$ are: "bc", "cd", "da", "af", so the string $$$b$$$="bccddaaf".
PASSED
800
standard input
2 seconds
The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$) — the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.
["abac\nac\nbcdaf\nzzzzzz"]
#include<stdio.h> #include<string.h> int main() { int i,j,n,l; char a[105]; while(scanf("%d",&n)!=EOF){ for(i=1;i<=n;i++){ scanf("%s",&a); j=strlen(a); for(l=0;l<j;l++){ if(l%2==0||l==j-1){printf("%c",a[l]);} }printf("\n"); } } return 0; }
Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.Bob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.For example, if Bob came up with the string $$$a$$$="abac", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: "ab", "ba", "ac". Therefore, the string $$$b$$$="abbaac".You are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.
C
ac77e2e6c86b5528b401debe9f68fc8e
4a26263248185b718b245c303493e93b
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1592318100
["4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz"]
NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of string $$$a$$$ are: "bc", "cd", "da", "af", so the string $$$b$$$="bccddaaf".
PASSED
800
standard input
2 seconds
The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$) — the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.
["abac\nac\nbcdaf\nzzzzzz"]
#include<stdio.h> #include<string.h> int main() { int i,j,n,l; char a[105]; while(scanf("%d",&n)!=EOF){ for(i=1;i<=n;i++){ scanf("%s",&a); j=strlen(a); printf("%c%c",a[0],a[1]); for(l=3;l<j;l=l+2){ printf("%c",a[l]); }printf("\n"); } } return 0; }
Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.Bob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.For example, if Bob came up with the string $$$a$$$="abac", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: "ab", "ba", "ac". Therefore, the string $$$b$$$="abbaac".You are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.
C
ac77e2e6c86b5528b401debe9f68fc8e
c04f8c82effbb4e656d967049a47e2e1
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1592318100
["4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz"]
NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of string $$$a$$$ are: "bc", "cd", "da", "af", so the string $$$b$$$="bccddaaf".
PASSED
800
standard input
2 seconds
The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$) — the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.
["abac\nac\nbcdaf\nzzzzzz"]
#include<stdio.h> #include<string.h> int main() { char s[1000]; char s1[100]; char b; int t,l,i,j; scanf("%d",&t); while(t--) { scanf("%s",&s); l=strlen(s); if(l==2) { printf("%s\n",s); } else{ for(i=0,j=0;i<l,j<l;i=i+2,j++) { s1[j]=s[i]; b=s[l-1]; } printf("%s%c\n",s1,b); } printf ("\n"); } return 0; }
Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.Bob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.For example, if Bob came up with the string $$$a$$$="abac", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: "ab", "ba", "ac". Therefore, the string $$$b$$$="abbaac".You are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.
C
ac77e2e6c86b5528b401debe9f68fc8e
d3909afdc7e9d7f3991e83ebd853545b
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1592318100
["4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz"]
NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of string $$$a$$$ are: "bc", "cd", "da", "af", so the string $$$b$$$="bccddaaf".
PASSED
800
standard input
2 seconds
The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$) — the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.
["abac\nac\nbcdaf\nzzzzzz"]
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> int main(void) { int a, i = 0, A; char m[101], M[101] = { 0 }; scanf("%d", &a); A = a; while (a--) { i = 0; while (i++ < 100) { M[i] = 0, m[i] = 0; } scanf("%s", m); i = 0; while(m[2*i]!=0) { M[i] = m[2 * i]; i++; } M[i] = m[2 * i - 1]; i = 0; while (M[i] != 0) { printf("%c", M[i]); i++; } printf("\n"); } return 0; }
Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.Bob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.For example, if Bob came up with the string $$$a$$$="abac", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: "ab", "ba", "ac". Therefore, the string $$$b$$$="abbaac".You are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.
C
ac77e2e6c86b5528b401debe9f68fc8e
2fc472cf7092c94803ac397d3bccd74a
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1592318100
["4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz"]
NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of string $$$a$$$ are: "bc", "cd", "da", "af", so the string $$$b$$$="bccddaaf".
PASSED
800
standard input
2 seconds
The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$) — the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.
["abac\nac\nbcdaf\nzzzzzz"]
#include<stdio.h> #include<string.h> int main(){ int t; scanf("%d",&t); while(t--){ char stringInput[100],stringOutput[100]; scanf("%s",stringInput); int n = strlen(stringInput); if(n!=2){ stringOutput[0]=stringInput[0]; int j=1, i; for(i=1;;i++){ stringOutput[i]=stringInput[j]; j=j+2; if(j>=n-1) break; } stringOutput[i+1]=stringInput[n-1]; /*printf("%s\n",stringOutput);*/ for(int i2=0; i2<=i+1;i2++) printf("%c",stringOutput[i2]); printf("\n"); } else if(n==2) printf("%s\n",stringInput); } return 0; }
Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.Bob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.For example, if Bob came up with the string $$$a$$$="abac", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: "ab", "ba", "ac". Therefore, the string $$$b$$$="abbaac".You are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.
C
ac77e2e6c86b5528b401debe9f68fc8e
14b48bbcf978115659a6d4745738d5b3
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1592318100
["4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz"]
NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of string $$$a$$$ are: "bc", "cd", "da", "af", so the string $$$b$$$="bccddaaf".
PASSED
800
standard input
2 seconds
The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$) — the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.
["abac\nac\nbcdaf\nzzzzzz"]
/* * File: main.c * Description: Codeforce problemset 1267A - Short Substrings. * Created on: Aug 15 2020 22:11 +0700 * Author: tbtt */ #include <stdio.h> #include <stdlib.h> #include <inttypes.h> #include <string.h> #define MAX_LEN 100 int main (void) { #ifndef ONLINE_JUDGE freopen ("input.txt", "r", stdin); #endif uint16_t t; char b[MAX_LEN + 2]; uint8_t len; uint8_t i; scanf ("%" SCNu16 "\n", &t); while (t--) { if (fgets (b, sizeof (b), stdin)) { len = (uint8_t) strlen (b) - 1; printf ("%c", b[0]); for (i = 1; i < len; i += 2) { if (b[i] == b[i + 1]) { printf ("%c", b[i]); } } printf ("%c", b[len - 1]); } printf ("\n"); } return EXIT_SUCCESS; }
Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.Bob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.For example, if Bob came up with the string $$$a$$$="abac", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: "ab", "ba", "ac". Therefore, the string $$$b$$$="abbaac".You are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.
C
ac77e2e6c86b5528b401debe9f68fc8e
ec9bac0c409c6e02d20be83c77c0788c
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1592318100
["4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz"]
NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of string $$$a$$$ are: "bc", "cd", "da", "af", so the string $$$b$$$="bccddaaf".
PASSED
800
standard input
2 seconds
The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$) — the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.
["abac\nac\nbcdaf\nzzzzzz"]
#include<stdio.h> int main() { char S[101]; int t,count; scanf("%d",&t); for(int i=0;i<t;i++) { scanf("%s",S); for(int j=0;S[j]!='\0';j+=2) { if(S[j+1]=='\0') { printf("%c",S[j]); break; } else if(S[j+2]=='\0') { printf("%c%c",S[j],S[j+1]); break; } else { printf("%c",S[j]); } } printf("\n"); } return 0; }
Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.Bob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.For example, if Bob came up with the string $$$a$$$="abac", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: "ab", "ba", "ac". Therefore, the string $$$b$$$="abbaac".You are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.
C
ac77e2e6c86b5528b401debe9f68fc8e
3784f8b25fc50b9c7a78dfa274539901
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1592318100
["4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz"]
NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of string $$$a$$$ are: "bc", "cd", "da", "af", so the string $$$b$$$="bccddaaf".
PASSED
800
standard input
2 seconds
The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$) — the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.
["abac\nac\nbcdaf\nzzzzzz"]
#include<stdio.h> int main() { char S[101]; int t,count; scanf("%d",&t); for(int i=0;i<t;i++) { scanf("%s",S); for(int j=0;S[j]!='\0';j++) { if(S[j+1]=='\0') { printf("%c",S[j]); } else if((j%2)==0) { printf("%c",S[j]); } } printf("\n"); } return 0; }
Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.Bob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.For example, if Bob came up with the string $$$a$$$="abac", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: "ab", "ba", "ac". Therefore, the string $$$b$$$="abbaac".You are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.
C
ac77e2e6c86b5528b401debe9f68fc8e
afcee7d77f1b2c1268ad9f243e004f46
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1592318100
["4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz"]
NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of string $$$a$$$ are: "bc", "cd", "da", "af", so the string $$$b$$$="bccddaaf".
PASSED
800
standard input
2 seconds
The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$) — the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.
["abac\nac\nbcdaf\nzzzzzz"]
#include<stdio.h> int main() { char S[101],prev; int t,count; scanf("%d",&t); for(int i=0;i<t;i++) { scanf("%s",S); printf("%c",S[0]); prev = S[0]; count = 1; for(int j=1;S[j]!='\0';j++) { if(S[j+1]=='\0') { printf("%c\n",S[j]); break; } else if(prev==S[j]) { count++; if((count%2)==0) { printf("%c",S[j]); } } else { count = 1; prev = S[j]; } } } return 0; }
Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.Bob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.For example, if Bob came up with the string $$$a$$$="abac", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: "ab", "ba", "ac". Therefore, the string $$$b$$$="abbaac".You are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.
C
ac77e2e6c86b5528b401debe9f68fc8e
e07f8207a8f5b2a4e646a3ff60e94f81
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1592318100
["4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz"]
NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of string $$$a$$$ are: "bc", "cd", "da", "af", so the string $$$b$$$="bccddaaf".
PASSED
800
standard input
2 seconds
The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$) — the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.
["abac\nac\nbcdaf\nzzzzzz"]
#include<stdio.h> #include<string.h> int main() { int t,j;scanf("%d",&t); while(t>0) { int i,x,n,len; char str1[100]; scanf("%s",&str1); len=strlen(str1);char str2[100]; for(i=0; i<=(len-1)/2; i++) { str2[i]=str1[i*2];} str2[(len-1)/2+1]=str1[len-1]; str2[(len-1)/2+2]='\0'; printf("%s\n",str2); t--; } }
Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.Bob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.For example, if Bob came up with the string $$$a$$$="abac", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: "ab", "ba", "ac". Therefore, the string $$$b$$$="abbaac".You are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.
C
ac77e2e6c86b5528b401debe9f68fc8e
6c7937cbfb271bb353060fba7a454553
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1592318100
["4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz"]
NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of string $$$a$$$ are: "bc", "cd", "da", "af", so the string $$$b$$$="bccddaaf".
PASSED
800
standard input
2 seconds
The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$) — the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.
["abac\nac\nbcdaf\nzzzzzz"]
#include<stdio.h> #include<string.h> int main() { int t; scanf("%d",&t); while(t) { char str[100]; int i,n; scanf("%s",str); n=strlen(str); for(i=0;i<n-1;i++) { if(i%2==0) printf("%c",str[i]); } printf("%c\n",str[i]); t--; } }
Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.Bob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.For example, if Bob came up with the string $$$a$$$="abac", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: "ab", "ba", "ac". Therefore, the string $$$b$$$="abbaac".You are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.
C
ac77e2e6c86b5528b401debe9f68fc8e
c3442ace980bb1bc984dd71b557456da
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "strings" ]
1592318100
["4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz"]
NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of string $$$a$$$ are: "bc", "cd", "da", "af", so the string $$$b$$$="bccddaaf".
PASSED
800
standard input
2 seconds
The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$) — the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.
["abac\nac\nbcdaf\nzzzzzz"]
#include <stdio.h> #include <string.h> int main(void) { int n; char s[100]; scanf("%d", &n); while(n--) { scanf("%s", &s); for(int i = 0, a = strlen(s); i < a; i++) { if(i == 0 || i % 2 == 0 || i == a-1) printf("%c", s[i]); } printf("\n"); } return 0; }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
13510315afa589a9ba004a58e83f5a8d
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include <stdio.h> int main() { int a,i,s[200005],sum=0,sum1=0,count=0; scanf("%d",&a); for(i=0;i<a;i++) { scanf("%d",&s[i]); sum=sum+s[i]; } if(sum%2==1) { sum++; } for(i=0;i<a;i++) { sum1=sum1+s[i]; count++; if(sum1>=(sum/2)) { break; } } printf("%d",count); }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
0109ae21806be0b08a1409934e5dd6d3
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include <stdio.h> int main() { long long int num,i,j,sum=0,count=0,sum1=0,s[1000005]; scanf("%lld",&num); for(i=0;i<num;i++) { scanf("%lld",&s[i]); sum=sum+s[i]; } for(i=0;i<num;i++) { sum1=sum1+s[i]; count++; if(sum1>=(1.0)*(sum)/2) { break; } } printf("%lld",count); }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
adad1b6385b954f7214851eb72ad57f0
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include<stdio.h> int ara[10000000]; int main() { int i,a,sum1=0; double sum=0; scanf("%d",&a); for(i=0;i<a;i++){ scanf("%d",&ara[i]); sum+=ara[i]; } for(i=0;i<a;i++){ sum1+=ara[i]; if((sum/2)<=sum1){ printf("%d\n",i+1); return 0; } } return 0; }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
25bb1612ed142efee4a4089b59ecbc26
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include<stdio.h> int main () { int n,i,x=0,b=0; int count ; scanf("%d",&n); int a[n]; for(i=0; i<n; i++) { scanf("%d",&a[i]); b=b+a[i]; } for(i=0; i<n; i++) { x=x+a[i]; if(b%2==0) { if(x>=b/2) { count=i+1; break; } } if (b%2!=0) { if(x>=b/2+1) { count=i+1; break; } } } printf("%d",count); }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
844fded27743c6c8b67af1a1b767e0b5
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include<stdio.h> int main() { int n,a[200005]; int i,s=0,x=0; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&a[i]); s += a[i]; } if(s%2 != 0) { s = s/2 + 1; } else { s = s/2; } for(i=0;i<n;i++) { x += a[i]; if(x>=s) { printf("%d\n",i+1); return 0; } } }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
8599351e8516823e6be50239ada0f990
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include<stdio.h> int main() { int long i,n,a[200000]={0},sum=0,sum1=0; scanf("%ld",&n); for(i=1;i<=n;i++) { scanf("%ld",&a[i]); sum+=a[i]; } i=0; while(sum1<sum/2.0) { i++; sum1+=a[i]; } printf("%ld",i); return 0; }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
c0341a557253a4e0c0bbc080325c0c6f
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include<stdio.h> int main() { int i,t,arr[200000],count=0; double sum=0,sum2=0; scanf("%d",&t); for(i=0;i<t;i++) { scanf("%d",&arr[i]); sum+=arr[i]; } int total = ceil(sum/2); //printf("%d",total); for(i=0;i<t;i++) { sum2+=arr[i]; count++; if(sum2>=(total)) { printf("%d",count); return 0; } } return 0; }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
3faf5cb9f5937a1d475803addcbd6422
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include<stdio.h> #include<stdlib.h> int main() { long n,i; long long s1=0,s2=0; scanf("%ld",&n); int *a=malloc(n*sizeof(int)); for(i=0;i<n;i++){ scanf("%d",&a[i]); s1+=a[i];} for(i=0;i<n;i++) { s2+=a[i]; if(s2>=(s1+1)/2) { printf("%ld",i+1); return 0; } } }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
2f63a2bd9fe4d6720a7837d04ba8dd83
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include<stdio.h> int main() { int n, i, s = 0, c = 0; scanf("%d", &n); int a[2000001]; for (i = 0; i<n; i++) { scanf("%d", &a[i]); s = s + a[i]; } for (i = 0; i<n; i++) { if (c * 2 < s) { c = c + a[i]; } else { break; } } printf("%d\n", i); return 0; }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
a99d5307c04e45123e269fec8c959ea7
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include <stdio.h> int pro[200010]; int n; int sum = 0; int k = 0; int i; int day; int main() { scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &pro[i]); sum += pro[i]; } for (i = 0; i < n; i++) { k += pro[i]; if (2 * k >= sum) { day = i + 1; break; } } printf("%d", day); return 0; }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
7b6b5469f37748ff1a41e24d6f63f561
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include<stdio.h> int main() { int n,i,sum=0,p,num=0; scanf("%d",&n); int a[n]; for(i=0;i<n;i=i+1) { scanf("%d",&a[i]); sum=sum+a[i]; } if(sum%2==0) { p=sum/2; } else { p=(sum/2)+1; } for(i=0;i<n;i=i+1) { num=num+a[i]; if(num>=p) { printf("%d\n",i+1); break; } } }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
216c3731a306846518b22b967b38a7a6
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include<stdio.h> int main() { int n,i,j,r,c=0,sum=0; scanf("%d",&n); int ar[n]; for(i=0;i<n;i++) { scanf("%d",&ar[i]); sum+=ar[i]; } for(i=0;i<n;i++) { c+=ar[i]; if(c>=sum/2 +(sum%2)) { printf("%d",i+1); break; } } }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
893db2730d0f030f1c605076be1babd6
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include <stdio.h> #define N 200000 int main() { static int aa[N]; int n, i, sum1, sum2; scanf("%d", &n); sum1 = 0; for (i = 0; i < n; i++) { scanf("%d", &aa[i]); sum1 += aa[i]; } sum2 = 0; for (i = 0; i < n; i++) { sum2 += aa[i]; if (sum2 >= (sum1 + 1) / 2) break; } printf("%d\n", i + 1); return 0; }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
53e72695bd74579d1890568d4bbe5e9f
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include<stdio.h> int main() { int n,p[2000000],i,r,count=0; double sum=0, a=0; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&p[i]); a=a+p[i]; } a=a/2; for(i=0;i<n;i++) { if(sum<a) { sum=sum+p[i]; count++; }else break; } printf("%d",count); return 0; }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
3e71b7af1c794d9ce7e343d46da8cfa5
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include <stdio.h> int main() { int n,a[200000],b,c=0,i,j,sum=0; scanf("%d",&n); for(i=0;i<n;i++){ scanf("%d",&a[i]); sum+=a[i]; } for(i=0;i<n;i++){ c+=a[i]; if(c>=sum/2.00){ break; } } printf("%d",i+1); }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
7201c4d1da002113ca962b9f4f3a2c23
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include <stdio.h> int main(void) { int n,m[200000],i,j,k=0,l,a=0; scanf("%d",&n); if(n==1) { printf("1"); } else { for(i=0;i<n;i++) { scanf("%d",&m[i]); k=k+m[i]; } if((k%2)==0) { l=k/2; } else { l=(k/2)+1; } for(j=0;j<n;j++) { a=a+m[j]; if(a>=l) { printf("%d",j+1); break; } } } return 0; }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
d150756153f3f64b4e7aef8365e8fc65
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include <stdio.h> int main(void) { // your code goes here long n,sum=0,i,c=0; scanf("%ld", &n); long a[n]; for(i=0;i<n;i++) { scanf("%ld", &a[i]); sum+=a[i]; } for(i=0;i<n;i++) { c+=a[i]; if(c>=(sum+1)/2) break; } printf("%ld", i+1); return 0; }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
a3c633eed4b8c338a10ce0a49107e150
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include <stdio.h> int main(void){ int n; int lala[200002] = {0}; scanf("%d", &n); int counter = 0; for(int i = 0; i < n; i ++){ scanf("%d", &(lala[i])); counter += lala[i]; } int temp = 0; for(int i = 0; i < n; i ++){ temp += lala[i]; if(counter % 2 == 0){ if(temp >= (counter/2)){ printf("%d\n", i+1); break; } } else{ if(temp >= (counter/2 + 1)){ printf("%d\n", i+1); break; } } } return 0; }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
c7228e5362c70cc75478d838bcccde37
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include<stdio.h> int main() { long long int i,t,num=0; double sum=0; scanf("%lld",&t); long long int a[t]; for(i=0;i<t;i++) { scanf("%lld",&a[i]); sum=sum+a[i]; } sum=sum/2; for(i=0;i<t;i++) { num=num+a[i]; if(num>=sum) break; } printf("%d",i+1); }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
fffc0a2f388599d4f05a247f48c1a0b9
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include <stdio.h> int main() { int n; scanf("%d",&n); int a[n]; for(int i=0;i<n;i++){ scanf("%d",&a[i]); } int sum1=a[0],sum2=a[n-1],i=0,j=n-1; while(i!=j){ if(sum1 >= sum2){ j--; sum2 += a[j]; } else{ i++; sum1 += a[i]; } } printf("%d",i+1); return 0; }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
4c6d90cb6e9e2ebed8a22c16ced16d30
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include <stdio.h> #include <memory.h> #define DATA_SIZE 200005 int data[DATA_SIZE]; int main() { int n, sum = 0; memset(data, 0, sizeof(data)); scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", data + i); sum += data[i]; } int half = sum % 2 ? (sum >> 1) + 1 : (sum >> 1); sum = 0; for (int i = 0; i < n; i++) { sum += data[i]; if (sum >= half) { printf("%d", i + 1); break; } } return 0; }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
1f4904d54032f91ef4f60a0cf8604bea
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include<stdio.h> int main() { int n; scanf("%d",&n); int a[n], i, sum=0, sum1=0; for(i=0;i<n;i++) { scanf("%d",&a[i]); sum+=a[i]; } for(i=0;i<n;i++) { sum1+=a[i]; if(sum1>=(0.5*sum)) break; } printf("%d",i+1); }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
0b2d02431d53125c47f6b24deeee84c7
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include<stdio.h> int main() { long long n; scanf("%lld",&n); long long ar[n],sum=0,temp=0,p=0; for(long long i=0;i<n;i++) { scanf("%lld",&ar[i]); sum+=ar[i]; } if(sum%2!=0) sum+=1; for(long long i=0;i<n;i++) { temp+=ar[i]; if(temp>=sum/2) { p=i; break; } } long long y=p+1; printf("%lld",y); return 0; }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
354bc68dac739281a222f632332a9a73
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include <stdio.h> int main(){ long n; scanf("%ld",&n); double probsolvedfromday1[n]; for(int i=0;i<n;i++){ double solved; scanf("%lf",&solved); if(i>0){ probsolvedfromday1[i]=probsolvedfromday1[i-1]+solved; } else{ probsolvedfromday1[i]=solved; } } double totalsolved=probsolvedfromday1[n-1]; int idx=0; while(probsolvedfromday1[idx]<totalsolved/2){ idx++; } printf("%d\n",idx+1); }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
e3bb19be53c42ad5e67d642d5c1ae9d0
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include <stdio.h> int main() { long long int num,i,j,sum=0,count=0,sum1=0,s[1000005]; scanf("%lld",&num); for(i=0;i<num;i++) { scanf("%lld",&s[i]); sum=sum+s[i]; } for(i=0;i<num;i++) { sum1=sum1+s[i]; count++; if(sum1>=(1.0)*(sum)/2) { break; } } printf("%lld",count); }
Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.Determine the index of day when Polycarp will celebrate the equator.
Print the index of the day when Polycarp will celebrate the equator.
C
241157c465fe5dd96acd514010904321
d0a940dd3c302da239501508fa73732b
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation" ]
1523370900
["4\n1 3 2 1", "6\n2 2 2 2 2 2"]
NoteIn the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $$$6$$$ out of $$$12$$$ scheduled problems on six days of the training.
PASSED
1,300
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$$i$$$-th day.
["2", "3"]
#include<stdio.h> #include<stdlib.h> void fun(int [],int ); void fun(int a[],int n) { int i,sum=0,ans=0; for(i=0;i<n;i++) { sum=sum+a[i]; } for(i=0;i<n;i++) { ans=ans+a[i]; if(sum%2==0) { if(ans>=sum/2) { printf("%d\n",i+1); return; } } else { if(ans>=sum/2+1) { printf("%d\n",i+1); return; } } } } int main() { int a[200001]; int n,i; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&a[i]); } fun(a,n); return 0; }