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
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
C
f5451b19cf835b1cb154253fbe4ea6df
c27b97ebd768c3118167c5232fd96c85
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1346081400
["2\naazz", "3\nabcabcabz"]
null
PASSED
1,000
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≀ |s| ≀ 1000, where |s| is the length of string s.
["azaz", "-1"]
#include<stdio.h> #include<string.h> int a[26]; int main() { int k; scanf("%d",&k); char s[1001]; scanf("%s",s); int i=0,j=0; int n=strlen(s); for(i=0;i<n;i++) a[s[i]-'a']++; // printf("%d\n\n",a[25]); for(i=0;i<26;i++) { if(a[i]%k!=0) { printf("-1\n"); return 0; } } int l=0; for(l=0;l<k;l++) { for(i=0;i<26;i++) { for(j=0;j<a[i]/k;j++) { printf("%c",i+97); } } } printf("\n"); return 0; }
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
C
f5451b19cf835b1cb154253fbe4ea6df
f60eca9d91df7734cd6bb9ebbbfa7dd5
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1346081400
["2\naazz", "3\nabcabcabz"]
null
PASSED
1,000
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≀ |s| ≀ 1000, where |s| is the length of string s.
["azaz", "-1"]
#include<string.h> #include<stdio.h> main() { int k,x,a[27]={0},g,t,y,j=0; char s[1001],b[1001]; scanf("%d%s",&k,s); g=strlen(s); if(g%k==0) { t=g/k; for(x=0;x<g;x++) a[s[x]-96]++; for(x=1;x<=26;x++) { if(a[x]%k==0) { for(y=1;y<=a[x]/k;y++) b[j++]=(char)(96+x); } else goto v; } b[j]='\0'; if(strlen(b)==t) { for(x=1;x<=k;x++) printf("%s",b); return(0); }} v: printf("-1"); return(0); }
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
C
f5451b19cf835b1cb154253fbe4ea6df
0f52033db2e3ce1e69dc9d45055b9e1b
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1346081400
["2\naazz", "3\nabcabcabz"]
null
PASSED
1,000
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≀ |s| ≀ 1000, where |s| is the length of string s.
["azaz", "-1"]
#include <stdio.h> #include <stdlib.h> int main() { char s[1001]; int n; scanf("%d ",&n); gets(s); int arr[26]={0}; int i; for(i=0;i<strlen(s);i++){ int y=s[i]; arr[y-97]++; } int j; int numL; for(i=0;i<26;i++){ if(!(arr[i]%n==0||arr[i]==0)){ printf("-1"); return 0; } if(arr[i]!=0){ numL=arr[i]; } } int k; for(j=0;j<n;j++){ for(i=0;i<26;i++){ if(arr[i]>0){ for(k=0;k<arr[i]/n;k++){ int x=i+97; printf("%c",x); } } } } return 0; }
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
C
f5451b19cf835b1cb154253fbe4ea6df
326c1f5506569b6447e8ad49292021c2
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1346081400
["2\naazz", "3\nabcabcabz"]
null
PASSED
1,000
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≀ |s| ≀ 1000, where |s| is the length of string s.
["azaz", "-1"]
#include<stdio.h> #include<string.h> int main() {int i,j,k,n,m,t,b[26]={0};char a[1005]={'\0'},c[1005]={'\0'},d[1005]={'\0'}; scanf("%d",&n); scanf("%s",a); t=strlen(a); for(i=0;i<t;i++) {k=a[i];m=k-97; b[m]++; }j=0; for(i=0;i<26;i++) { if(b[i]<n&&b[i]!=0) {printf("-1");goto flag;} else {if(b[i]!=0) {while(b[i]>0) {c[j++]=i+97; b[i]-=n;}} if(b[i]-n<0&&b[i]!=0) {printf("-1");goto flag;}}} for(i=1;i<=n;i++) strcat(d,c); printf("%s",d); flag: return 0; }
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
C
f5451b19cf835b1cb154253fbe4ea6df
7641fbba163589fd8eac54b8042d7b24
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1346081400
["2\naazz", "3\nabcabcabz"]
null
PASSED
1,000
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≀ |s| ≀ 1000, where |s| is the length of string s.
["azaz", "-1"]
int main() { char s[1010]; int freq[26]={0}; int k; int i,j,l; scanf("%d", &k); scanf(" %s", s); for( i = 0; s[i] != '\0'; i++) freq[s[i]-'a']++; for( i = 0; i < 26; i++) if(freq[i]%k != 0) { printf("-1\n"); return 0; } for( i = 1; i <= k; i++) { for( j = 0; j < 26; j++) for( l = 1; l <= freq[j]/k; l++) printf("%c", 'a' + j); } return 0; }
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
C
f5451b19cf835b1cb154253fbe4ea6df
224fb17a4bdc0e9d9e2047e663a49817
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1346081400
["2\naazz", "3\nabcabcabz"]
null
PASSED
1,000
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≀ |s| ≀ 1000, where |s| is the length of string s.
["azaz", "-1"]
#include <stdio.h> int main() { int k, i, let[26] = { 0 }; char s[1001]; scanf ("%d %s", &k, s); for (i = 0; s[i]; i++) let[s[i] - 'a']++; for (i = 0; i < 26 && let[i] % k == 0; i++) let[i] /= k; if (i < 26) printf ("-1"); else { while (k--) { for (i = 0; i < 26; i++) if (let[i] > 0) { int j; for (j = 0; j < let[i]; j++) putchar (i + 'a'); } } } return 0; }
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
C
f5451b19cf835b1cb154253fbe4ea6df
7e1c4ca687880a28e8f7888a856593d4
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1346081400
["2\naazz", "3\nabcabcabz"]
null
PASSED
1,000
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≀ |s| ≀ 1000, where |s| is the length of string s.
["azaz", "-1"]
#include<stdio.h> #include<string.h> int main() { char s[1001],a[1001]; int coun[1001]; int i,j,k,x,y,count,n=0,c=0,m=0,co; scanf("%d",&k); scanf("%s",&s); x=strlen(s); for(i=0;i<x;i++) { c=0; count=0; for(y=0;y<n;y++) { if(s[i]!=a[y]) c++; } if(c==n) { for(j=0;j<x;j++) { if(s[i]==s[j]) count++; } if(count%k!=0) { printf("-1"); return 0; } if(count%k==0) { a[n++]=s[i]; coun[m++]=count; } } } c=k; while(k--) { for(i=0;i<n;i++) { co=coun[i]/c; while(co--) printf("%c",a[i]); } } return 0; }
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
C
f5451b19cf835b1cb154253fbe4ea6df
4f61feeac3f380488080382a109e55c6
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1346081400
["2\naazz", "3\nabcabcabz"]
null
PASSED
1,000
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≀ |s| ≀ 1000, where |s| is the length of string s.
["azaz", "-1"]
#include<string.h> #include<stdio.h> int main () { int x,i,h[1006],f=1,j,diz=0; char d[1006],cvp[1006]; scanf("%d %s",&x,d); for(i=0;i<strlen(d);i++) h[d[i]-'a']++; for(i=0;i<26;i++){ if(h[i]){ if(!(h[i]%x)){ for(j=0;j<h[i]/x;j++){ cvp[diz]=i+'a'; diz++;}} else{ printf("-1"); return 0;}}} for(i=0;i<x;i++) for(j=0;j<diz;j++) printf("%c",cvp[j]); return 0; }
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
C
f5451b19cf835b1cb154253fbe4ea6df
73a26e55419c5fbf990df9dddf192773
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1346081400
["2\naazz", "3\nabcabcabz"]
null
PASSED
1,000
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≀ |s| ≀ 1000, where |s| is the length of string s.
["azaz", "-1"]
main () { int x,i,h[1006],f=1,j,diz=0; char d[1006],cvp[1006]; scanf("%d %s",&x,d); for(i=0;i<strlen(d);i++) h[d[i]-'a']++; for(i=0;i<26;i++){ if(h[i]){ if(!(h[i]%x)){ for(j=0;j<h[i]/x;j++){ cvp[diz]=i+'a'; diz++;}} else{ printf("-1"); return 0;}}} for(i=0;i<x;i++) for(j=0;j<diz;j++) printf("%c",cvp[j]); }
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
C
f5451b19cf835b1cb154253fbe4ea6df
d728dd4bc2b14d3e854fbbe878da7945
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1346081400
["2\naazz", "3\nabcabcabz"]
null
PASSED
1,000
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≀ |s| ≀ 1000, where |s| is the length of string s.
["azaz", "-1"]
#include <stdio.h> int A[150], B[150]; int main() { char i; int k; char str[1001]; scanf("%d", &k); getchar(); gets(str); for (i = 0; i < strlen(str); i++) A[str[i]]++; for (i = 'a'; i <= 'z'; i++) if (A[i] % k) { printf("-1"); return 0; } else B[i] = A[i] / k; while (1) { int check = 1; for (i = 'a'; i <= 'z'; i++) if (A[i]) { check = 0; A[i] -= B[i]; int cou = B[i]; while (cou--) printf("%c", i); } if (check) break; } return 0; }
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
C
f5451b19cf835b1cb154253fbe4ea6df
d89a12161d3bbe1ab65fae7aa5cf36a7
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1346081400
["2\naazz", "3\nabcabcabz"]
null
PASSED
1,000
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≀ |s| ≀ 1000, where |s| is the length of string s.
["azaz", "-1"]
#include <stdio.h> char s[1010]; int n, a[26],i,j,k; int main ( ) { scanf ( "%d%s", &n, s ); for ( i = 0; s[i]; ++i ) ++a[s[i] - 'a']; for ( i = 0; i < 26; ++i ) { if ( a[i] % n ) { printf ( "-1\n" ); return 0; } } for ( i = 1; i <= n; ++i ) for ( k = 0; k < 26; ++k ) for ( j = 1; j <= a[k] / n; ++j ) printf ( "%c", 'a' + k ); printf ( "\n" ); return 0; }
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
C
f5451b19cf835b1cb154253fbe4ea6df
21f7fb08cf918d0c096178a586231210
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1346081400
["2\naazz", "3\nabcabcabz"]
null
PASSED
1,000
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≀ |s| ≀ 1000, where |s| is the length of string s.
["azaz", "-1"]
#include<string.h> #include<stdio.h> int main() { int k,x,a[27]={0},g,t,y,j=0; char s[1001],b[1001]; scanf("%d%s",&k,s); g=strlen(s); if(g%k==0) { t=g/k; for(x=0;x<g;x++) a[s[x]-96]++; for(x=1;x<=26;x++) { if(a[x]%k==0) { for(y=1;y<=a[x]/k;y++) b[j++]=(char)(96+x); } else goto v; } b[j]='\0'; if(strlen(b)==t) { for(x=1;x<=k;x++) printf("%s",b); return(0); }} v: printf("-1"); return(0); }
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
C
f5451b19cf835b1cb154253fbe4ea6df
c9dcc2072ce90827152a605ae4ae5db8
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1346081400
["2\naazz", "3\nabcabcabz"]
null
PASSED
1,000
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≀ |s| ≀ 1000, where |s| is the length of string s.
["azaz", "-1"]
#include<stdio.h> int main() { int i,j,k,a[26]={0},l,flag=0,cnt=0; char s[1011],b[100]; scanf("%d",&k); scanf("%s",s); for(i=0;s[i]!='\0';i++) { a[s[i]-97]++; } for(i=0;i<26;i++) { if(a[i]>0) { if(a[i]%k==0) { l=a[i]/k; for(j=0;j<l;j++){ b[cnt]=i+97; cnt++;} } else { flag=1; } } } b[cnt]='\0'; if(flag) { printf("-1\n"); } else { for(i=0;i<k;i++) { printf("%s",b); } } return 0; }
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
C
f5451b19cf835b1cb154253fbe4ea6df
0d20112a2032cb4dd0d41203d2566bae
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1346081400
["2\naazz", "3\nabcabcabz"]
null
PASSED
1,000
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≀ |s| ≀ 1000, where |s| is the length of string s.
["azaz", "-1"]
#include <stdio.h> int s[26]; int main() { //printf("%d", 'z'-('a'-1));//26 int k; scanf("%d\n", &k); char c; int len=0; while((c = getchar()) != EOF && c != '\n') { //printf("'%c'\n", c); s[c-'a']++; ++len; } int i; for(i=0; i<26; i++) if(!(s[i] == 0 || s[i] % k == 0)) { puts("-1"); return 0; } int j, m; for(i=0; i<k; i++) for(j=0; j<26; j++) if(s[j] != 0) for(m=0; m<s[j]/k; m++) printf("%c", j+'a'); return 0; }
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
C
f5451b19cf835b1cb154253fbe4ea6df
f3c75b699346bafa1585f7a6ece694eb
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1346081400
["2\naazz", "3\nabcabcabz"]
null
PASSED
1,000
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≀ |s| ≀ 1000, where |s| is the length of string s.
["azaz", "-1"]
#include<stdio.h> #include<math.h> #include<ctype.h> #include<string.h> #define getchar getchar//_unlocked #define M 1000000007 int getint () { int n=0; char ch=getchar(); while(ch<'0' || ch>'9') ch=getchar(); while(ch>='0' && ch<='9') { n=n*10+ch-'0'; ch=getchar(); } return n; } unsigned long long gcd(unsigned long long a, unsigned long long b) { unsigned long long div=a,did=b,rem; while((rem=did%div)!=0) { did=div; div=rem; } return div; } long long getlonglong () { long long n=0; char ch=getchar(); while(ch<'0' || ch>'9') ch=getchar(); while(ch>='0' && ch<='9') { n=n*10+ch-'0'; ch=getchar(); } return n; } void sort(int a[] ,int start1 ,int end1 ,int start2 ,int end2) { int temp[end1-start1 +1 + end2-start2+1 ]; int i=start1,j=start2,count=0; while(i<=end1 && j<=end2) { if(a[i]<=a[j]) temp[count++]=a[i++]; else temp[count++]=a[j++]; } for(;i<=end1;++i) temp[count++]=a[i]; for(;j<=end2;++j) temp[count++]=a[j]; for(i=0;i<count;++i) a[i+start1]=temp[i]; } void mergesort(int a[] ,int start,int end) { if(start==end) return; int middle =(start+end)/2; mergesort(a,start,middle); mergesort(a,middle+1,end); sort(a,start,middle,middle+1,end); } long long Ceil(long long a , long long n) { if(a<0) return 0; if(a%n==0) return a/n; else return a/n +1 ; } long long Max(long long a ,long long b) { if(a>b) return a; else return b; } long long Abs(long long a) { if(a<0) return -a; else return a; } void sorttt(int n, int a[n][2]) { int i,j,smallest,temp1,temp2; for(i=0;i<n;++i) { smallest =i; for(j=i+1;j<n;++j) { if(a[smallest][0] > a[j][0]) smallest=j; if(a[smallest][0]==a[j][0] && a[smallest][1]<a[j][1]) smallest=j; } temp1=a[i][0]; temp2=a[i][1]; a[i][0]= a[smallest][0]; a[i][1] = a[smallest][1]; a[smallest][0] =temp1; a[smallest][1]=temp2; } } int main() { int i,j,k1,k=getint(),l=0,a[26]={0},f[26]={0}; char ch; while(isalpha(ch=getchar())) { a[ch-'a']++; ++l; } if(l%k!=0) { printf("-1"); return 0; } for(i=0;i<26;++i) { if(a[i]%k==0) f[i]=a[i]/k; else { printf("-1"); return 0; } } for(i=0;i<k;++i) for(j=0;j<26;++j) for(k1=1;k1<=f[j];++k1) printf("%c",'a'+j); return 0; }
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
C
f5451b19cf835b1cb154253fbe4ea6df
e60079a210db373f21d1cdeef0bf716e
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1346081400
["2\naazz", "3\nabcabcabz"]
null
PASSED
1,000
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≀ |s| ≀ 1000, where |s| is the length of string s.
["azaz", "-1"]
int main() { int a[256]={0},k,n,l=0,ll; char ans[1000]={""}; scanf("%i",&n); getchar(); while((k=getchar())!='\n')a[k]++; for(k='a';k<='z';k++){ if(a[k]%n){puts("-1");return 0;} ll=a[k]/n; while(ll--)ans[l++]=k; } while(n--)printf("%s",ans); }
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
C
f5451b19cf835b1cb154253fbe4ea6df
e3a0b9701647937592db6ef5cb129ab5
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1346081400
["2\naazz", "3\nabcabcabz"]
null
PASSED
1,000
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≀ |s| ≀ 1000, where |s| is the length of string s.
["azaz", "-1"]
#include<stdio.h> #include<string.h> int main() { int n; scanf("%d",&n); char s[1005]; scanf("%s",s); int a[150]={0},i=0; char *p=s; while(*p) { a[*p]++; p++; } int c=0,flag=0; char b[1005]; int k=0; for(i=97;i<=122;i++) { if(a[i]) { if(a[i]%n ==0) { int l=a[i]/n; while(l--) { b[k++]=(char)i; } }else{ flag=1; break; } } } char d[1001]=""; b[k]='\0'; while(n--) { strcat(d,b); } if(flag)printf("-1\n"); else printf("%s\n",d); return 0; }
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
C
f5451b19cf835b1cb154253fbe4ea6df
1d13ef594bcc61e4b984250dad0b50a1
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1346081400
["2\naazz", "3\nabcabcabz"]
null
PASSED
1,000
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≀ |s| ≀ 1000, where |s| is the length of string s.
["azaz", "-1"]
#include <stdio.h> #include <math.h> #include <string.h> #include <stdbool.h> #define MAXLEN 101000 int main() { char buf[MAXLEN]; int k; int i,j; int counts[30]; int bufIndex; while( scanf("%d",&k) != EOF ) { getchar(); gets(buf); memset(counts,0,sizeof(counts)); int len = strlen(buf); for( i = 0; i < len; i++ ) counts[buf[i] - 'a']++; bufIndex = 0; for( i = 0; i < 26; i++ ) if( counts[i] ) if( counts[i] % k == 0 ) { int limit = counts[i] / k; for( j = 0; j < limit; j++ ) buf[bufIndex++] = i + 'a'; } else if( counts[i] % k != 0 ) { printf("-1"); break; } if( i >= 26 ) for( j = 0; j < k; j++ ) for( i = 0; i < bufIndex; i++ ) printf("%c",buf[i]); printf("\n"); } return 0; }
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
C
f5451b19cf835b1cb154253fbe4ea6df
1b4cf632e50d9c419125b9ed6bc428d8
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1346081400
["2\naazz", "3\nabcabcabz"]
null
PASSED
1,000
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≀ |s| ≀ 1000, where |s| is the length of string s.
["azaz", "-1"]
#include <stdio.h> #include <string.h> int main() { int a, b, c, d; int ZB[26]; char ZA[1001], ZC[1001]; scanf("%d%s", &a, ZA); if (a == 1) { printf("%s\n", ZA); } else if (strlen(ZA) % a == 0) { for (b = 0; b < 26; ZB[b++] = 0); for (b = 0; ZA[b]; ++b) ZB[ZA[b] - 'a'] += 1; c = 0; for (b = 0; b < 26; ++b) if (ZB[b] != 0) c += 1; if (c <= strlen(ZA) / a) { for (b = 0; b < 26; ++b) if (ZB[b] != 0 && ZB[b] / a * a != ZB[b]) break; if (b != 26) { printf("-1\n"); } else { d = 0; for (b = 0; b < 26; ++b) if (ZB[b] != 0) for (c = 0; c < ZB[b] / a; ++c) ZC[d++] = 'a' + b; ZC[d] = 0; for (b = 0; b < a; ++b) printf("%s", ZC); printf("\n"); } } else { printf("-1\n"); } } else { printf("-1\n"); } return 0; }
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
C
f5451b19cf835b1cb154253fbe4ea6df
76454e9d154ae09c8c5b584b54ae3e3d
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1346081400
["2\naazz", "3\nabcabcabz"]
null
PASSED
1,000
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≀ |s| ≀ 1000, where |s| is the length of string s.
["azaz", "-1"]
#include<stdio.h> int main() { int i,n,j,k,x; char a[10000]; int f[26]; for(i=0;i<26;i++) f[i]=0; scanf("%d %s",&n,a); for(i=0;a[i]!=0;i++) f[a[i]-'a']++; for(i=0;i<26;i++) { if(f[i]==0 || f[i]%n == 0) continue; break; } if(i<26) printf("-1\n"); else { for(i=0;i<26;i++) { if(f[i]) break; } for(x=0;x<n;x++) for(j=0;j<26;j++) for(i=0;i<f[j]/n;i++) printf("%c",'a'+j); printf("\n"); } return 0; }
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
C
f5451b19cf835b1cb154253fbe4ea6df
09e2fa203f8c5f0bb403803417a4ed33
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1346081400
["2\naazz", "3\nabcabcabz"]
null
PASSED
1,000
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≀ |s| ≀ 1000, where |s| is the length of string s.
["azaz", "-1"]
#include<stdio.h> int main() { int m=1,k,n,p=0,i=0,c,l[26]={0},j; char s[1000]; scanf("%d\n",&n); while((c=getchar())!='\n') {s[i++]=c; ++l[c-'a']; } for(j=0;j<i;j++) { k=s[j]-'a'; if(l[k]<n&&n!=1||(l[k]%n)) {m=0;break;}} if(m) {for(i=0;i<n;i++) {for(c=0;c<26;c++) if(l[c]) for(j=0;j<l[c]/n;j++) printf("%c",c+'a'); } } else printf("-1"); return 0; }
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
C
f5451b19cf835b1cb154253fbe4ea6df
2616181d7f14853865efb69eaf6e2dac
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1346081400
["2\naazz", "3\nabcabcabz"]
null
PASSED
1,000
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≀ |s| ≀ 1000, where |s| is the length of string s.
["azaz", "-1"]
#include<stdio.h> int main() { int k,i,j; scanf("%d",&k); char s[1003],s1[1003]; scanf("%s",s); int a[26]; for(i=0;i<26;i++) a[i]=0; int l=strlen(s);int f=0,m; for(i=0;i<l;i++) { a[s[i]-97]++; } for(i=0;i<26;i++) { if(a[i]%k!=0) { f=1;break; } } if(f==1) printf("-1\n"); else { int b[26];int p,k1=0; for(i=0;i<26;i++) b[i]=a[i]/k; int max=1; while(max!=0) { max=0; for(i=0;i<26;i++) { for(p=0;p<b[i];p++) { s1[k1]=i+97; k1++;a[i]--; } } for(i=0;i<26;i++) { if(a[i]>max) max=a[i]; } } s1[k1]='\0'; printf("%s\n",s1); } return 0; }
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
C
f5451b19cf835b1cb154253fbe4ea6df
1cc798c3f95c42c62afdfeac001f569d
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1346081400
["2\naazz", "3\nabcabcabz"]
null
PASSED
1,000
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≀ |s| ≀ 1000, where |s| is the length of string s.
["azaz", "-1"]
#include<stdio.h> #include<string.h> int main(){ int x,i,j,k; scanf("%d",&x); char s[1001]; scanf("%s",s); int arr[26]; for(i=0;i<26;i++){ arr[i]=0; } for(i=0;i<strlen(s);i++){ arr[s[i]-97]++; } for(i=0;i<26;i++){ if(arr[i]%x==0){ continue; } else{ printf("-1"); return 0; } } for(i=0;i<x;i++){ for(j=0;j<26;j++){ for(k=0;k<(arr[j]/x);k++){ printf("%c",j+97); } } } return 0; }
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
C
f5451b19cf835b1cb154253fbe4ea6df
2b6fe8fe513466a02ff807117430cd99
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1346081400
["2\naazz", "3\nabcabcabz"]
null
PASSED
1,000
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≀ |s| ≀ 1000, where |s| is the length of string s.
["azaz", "-1"]
#include <stdio.h> #include <string.h> int main() { int k,count[26]={0}; scanf("%d",&k); char a[1000]; scanf("%s",a); int l=strlen(a); char nava[l/k]; int ind=0,i,j; for(i=0;a[i]!='\0';i++) count[a[i]-'a']++; for(i=0;i<26;i++) { if(count[i]%k!=0) { printf("-1"); return 0; } else { for(j=1;j<=count[i]/k;j++) { nava[ind]=i+'a'; ind++; } } } while(k>0) { for(j=0;j<ind;j++) printf("%c",nava[j]); k--; } return 0; }
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
C
f5451b19cf835b1cb154253fbe4ea6df
0c71665168f01d1fa7ff2b42cf32aa49
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1346081400
["2\naazz", "3\nabcabcabz"]
null
PASSED
1,000
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≀ |s| ≀ 1000, where |s| is the length of string s.
["azaz", "-1"]
#include<stdio.h> #include<string.h> main() { int n,i,j,k,m,b,a; int x[26]; scanf("%d",&n); char y[1000]; scanf("%s",&y); for(i=0;i<26;i++) { x[i]=0; } for(i=0;i<strlen(y);i++) { j=y[i]-'a'; x[j]++; } for(i=0;i<26;i++) { if(x[i]%n!=0) { printf("-1"); return 0; } } b=strlen(y)/n; for(k=1;k<=n;k++) { for(i=0;i<26;i++) { a=x[i]/n; if(x[i]>0) { for(j=0;j<a;j++) { printf("%c",i+'a'); } } } } }
A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).
C
f5451b19cf835b1cb154253fbe4ea6df
b4d1204e138a910bce8360ba6e01062f
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1346081400
["2\naazz", "3\nabcabcabz"]
null
PASSED
1,000
standard input
2 seconds
The first input line contains integer k (1 ≀ k ≀ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≀ |s| ≀ 1000, where |s| is the length of string s.
["azaz", "-1"]
#include<stdio.h> #include<string.h> int arr[26],c; char ans[1000007]; int main () { int n,i,j; char s[1000007]; scanf("%d",&n); getchar(); gets(s); int len=strlen(s); for(i=0; i<len; i++) arr[s[i]-'a']++; for(i=0; i<26; i++) { if(arr[i]%n!=0) { printf("-1\n"); return 0; } if(arr[i]>0) { for(j=0; j<arr[i]/n; j++) ans[c++]=i+'a'; } } for(i=0; i<n; i++) printf("%s",ans); printf("\n"); return 0; }
You are given three integers $$$n$$$, $$$d$$$ and $$$k$$$.Your task is to construct an undirected tree on $$$n$$$ vertices with diameter $$$d$$$ and degree of each vertex at most $$$k$$$, or say that it is impossible.An undirected tree is a connected undirected graph with $$$n - 1$$$ edges.Diameter of a tree is the maximum length of a simple path (a path in which each vertex appears at most once) between all pairs of vertices of this tree.Degree of a vertex is the number of edges incident to this vertex (i.e. for a vertex $$$u$$$ it is the number of edges $$$(u, v)$$$ that belong to the tree, where $$$v$$$ is any other vertex of a tree).
If there is no tree satisfying the conditions above, print only one word "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), and then print $$$n - 1$$$ lines describing edges of a tree satisfying the conditions above. Vertices of the tree must be numbered from $$$1$$$ to $$$n$$$. You can print edges and vertices connected by an edge in any order. If there are multiple answers, print any of them.1
C
a4849505bca48b408a5e8fb5aebf5cb6
610f6533fac7102493c4452e11bf09fd
GNU C
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "graphs" ]
1530628500
["6 3 3", "6 2 3", "10 4 3", "8 5 3"]
null
PASSED
2,100
standard input
4 seconds
The first line of the input contains three integers $$$n$$$, $$$d$$$ and $$$k$$$ ($$$1 \le n, d, k \le 4 \cdot 10^5$$$).
["YES\n3 1\n4 1\n1 2\n5 2\n2 6", "NO", "YES\n2 9\n2 10\n10 3\n3 1\n6 10\n8 2\n4 3\n5 6\n6 7", "YES\n2 5\n7 2\n3 7\n3 1\n1 6\n8 7\n4 3"]
#include<stdio.h> #include<stdlib.h> #define MAXVERS 500000 typedef struct Edge{ int adjver; int isVisited; struct Edge *next; }Edge; typedef struct Vertex{ int degree; int dist; // the distence between the vertex and the nearest end of diameter. struct Edge *edgelist; }Vertex; Vertex vertex[MAXVERS]; int nVers; int nowVer; int diameter; int maxDegree; void addEdge(int ver,int adjver) { Edge *edge; edge = (Edge*)malloc(sizeof(Edge)); edge->adjver = adjver; edge->isVisited = 0; edge->next = vertex[ver].edgelist; vertex[ver].edgelist = edge; } int getDiameter(void) { for(nowVer=1; nowVer<diameter; nowVer++){ if(vertex[nowVer].degree < maxDegree && vertex[nowVer+1].degree < maxDegree){ addEdge(nowVer,nowVer+1); //addEdge(nowVer+1,nowVer); vertex[nowVer].degree++; vertex[nowVer+1].degree++; vertex[nowVer].dist = (nowVer-1 < diameter-nowVer) ? (nowVer-1):(diameter-nowVer); }else{ return 0; } } vertex[diameter].dist = 0; return 1; } int begin=2; int findVer(void) { int v; for(v = begin; v <= nowVer; v++){ if(vertex[v].dist > 0 && vertex[v].degree < maxDegree){ return v; } } return 0; } int getTree(void) { int v; while(nowVer < nVers){ v = findVer(); //find the vertex that could extend. if(v == 0){ return 0; } //printf("nowVer=%d,v=%d\n",nowVer,v); nowVer++; vertex[v].degree++; vertex[nowVer].degree++; vertex[nowVer].dist = vertex[v].dist-1; if(vertex[v].degree == maxDegree){ begin = v+1; } addEdge(v,nowVer); //addEdge(nowVer,v); } return 1; } int visit(int ver,int adjver) { Edge *edge; edge = vertex[ver].edgelist; while(edge!=NULL){ if(edge->adjver == adjver && !edge->isVisited){ return 0; } edge = edge->next; } return 1; } void print(void) { printf("YES\n"); int v; Edge *edge; for(v=1; v<=nVers; v++){ edge = vertex[v].edgelist; while(edge!=NULL){ //if(!edge->isVisited && !visit(edge->adjver,v)){ printf("%d %d\n",v,edge->adjver); // edge->isVisited = 1; //} edge = edge->next; } } } int main(void) { scanf("%d%d%d",&nVers,&diameter,&maxDegree); diameter++; if(nVers < diameter){ printf("NO"); return 0; } if(!getDiameter()){ printf("NO"); return 0; } if(!getTree()){ printf("NO"); return 0; } print(); return 0; }
You are given three integers $$$n$$$, $$$d$$$ and $$$k$$$.Your task is to construct an undirected tree on $$$n$$$ vertices with diameter $$$d$$$ and degree of each vertex at most $$$k$$$, or say that it is impossible.An undirected tree is a connected undirected graph with $$$n - 1$$$ edges.Diameter of a tree is the maximum length of a simple path (a path in which each vertex appears at most once) between all pairs of vertices of this tree.Degree of a vertex is the number of edges incident to this vertex (i.e. for a vertex $$$u$$$ it is the number of edges $$$(u, v)$$$ that belong to the tree, where $$$v$$$ is any other vertex of a tree).
If there is no tree satisfying the conditions above, print only one word "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), and then print $$$n - 1$$$ lines describing edges of a tree satisfying the conditions above. Vertices of the tree must be numbered from $$$1$$$ to $$$n$$$. You can print edges and vertices connected by an edge in any order. If there are multiple answers, print any of them.1
C
a4849505bca48b408a5e8fb5aebf5cb6
0e015114ea212b236e14d94886dbfc92
GNU C
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "graphs" ]
1530628500
["6 3 3", "6 2 3", "10 4 3", "8 5 3"]
null
PASSED
2,100
standard input
4 seconds
The first line of the input contains three integers $$$n$$$, $$$d$$$ and $$$k$$$ ($$$1 \le n, d, k \le 4 \cdot 10^5$$$).
["YES\n3 1\n4 1\n1 2\n5 2\n2 6", "NO", "YES\n2 9\n2 10\n10 3\n3 1\n6 10\n8 2\n4 3\n5 6\n6 7", "YES\n2 5\n7 2\n3 7\n3 1\n1 6\n8 7\n4 3"]
#include<stdio.h> int n,d,k; void cat(){ int i,j; long long l,r; if(n<=d){ printf("NO\n"); return; } r=1; l=k; for(i=1;i*2-1<=d;i++){ j=d-(i*2-1); if(n-j-r<=l/k){ break; } j--; if(j>=0&&n-j-r>l/k&&n-j<=r+l){ break; } r+=l; l*=k-1; } if(i*2-1>d){ printf("NO\n"); return; } if(j>0&&k==1){ printf("NO\n"); return; } printf("YES\n"); if(n==1){ return; } printf("%d %d\n",1,2); for(i=2;i<n-j;i++){ printf("%d %d\n",(i-2)/(k-1)+1,i+1); } for(;i<n;i++){ printf("%d %d\n",i,i+1); } } void run(){ while(scanf("%d%d%d",&n,&d,&k)!=EOF){ cat(); } } main(){ #ifndef ONLINE_JUDGE freopen("4943e_min.in","rb",stdin); freopen("4943e_.out","wb",stdout); #endif run(); return 0; }
You are given three integers $$$n$$$, $$$d$$$ and $$$k$$$.Your task is to construct an undirected tree on $$$n$$$ vertices with diameter $$$d$$$ and degree of each vertex at most $$$k$$$, or say that it is impossible.An undirected tree is a connected undirected graph with $$$n - 1$$$ edges.Diameter of a tree is the maximum length of a simple path (a path in which each vertex appears at most once) between all pairs of vertices of this tree.Degree of a vertex is the number of edges incident to this vertex (i.e. for a vertex $$$u$$$ it is the number of edges $$$(u, v)$$$ that belong to the tree, where $$$v$$$ is any other vertex of a tree).
If there is no tree satisfying the conditions above, print only one word "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), and then print $$$n - 1$$$ lines describing edges of a tree satisfying the conditions above. Vertices of the tree must be numbered from $$$1$$$ to $$$n$$$. You can print edges and vertices connected by an edge in any order. If there are multiple answers, print any of them.1
C
a4849505bca48b408a5e8fb5aebf5cb6
8a3475752407e14ea0eeb99dfd82e48e
GNU C
standard output
256 megabytes
train_002.jsonl
[ "constructive algorithms", "graphs" ]
1530628500
["6 3 3", "6 2 3", "10 4 3", "8 5 3"]
null
PASSED
2,100
standard input
4 seconds
The first line of the input contains three integers $$$n$$$, $$$d$$$ and $$$k$$$ ($$$1 \le n, d, k \le 4 \cdot 10^5$$$).
["YES\n3 1\n4 1\n1 2\n5 2\n2 6", "NO", "YES\n2 9\n2 10\n10 3\n3 1\n6 10\n8 2\n4 3\n5 6\n6 7", "YES\n2 5\n7 2\n3 7\n3 1\n1 6\n8 7\n4 3"]
#define _USE_MATH_DEFINES #include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <stdbool.h> #include <float.h> #include <limits.h> #include <malloc.h> #include <memory.h> #include <complex.h> #include <errno.h> #include <time.h> #define Max(X,Y) ((X)>(Y) ? (X) : (Y)) #define Min(X,Y) ((X)<(Y) ? (X) : (Y)) #define Swap(X,Y) (X=X^Y,Y=X^Y,X=X^Y) #define EPS 1e-7 #define MOD 998244353 #define N 400005 int n,d,k,i,sum,c,tot; long long tt,a[N],b[N],s[N]; void hunter(int x,int y) { int i,t; if (x>c||!sum) return; t=x==1 ? k-2 : k-1; for (i=1;i<=t;i++) if (sum) { printf("%d %d\n",y,++tot); sum--; hunter(x+1,tot); } else return; } int main() { scanf("%d %d %d",&n,&d,&k); sum=n-d-1; for (i=1;i<=d+2>>1;i++) a[i]=i-1; for (i=1+(d+2>>1);i<=d+1;i++) a[i]=d+1-i; for (i=2,b[1]=s[1]=k-2;i<=d+2>>1;i++) { b[i]=b[i-1]*(k-1)%N; s[i]=s[i-1]+b[i]; } for (i=2,tt=0;i<=d;i++) tt+=s[a[i]]; if (tt<sum||sum<0) { puts("NO"); exit(0); } puts("YES"); for (i=1;i<=d;i++) printf("%d %d\n",i,i+1); for (i=2,tot=d+1;i<=d;i++) { c=a[i]; hunter(1,i); } return 0; }
Anton likes permutations, especially he likes to permute their elements. Note that a permutation of n elements is a sequence of numbers {a1, a2, ..., an}, in which every number from 1 to n appears exactly once.One day Anton got a new permutation and started to play with it. He does the following operation q times: he takes two elements of the permutation and swaps these elements. After each operation he asks his friend Vanya, how many inversions there are in the new permutation. The number of inversions in a permutation is the number of distinct pairs (i, j) such that 1 ≀ i &lt; j ≀ n and ai &gt; aj.Vanya is tired of answering Anton's silly questions. So he asked you to write a program that would answer these questions instead of him.Initially Anton's permutation was {1, 2, ..., n}, that is ai = i for all i such that 1 ≀ i ≀ n.
Output q lines. The i-th line of the output is the number of inversions in the Anton's permutation after the i-th operation.
C
ed9375dfd4749173472c0c18814c2855
8bb635228822a38b9df51b35ae051812
GNU C
standard output
512 megabytes
train_002.jsonl
[ "data structures", "brute force" ]
1489590300
["5 4\n4 5\n2 4\n2 5\n2 2", "2 1\n2 1", "6 7\n1 4\n3 5\n2 3\n3 3\n3 6\n2 1\n5 1"]
NoteConsider the first sample.After the first Anton's operation the permutation will be {1, 2, 3, 5, 4}. There is only one inversion in it: (4, 5).After the second Anton's operation the permutation will be {1, 5, 3, 2, 4}. There are four inversions: (2, 3), (2, 4), (2, 5) and (3, 4).After the third Anton's operation the permutation will be {1, 4, 3, 2, 5}. There are three inversions: (2, 3), (2, 4) and (3, 4).After the fourth Anton's operation the permutation doesn't change, so there are still three inversions.
PASSED
2,200
standard input
4 seconds
The first line of the input contains two integers n and q (1 ≀ n ≀ 200 000, 1 ≀ q ≀ 50 000)Β β€” the length of the permutation and the number of operations that Anton does. Each of the following q lines of the input contains two integers li and ri (1 ≀ li, ri ≀ n)Β β€” the indices of elements that Anton swaps during the i-th operation. Note that indices of elements that Anton swaps during the i-th operation can coincide. Elements in the permutation are numbered starting with one.
["1\n4\n3\n3", "1", "5\n6\n7\n7\n10\n11\n8"]
#include <math.h> #include <stdio.h> /* http://codeforces.com/contest/785/submission/25670789 (Dukkha) */ #define N 200000 int aa[N], bb[N]; int n, k; int search(int i, int j, int a) { int lower = i - 1, upper = j, mid; while (upper - lower > 1) { mid = (lower + upper) / 2; if (bb[mid] <= a) lower = mid; else upper = mid; } return lower; } int count(int l, int r, int lower, int upper) { int h, cnt; cnt = 0; for (h = l; h < r && h % k > 0; h++) if (aa[h] > lower && aa[h] < upper) cnt++; for (; h + k < r; h += k) cnt += search(h, h + k, upper) - search(h, h + k, lower); for (; h < r; h++) if (aa[h] > lower && aa[h] < upper) cnt++; return cnt; } void update(int x, int a, int b) { int h, i, j; i = x / k * k, j = i + k < n ? i + k : n; h = search(i, j, a); if (a < b) while (h + 1 < j && bb[h + 1] < b) { bb[h] = bb[h + 1]; h++; } else while (h - 1 >= i && bb[h - 1] > b) { bb[h] = bb[h - 1]; h--; } bb[h] = b; } int main() { long long cnt; int q, i; scanf("%d%d", &n, &q); for (i = 0; i < n; i++) aa[i] = bb[i] = i; cnt = 0; k = sqrt(n * 3); while (q-- > 0) { int l, r, tmp; scanf("%d%d", &l, &r); l--, r--; if (l > r) tmp = l, l = r, r = tmp; if (l != r) { if (aa[l] < aa[r]) cnt += count(l + 1, r, aa[l], aa[r]) * 2 + 1; else cnt -= count(l + 1, r, aa[r], aa[l]) * 2 + 1; if (l / k != r / k) { update(l, aa[l], aa[r]); update(r, aa[r], aa[l]); } tmp = aa[l], aa[l] = aa[r], aa[r] = tmp; } printf("%lld\n", cnt); } return 0; }
Anton likes permutations, especially he likes to permute their elements. Note that a permutation of n elements is a sequence of numbers {a1, a2, ..., an}, in which every number from 1 to n appears exactly once.One day Anton got a new permutation and started to play with it. He does the following operation q times: he takes two elements of the permutation and swaps these elements. After each operation he asks his friend Vanya, how many inversions there are in the new permutation. The number of inversions in a permutation is the number of distinct pairs (i, j) such that 1 ≀ i &lt; j ≀ n and ai &gt; aj.Vanya is tired of answering Anton's silly questions. So he asked you to write a program that would answer these questions instead of him.Initially Anton's permutation was {1, 2, ..., n}, that is ai = i for all i such that 1 ≀ i ≀ n.
Output q lines. The i-th line of the output is the number of inversions in the Anton's permutation after the i-th operation.
C
ed9375dfd4749173472c0c18814c2855
b7463902cbc53661bf03dcb2e5ba2dc5
GNU C
standard output
512 megabytes
train_002.jsonl
[ "data structures", "brute force" ]
1489590300
["5 4\n4 5\n2 4\n2 5\n2 2", "2 1\n2 1", "6 7\n1 4\n3 5\n2 3\n3 3\n3 6\n2 1\n5 1"]
NoteConsider the first sample.After the first Anton's operation the permutation will be {1, 2, 3, 5, 4}. There is only one inversion in it: (4, 5).After the second Anton's operation the permutation will be {1, 5, 3, 2, 4}. There are four inversions: (2, 3), (2, 4), (2, 5) and (3, 4).After the third Anton's operation the permutation will be {1, 4, 3, 2, 5}. There are three inversions: (2, 3), (2, 4) and (3, 4).After the fourth Anton's operation the permutation doesn't change, so there are still three inversions.
PASSED
2,200
standard input
4 seconds
The first line of the input contains two integers n and q (1 ≀ n ≀ 200 000, 1 ≀ q ≀ 50 000)Β β€” the length of the permutation and the number of operations that Anton does. Each of the following q lines of the input contains two integers li and ri (1 ≀ li, ri ≀ n)Β β€” the indices of elements that Anton swaps during the i-th operation. Note that indices of elements that Anton swaps during the i-th operation can coincide. Elements in the permutation are numbered starting with one.
["1\n4\n3\n3", "1", "5\n6\n7\n7\n10\n11\n8"]
#include <math.h> #include <stdio.h> #include <stdlib.h> /* http://codeforces.com/contest/785/submission/25674261 (Dukkha) */ int **tt, *aa; int n, k, m; void alloc() { int i; aa = malloc(n * sizeof *aa); tt = malloc(m * sizeof *tt); for (i = 0; i < m; i++) tt[i] = calloc(n, sizeof *tt[i]); } void update(int i, int j_, int a) { while (i < m) { int j = j_; while (j < n) { tt[i][j] += a; j |= j + 1; } i |= i + 1; } } int query(int i, int j_) { int sum = 0; while (i >= 0) { int j = j_; while (j >= 0) { sum += tt[i][j]; j &= j + 1; j--; } i &= i + 1; i--; } return sum; } void update_(int i, int a) { update(i / k, aa[i], a); } int query_(int i) { int cnt = query(i / k - 1, aa[i]); int j; for (j = i / k * k; j < i; j++) if (aa[j] < aa[i]) cnt++; return cnt * 2 + aa[i] - i; } int main() { long long cnt; int q, i; scanf("%d%d", &n, &q); k = sqrt(n); m = (n - 1) / k + 1; alloc(); for (i = 0; i < n; i++) { aa[i] = n - 1 - i; update_(i, 1); } cnt = 0; while (q-- > 0) { int l, r, tmp; scanf("%d%d", &l, &r); l--, r--; if (l != r) { if (l > r) tmp = l, l = r, r = tmp; cnt -= query_(l) + query_(r); update_(l, -1); update_(r, -1); tmp = aa[l], aa[l] = aa[r], aa[r] = tmp; cnt += aa[l] < aa[r] ? -1 : 1; update_(l, 1); update_(r, 1); cnt += query_(l) + query_(r); } printf("%lld\n", cnt); } return 0; }
Anton likes permutations, especially he likes to permute their elements. Note that a permutation of n elements is a sequence of numbers {a1, a2, ..., an}, in which every number from 1 to n appears exactly once.One day Anton got a new permutation and started to play with it. He does the following operation q times: he takes two elements of the permutation and swaps these elements. After each operation he asks his friend Vanya, how many inversions there are in the new permutation. The number of inversions in a permutation is the number of distinct pairs (i, j) such that 1 ≀ i &lt; j ≀ n and ai &gt; aj.Vanya is tired of answering Anton's silly questions. So he asked you to write a program that would answer these questions instead of him.Initially Anton's permutation was {1, 2, ..., n}, that is ai = i for all i such that 1 ≀ i ≀ n.
Output q lines. The i-th line of the output is the number of inversions in the Anton's permutation after the i-th operation.
C
ed9375dfd4749173472c0c18814c2855
149bf669930805cd426bdde19f3b97c1
GNU C
standard output
512 megabytes
train_002.jsonl
[ "data structures", "brute force" ]
1489590300
["5 4\n4 5\n2 4\n2 5\n2 2", "2 1\n2 1", "6 7\n1 4\n3 5\n2 3\n3 3\n3 6\n2 1\n5 1"]
NoteConsider the first sample.After the first Anton's operation the permutation will be {1, 2, 3, 5, 4}. There is only one inversion in it: (4, 5).After the second Anton's operation the permutation will be {1, 5, 3, 2, 4}. There are four inversions: (2, 3), (2, 4), (2, 5) and (3, 4).After the third Anton's operation the permutation will be {1, 4, 3, 2, 5}. There are three inversions: (2, 3), (2, 4) and (3, 4).After the fourth Anton's operation the permutation doesn't change, so there are still three inversions.
PASSED
2,200
standard input
4 seconds
The first line of the input contains two integers n and q (1 ≀ n ≀ 200 000, 1 ≀ q ≀ 50 000)Β β€” the length of the permutation and the number of operations that Anton does. Each of the following q lines of the input contains two integers li and ri (1 ≀ li, ri ≀ n)Β β€” the indices of elements that Anton swaps during the i-th operation. Note that indices of elements that Anton swaps during the i-th operation can coincide. Elements in the permutation are numbered starting with one.
["1\n4\n3\n3", "1", "5\n6\n7\n7\n10\n11\n8"]
#include <stdio.h> #include <string.h> #define N0 1877 typedef long long LL; int n,m,q,a[200010],b[200010]; void update(int pos,int val); int count(int pos); int query(int pos,int val); int main(void) { //freopen("permutation.in","r",stdin); //freopen("permutation.out","w",stdout); scanf("%d%d",&n,&q); m=(n-1)/N0+1; int i; for(i=1;i<=n;i++) a[i]=b[i]=i; LL ans=0; int x,y,l,r,t; for(i=1;i<=q;i++) { scanf("%d%d",&l,&r); if(l>r) { t=l; l=r; r=t; } if(l<r&&a[l]<a[r]) ans--; else if(l<r) ans++; ans-=count(l)+count(r); x=a[l]; y=a[r]; update(l,y); update(r,x); ans+=count(l)+count(r); printf("%I64d\n",ans); } return 0; } void update(int pos,int val) { int k=(pos-1)/N0+1,i,j,t; for(i=1;i<=N0;i++) if(b[(k-1)*N0+i]==a[pos]) { b[(k-1)*N0+i]=val; break; } for( j=(k-1)*N0+i ; j<n && j<k*N0 && b[j]>b[j+1] ; j++ ) { t=b[j]; b[j]=b[j+1]; b[j+1]=t; } for( j=(k-1)*N0+i ; j>(k-1)*N0+1 && b[j]<b[j-1] ; j-- ) { t=b[j]; b[j]=b[j-1]; b[j-1]=t; } a[pos]=val; } int count(int pos) { return query(pos,n)-query(pos,a[pos])+query(n,a[pos]-1)-query(pos,a[pos]-1); } int query(int pos,int val) { int k=(pos-1)/N0+1,i,ans=0,l,r,m; for(i=1;i<=(pos-1)%N0+1;i++) if(a[(k-1)*N0+i]<=val) ans++; for(i=1;i<k;i++) { l=0; r=N0; while(l<r) { m=(l+r+1)/2; if(b[(i-1)*N0+m]<=val) l=m; else r=m-1; } ans+=l; } return ans; }
Anton likes permutations, especially he likes to permute their elements. Note that a permutation of n elements is a sequence of numbers {a1, a2, ..., an}, in which every number from 1 to n appears exactly once.One day Anton got a new permutation and started to play with it. He does the following operation q times: he takes two elements of the permutation and swaps these elements. After each operation he asks his friend Vanya, how many inversions there are in the new permutation. The number of inversions in a permutation is the number of distinct pairs (i, j) such that 1 ≀ i &lt; j ≀ n and ai &gt; aj.Vanya is tired of answering Anton's silly questions. So he asked you to write a program that would answer these questions instead of him.Initially Anton's permutation was {1, 2, ..., n}, that is ai = i for all i such that 1 ≀ i ≀ n.
Output q lines. The i-th line of the output is the number of inversions in the Anton's permutation after the i-th operation.
C
ed9375dfd4749173472c0c18814c2855
904cd96b2da2b2059e422a8674781274
GNU C
standard output
512 megabytes
train_002.jsonl
[ "data structures", "brute force" ]
1489590300
["5 4\n4 5\n2 4\n2 5\n2 2", "2 1\n2 1", "6 7\n1 4\n3 5\n2 3\n3 3\n3 6\n2 1\n5 1"]
NoteConsider the first sample.After the first Anton's operation the permutation will be {1, 2, 3, 5, 4}. There is only one inversion in it: (4, 5).After the second Anton's operation the permutation will be {1, 5, 3, 2, 4}. There are four inversions: (2, 3), (2, 4), (2, 5) and (3, 4).After the third Anton's operation the permutation will be {1, 4, 3, 2, 5}. There are three inversions: (2, 3), (2, 4) and (3, 4).After the fourth Anton's operation the permutation doesn't change, so there are still three inversions.
PASSED
2,200
standard input
4 seconds
The first line of the input contains two integers n and q (1 ≀ n ≀ 200 000, 1 ≀ q ≀ 50 000)Β β€” the length of the permutation and the number of operations that Anton does. Each of the following q lines of the input contains two integers li and ri (1 ≀ li, ri ≀ n)Β β€” the indices of elements that Anton swaps during the i-th operation. Note that indices of elements that Anton swaps during the i-th operation can coincide. Elements in the permutation are numbered starting with one.
["1\n4\n3\n3", "1", "5\n6\n7\n7\n10\n11\n8"]
#include <stdio.h> #include <string.h> #include <stdbool.h> #include <assert.h> #define LIM 2000 #define MAX 200010 #define clr(ar) memset(ar, 0, sizeof(ar)) #define read() freopen("lol.txt", "r", stdin) long long res = 0; int n, m, d, q, lim, ar[MAX], lol[MAX], tmp[MAX], tree[(MAX / LIM) + 5][MAX]; void update(int *tree, int p, int v){ while (p <= lim){ tree[p] += v; p += (p & (-p)); } } int query(int *tree, int p){ int res = 0; while (p){ res += tree[p]; p ^= (p & (-p)); } return res; } void mergesort(int i, int j){ if (i == j) return; int ini = i, k = (i + j) >> 1, l = k + 1; mergesort(i, k); mergesort(l, j); int idx = 0; while (i <= k && l <= j){ if (lol[i] <= lol[l]) tmp[idx++] = lol[i++]; else{ res += (l - ini - idx); tmp[idx++] = lol[l++]; } } while (i <= k) tmp[idx++] = lol[i++]; while (l <= j){ res += (l - ini - idx); tmp[idx++] = lol[l++]; } memcpy(&lol[ini], &tmp[0], idx << 2); } void build(){ int i, j, k, l, x, y, v; m = LIM, d = (n - 1) / LIM; for (i = 0; i < n; i += m){ for (j = 0, k = i / m; (i + j) < n && j < m; j++){ update(tree[k], ar[i + j], 1); } } for (i = 0, res = 0; i < n; i++) lol[i] = ar[i]; mergesort(0, n - 1); } void modify(int i, int v){ int j, k, l, x, y; k = i / m, l = (k * m), x = ar[i], ar[i] = v; update(tree[k], x, -1); for (j = i - 1; j >= l; j--) res -= (ar[j] > x); for (j = i + 1; j < (l + m) && j < n; j++) res -= (ar[j] < x); for (j = 0; j < k; j++) res -= (m - query(tree[j], x)); for (j = k + 1; j <= d; j++) res -= query(tree[j], x - 1); update(tree[k], v, 1); for (j = i - 1; j >= l; j--) res += (ar[j] > v); for (j = i + 1; j < (l + m) && j < n; j++) res += (ar[j] < v); for (j = 0; j < k; j++) res += (m - query(tree[j], v)); for (j = k + 1; j <= d; j++) res += query(tree[j], v - 1); } int main(){ int i, j, k, l, r, x, y, u, v; scanf("%d %d", &n, &q); for (i = 0; i < n; i++) ar[i] = i + 1; for (lim = 0, i = 0; i < n; i++){ if (ar[i] > lim) lim = ar[i]; } build(); while (q--){ scanf("%d %d", &l, &r); l--, r--; if (l != r){ u = ar[l], v = ar[r]; modify(l, v); modify(r, u); } printf("%lld\n", res); } return 0; }
Anton likes permutations, especially he likes to permute their elements. Note that a permutation of n elements is a sequence of numbers {a1, a2, ..., an}, in which every number from 1 to n appears exactly once.One day Anton got a new permutation and started to play with it. He does the following operation q times: he takes two elements of the permutation and swaps these elements. After each operation he asks his friend Vanya, how many inversions there are in the new permutation. The number of inversions in a permutation is the number of distinct pairs (i, j) such that 1 ≀ i &lt; j ≀ n and ai &gt; aj.Vanya is tired of answering Anton's silly questions. So he asked you to write a program that would answer these questions instead of him.Initially Anton's permutation was {1, 2, ..., n}, that is ai = i for all i such that 1 ≀ i ≀ n.
Output q lines. The i-th line of the output is the number of inversions in the Anton's permutation after the i-th operation.
C
ed9375dfd4749173472c0c18814c2855
f8e6a1c372f2f0af7bf0342dbc2c4729
GNU C
standard output
512 megabytes
train_002.jsonl
[ "data structures", "brute force" ]
1489590300
["5 4\n4 5\n2 4\n2 5\n2 2", "2 1\n2 1", "6 7\n1 4\n3 5\n2 3\n3 3\n3 6\n2 1\n5 1"]
NoteConsider the first sample.After the first Anton's operation the permutation will be {1, 2, 3, 5, 4}. There is only one inversion in it: (4, 5).After the second Anton's operation the permutation will be {1, 5, 3, 2, 4}. There are four inversions: (2, 3), (2, 4), (2, 5) and (3, 4).After the third Anton's operation the permutation will be {1, 4, 3, 2, 5}. There are three inversions: (2, 3), (2, 4) and (3, 4).After the fourth Anton's operation the permutation doesn't change, so there are still three inversions.
PASSED
2,200
standard input
4 seconds
The first line of the input contains two integers n and q (1 ≀ n ≀ 200 000, 1 ≀ q ≀ 50 000)Β β€” the length of the permutation and the number of operations that Anton does. Each of the following q lines of the input contains two integers li and ri (1 ≀ li, ri ≀ n)Β β€” the indices of elements that Anton swaps during the i-th operation. Note that indices of elements that Anton swaps during the i-th operation can coincide. Elements in the permutation are numbered starting with one.
["1\n4\n3\n3", "1", "5\n6\n7\n7\n10\n11\n8"]
#include <stdio.h> #define BLOCKSIZE 1000 #define BLOCK(x) ((x - 1) / BLOCKSIZE + 1) #define INDEX(x) ((x - 1) % BLOCKSIZE + 1) void Swap(int *a, int *b) { int t; t = *a; *a = *b; *b = t; } int n, bt[205][200005]; void BITModify(int blk, int idx, int det) { for (; idx <= n; idx += idx & -idx) bt[blk][idx] += det; } int BITQuery(int blk, int idx) { int ret; for (ret = 0; idx; idx -= idx & -idx) ret += bt[blk][idx]; return ret; } int num[200005]; int main(int argc, char *argv[]) { int q, i, j, k, l, r, cntL, cntR; long long ans; scanf("%d%d", &n, &q); for (i = 1; i <= n; ++i) { num[i] = i; BITModify(BLOCK(i), i, 1); } for (k = 1, ans = 0; k <= q; ++k) { scanf("%d%d", &l, &r); if (l > r) Swap(&l, &r); if (l < r) { cntL = cntR = 0; if (BLOCK(l) == BLOCK(r)) { for (i = l + 1; i <= r - 1; ++i) { cntL += num[i] < num[l]; cntR += num[i] < num[r]; } } else { for (i = l + 1; INDEX(i) != 1; ++i) { cntL += num[i] < num[l]; cntR += num[i] < num[r]; } for (j = BLOCK(i); j != BLOCK(r); ++j) { cntL += BITQuery(j, num[l]); cntR += BITQuery(j, num[r]); } for (i = r - 1; INDEX(i) != BLOCKSIZE; --i) { cntL += num[i] < num[l]; cntR += num[i] < num[r]; } } ans += 2 * cntR - 2 * cntL + (num[l] < num[r] ? 1 : -1); BITModify(BLOCK(l), num[l], -1); BITModify(BLOCK(r), num[r], -1); Swap(&num[l], &num[r]); BITModify(BLOCK(l), num[l], 1); BITModify(BLOCK(r), num[r], 1); } printf("%I64d\n", ans); } return 0; }
Let's assume that we are given an n × m table filled by integers. We'll mark a cell in the i-th row and j-th column as (i, j). Thus, (1, 1) is the upper left cell of the table and (n, m) is the lower right cell. We'll assume that a circle of radius r with the center in cell (i0, j0) is a set of such cells (i, j) that . We'll consider only the circles that do not go beyond the limits of the table, that is, for which r + 1 ≀ i0 ≀ n - r and r + 1 ≀ j0 ≀ m - r. A circle of radius 3 with the center at (4, 5). Find two such non-intersecting circles of the given radius r that the sum of numbers in the cells that belong to these circles is maximum. Two circles intersect if there is a cell that belongs to both circles. As there can be more than one way to choose a pair of circles with the maximum sum, we will also be interested in the number of such pairs. Calculate the number of unordered pairs of circles, for instance, a pair of circles of radius 2 with centers at (3, 4) and (7, 7) is the same pair as the pair of circles of radius 2 with centers at (7, 7) and (3, 4).
Print two integers β€” the maximum sum of numbers in the cells that are located into two non-intersecting circles and the number of pairs of non-intersecting circles with the maximum sum. If there isn't a single pair of non-intersecting circles, print 0 0.
C
a1ef0079119e18de424a81b05b68bb4c
5db39811146b1cc1edff653bb30c467c
GNU C
standard output
256 megabytes
train_002.jsonl
[ "data structures", "implementation", "brute force" ]
1384156800
["2 2 0\n1 2\n2 4", "5 6 1\n4 2 1 3 2 6\n2 3 2 4 7 2\n5 2 2 1 1 3\n1 4 3 3 6 4\n5 1 4 2 3 2", "3 3 1\n1 2 3\n4 5 6\n7 8 9"]
null
PASSED
2,500
standard input
4 seconds
The first line contains three integers n, m and r (2 ≀ n, m ≀ 500, r β‰₯ 0). Each of the following n lines contains m integers from 1 to 1000 each β€” the elements of the table. The rows of the table are listed from top to bottom at the elements in the rows are listed from left to right. It is guaranteed that there is at least one circle of radius r, not going beyond the table limits.
["6 2", "34 3", "0 0"]
#include <stdio.h> #include <string.h> #define MAXCIR 250033 #define MAXR 533 #define MAXC 533 typedef long long int llint; llint num[MAXR][MAXC]; llint sum[MAXR][MAXC]; llint bound[MAXC]; llint map[MAXR][MAXC]; llint dp[MAXR][MAXC]; llint cc[MAXR][MAXC]; llint d[MAXR][2]; llint tot[MAXR][MAXC]; llint n,m,r; llint can(llint dx,llint dy) { if(dx*dx+dy*dy<=r*r)return 1; else return 0; } int main() { llint i,j,k; llint dx,dy,tmp,nx,ny; llint max,cnt,ans,ans_cnt; llint t1; scanf("%I64d%I64d%I64d",&n,&m,&r); for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { scanf("%I64d",&num[i][j]); tot[i][j]=0; sum[i][j]=sum[i][j-1]+num[i][j]; } } d[0][0]=-r; d[0][1]=r; for(i=1;i<=r;i++) { d[i][0]=d[i-1][0]; d[i][1]=d[i-1][1]; while(can(i,d[i][0])==0)d[i][0]++; while(can(i,d[i][1])==0)d[i][1]--; } memset(map,0,sizeof(0)); for(i=0;i<=r;i++) { for(j=0;j<=r;j++) { nx=i+j; ny=d[i][1]+d[j][1]; for(k=0;k<=ny;k++)map[nx][k]=1; } } for(j=0;j<=m;j++) { bound[j]=n+1; for(i=n;i>=0;i--) if(map[i][j]==0)bound[j]--; else break; } /*check cover* / for(i=0;i<=n;i++) { for(j=0;j<=m;j++) { printf("%d ",map[i][j]); } puts(""); } puts("bound"); for(j=0;j<=m;j++) { printf("%d ",bound[j]); } puts(""); /**/ for(i=1+r;i<=n-r;i++) { for(j=1+r;j<=m-r;j++) { for(k=i-r;k<=i+r;k++) { if(i>k)dx=i-k; else dx=k-i; tmp=(sum[k][ j+d[dx][1] ] - sum[k][ j+d[dx][0]-1 ]); tot[i][j]+=tmp; } } } /*check tot* / puts("tot"); for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { printf("%2d ",tot[i][j]); } puts(""); } /**/ memset(dp,-1,sizeof(dp)); memset(cc,0,sizeof(cc)); for(j=1+r;j<=m-r;j++) { dp[n-r+1][j]=-1; cc[n-r+1][j]=0; } for(i=n-r;i>=1+r;i--) { for(j=1+r;j<=m-r;j++) { dp[i][j]=dp[i+1][j]; if(tot[i][j]>dp[i][j])dp[i][j]=tot[i][j],cc[i][j]=1; else if(tot[i][j]==dp[i][j])cc[i][j]=cc[i+1][j]+1; else cc[i][j]=cc[i+1][j]; } } /*check dp cc* / puts("dp"); for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { printf("%2d ",dp[i][j]); } puts(""); } puts("cc"); for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { printf("%2d ",cc[i][j]); } puts(""); } /**/ ans=0; ans_cnt=0; for(i=1+r;i<=n-r;i++) { for(j=1+r;j<=m-r;j++) { max=-1,cnt=0; for(k=j,t1=0;k<=m-r;k++,t1++) { if(dp[i+bound[t1]][k]>max)max=dp[i+bound[t1]][k],cnt=cc[i+bound[t1]][k]; else if(dp[i+bound[t1]][k]==max)cnt+=cc[i+bound[t1]][k]; } for(k=j-1,t1=1;k>=1+r;k--,t1++) { if(bound[t1]!=0) { if(dp[i+bound[t1]][k]>max)max=dp[i+bound[t1]][k],cnt=cc[i+bound[t1]][k]; else if(dp[i+bound[t1]][k]==max)cnt+=cc[i+bound[t1]][k]; } else { if(dp[i+bound[t1]+1][k]>max)max=dp[i+bound[t1]+1][k],cnt=cc[i+bound[t1]+1][k]; else if(dp[i+bound[t1]+1][k]==max)cnt+=cc[i+bound[t1]+1][k]; } } if(max==-1)continue; if(cnt==-1)continue; max+=tot[i][j]; /* test* / if(max==168) { printf("ij %d %d\n",i,j); puts("test"); for(k=j-1,t1=1;k>=1+r;k--,t1++) { if(bound[t1]==0) printf("%2d ",dp[i+bound[t1]+1][k]); else printf("%2d ",dp[i+bound[t1]][k]); } puts(""); for(k=j,t1=0;k<=m-r;k++,t1++) { printf("%2d ",dp[i+bound[t1]][k]); } puts(""); } /**/ if(max>ans && cnt!=-1)ans=max,ans_cnt=cnt; else if(max==ans && cnt!=-1)ans_cnt+=cnt; } } if(ans<=0 || ans_cnt<=0) puts("0 0"); else printf("%I64d %I64d\n",ans,ans_cnt); return 0; }
Let's assume that we are given an n × m table filled by integers. We'll mark a cell in the i-th row and j-th column as (i, j). Thus, (1, 1) is the upper left cell of the table and (n, m) is the lower right cell. We'll assume that a circle of radius r with the center in cell (i0, j0) is a set of such cells (i, j) that . We'll consider only the circles that do not go beyond the limits of the table, that is, for which r + 1 ≀ i0 ≀ n - r and r + 1 ≀ j0 ≀ m - r. A circle of radius 3 with the center at (4, 5). Find two such non-intersecting circles of the given radius r that the sum of numbers in the cells that belong to these circles is maximum. Two circles intersect if there is a cell that belongs to both circles. As there can be more than one way to choose a pair of circles with the maximum sum, we will also be interested in the number of such pairs. Calculate the number of unordered pairs of circles, for instance, a pair of circles of radius 2 with centers at (3, 4) and (7, 7) is the same pair as the pair of circles of radius 2 with centers at (7, 7) and (3, 4).
Print two integers β€” the maximum sum of numbers in the cells that are located into two non-intersecting circles and the number of pairs of non-intersecting circles with the maximum sum. If there isn't a single pair of non-intersecting circles, print 0 0.
C
a1ef0079119e18de424a81b05b68bb4c
6a1daaffb2678dffcb4d5241375be413
GNU C
standard output
256 megabytes
train_002.jsonl
[ "data structures", "implementation", "brute force" ]
1384156800
["2 2 0\n1 2\n2 4", "5 6 1\n4 2 1 3 2 6\n2 3 2 4 7 2\n5 2 2 1 1 3\n1 4 3 3 6 4\n5 1 4 2 3 2", "3 3 1\n1 2 3\n4 5 6\n7 8 9"]
null
PASSED
2,500
standard input
4 seconds
The first line contains three integers n, m and r (2 ≀ n, m ≀ 500, r β‰₯ 0). Each of the following n lines contains m integers from 1 to 1000 each β€” the elements of the table. The rows of the table are listed from top to bottom at the elements in the rows are listed from left to right. It is guaranteed that there is at least one circle of radius r, not going beyond the table limits.
["6 2", "34 3", "0 0"]
#include <stdio.h> #include <string.h> #define MAXCIR 250033 #define MAXR 533 #define MAXC 533 typedef long long int imo; imo num[MAXR][MAXC]; imo sum[MAXR][MAXC]; imo bound[MAXC]; imo map[MAXR][MAXC]; imo dp[MAXR][MAXC]; imo cc[MAXR][MAXC]; imo d[MAXR][2]; imo tot[MAXR][MAXC]; imo n,m,r; imo can(imo dx,imo dy) { if(dx*dx+dy*dy<=r*r)return 1; else return 0; } int main() { imo i,j,k; imo dx,dy,tmp,nx,ny; imo max,cnt,ans,ans_cnt; imo t1; scanf("%I64d%I64d%I64d",&n,&m,&r); for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { scanf("%I64d",&num[i][j]); tot[i][j]=0; sum[i][j]=sum[i][j-1]+num[i][j]; } } d[0][0]=-r; d[0][1]=r; for(i=1;i<=r;i++) { d[i][0]=d[i-1][0]; d[i][1]=d[i-1][1]; while(can(i,d[i][0])==0)d[i][0]++; while(can(i,d[i][1])==0)d[i][1]--; } memset(map,0,sizeof(0)); for(i=0;i<=r;i++) { for(j=0;j<=r;j++) { nx=i+j; ny=d[i][1]+d[j][1]; for(k=0;k<=ny;k++)map[nx][k]=1; } } for(j=0;j<=m;j++) { bound[j]=n+1; for(i=n;i>=0;i--) if(map[i][j]==0)bound[j]--; else break; } for(i=1+r;i<=n-r;i++) { for(j=1+r;j<=m-r;j++) { for(k=i-r;k<=i+r;k++) { if(i>k)dx=i-k; else dx=k-i; tmp=(sum[k][ j+d[dx][1] ] - sum[k][ j+d[dx][0]-1 ]); tot[i][j]+=tmp; } } } memset(dp,-1,sizeof(dp)); memset(cc,0,sizeof(cc)); for(j=1+r;j<=m-r;j++) { dp[n-r+1][j]=-1; cc[n-r+1][j]=0; } for(i=n-r;i>=1+r;i--) { for(j=1+r;j<=m-r;j++) { dp[i][j]=dp[i+1][j]; if(tot[i][j]>dp[i][j])dp[i][j]=tot[i][j],cc[i][j]=1; else if(tot[i][j]==dp[i][j])cc[i][j]=cc[i+1][j]+1; else cc[i][j]=cc[i+1][j]; } } ans=0; ans_cnt=0; for(i=1+r;i<=n-r;i++) { for(j=1+r;j<=m-r;j++) { max=-1,cnt=0; for(k=j,t1=0;k<=m-r;k++,t1++) { if(dp[i+bound[t1]][k]>max)max=dp[i+bound[t1]][k],cnt=cc[i+bound[t1]][k]; else if(dp[i+bound[t1]][k]==max)cnt+=cc[i+bound[t1]][k]; } for(k=j-1,t1=1;k>=1+r;k--,t1++) { if(bound[t1]!=0) { if(dp[i+bound[t1]][k]>max)max=dp[i+bound[t1]][k],cnt=cc[i+bound[t1]][k]; else if(dp[i+bound[t1]][k]==max)cnt+=cc[i+bound[t1]][k]; } else { if(dp[i+bound[t1]+1][k]>max)max=dp[i+bound[t1]+1][k],cnt=cc[i+bound[t1]+1][k]; else if(dp[i+bound[t1]+1][k]==max)cnt+=cc[i+bound[t1]+1][k]; } } if(max==-1)continue; if(cnt==-1)continue; max+=tot[i][j]; if(max>ans && cnt!=-1)ans=max,ans_cnt=cnt; else if(max==ans && cnt!=-1)ans_cnt+=cnt; } } if(ans<=0 || ans_cnt<=0) puts("0 0"); else printf("%I64d %I64d\n",ans,ans_cnt); return 0; }
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
7ba553b2c7a99b8d597c13d14fdd95c5
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
#include<stdio.h> int main() { int i,t; int d,a,b,c,max; scanf("%d",&t); for(i=1;i<=t;i++){ scanf("%d %d %d",&a, &b, &c); if (a>b && a>c){ max=a; } else if(b>a && b>c){ max=b; } else{ max=c; } d=max+1-a-b-c+max; if(d<=0){ d=1; printf("%d\n",d); } else{ printf("%d\n",d); } } }
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
d5cb00bb911c753b02e0b26cbc74f5d9
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
#include<stdio.h> int main(){ int t=0; long long int a,b,c,s,x,y,z; scanf("%lld",&t); while(t--){ scanf("%lld%lld%lld",&a,&b,&c); s=a+b+c; printf("%lld\n",s-2); } return 0; }
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
cf05f369aff743a20f645a769119f220
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
#include<stdio.h> main() { int t, max; int a[3]; scanf("%d", &t); while(t) { for(int i=0; i<3; i++) scanf("%d", &a[i]); max=a[0]; for(int i=1; i<3; i++) { if(max<a[i]) max = a[i]; } printf("%d\n", max); t--; } }
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
6aca36bab8691d3e80117b8f2d5ba8b6
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
#include<stdio.h> main() { long long t,a,b,c,d,i; scanf("%lld",&t); for(i=0;i<t;i++){ scanf("%lld %lld %lld",&a,&b,&c); d=(a+b+c-1); printf("%lld\n",d); } }
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
6ad31e87f7a4d8a8382ef26673719154
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
/*Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths a, b, and c. Now he needs to find out some possible integer length d of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to a, b, c, and d. Help Yura, find any possible length of the fourth side. A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself. Input The first line contains a single integer t β€” the number of test cases (1≀t≀1000). The next t lines describe the test cases. Each line contains three integers a, b, and c β€” the lengths of the three fence segments (1≀a,b,c≀10^9). Output For each test case print a single integer d β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.*/ #include<stdio.h> int main() { long long int a,b,c,d; int n,i; scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%lld %lld %lld",&a,&b,&c); d=(a+b+c)-2; printf("%lld\n",d); } return 0; }
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
e0cbff24b9c3462fc132ed4d70bc5c8e
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
#include<stdio.h> void solve() { int a, b, c; scanf("%d %d %d", &a, &b, &c); if (a >= b && a >= c) printf("%d\n", a); else if (b >= a && b >= c) printf("%d\n", b); else printf("%d\n", c); } int main() { int t; scanf("%d", &t); while (t--) { solve(); } return 0; }
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
66e7e987ec99d9dd2d205827c76f1594
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
#include<stdio.h> main() { long long int t; scanf("%I64d",&t); while(t--) { long long int a,b,c; scanf("%I64d%I64d%I64d",&a,&b,&c); long long int sum=0; sum=a+b+c-1; printf("%I64d\n",sum); } }
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
fe59e75fc4655b91fb6d154598971fa1
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
#include<stdio.h> #include<math.h> int main(void) { int t; scanf("%d",&t); while(t--) { long long a,b,c; scanf("%lld%lld%lld",&a,&b,&c); printf("%lld\n",(long long)sqrt(a*a+b*b+c*c)); // int ab=abs(a-b)+1; // for(d=(a+b+c)/3;;d++) // { // if(d>abs(ab-c)&&d<abs(ab+c)) // { // printf("%d\n",d); // break; // } // } } return 0; }
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
a55c98e77ce031929bc1dc44d1ca6158
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
#include <stdio.h> #include <stdlib.h> int main() { int t; scanf("%d",&t); while(t--) { long long a,b,c; scanf("%lld%lld%lld",&a,&b,&c); printf("%lld\n",(a+b+c-1)); } return 0; }
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
ebad55d4e43e0e3acf61b77ac23b780c
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
#include<stdio.h> int main() { int t; scanf("%d",&t); long long int a[t],b[t],c[t],r[t],d[t]; for(int i=1;i<=t;i++) { scanf("%lld%lld%lld",&a[i],&b[i],&c[i]); r[i]=abs(a[i]-b[i]); d[i]=c[i]+r[i]; printf("%lld\n",d[i]); } }
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
2b3a3eb20364eff103a5ca6922a36bb9
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
#include<stdio.h> int main() { int t; scanf("%d",&t); while(t--) { int a,b,c; scanf("%d %d %d",&a,&b,&c); int x=(a>b)? a:b; int y=(x>c)?x:c; printf("%d\n",y+1); } return 0; }
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
85949ed25b6680631886514defac52ce
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
#include <stdio.h> int main() { int a, b, c, max, t, i; scanf("%d", &t); for (i = 0; i < t; i++) { scanf("%d%d%d", &a, &b, &c); max = a - b - c; if (b - a - c > max) max = b - a - c; if (c - a - b > max) max = c - a - b; if (max < 0) max = 0; printf("%d\n", max + 1); } }
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
cd66091ece2ba1a48d3f0dde9b583eaa
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
#include <stdio.h> int main() { long long int t,a,b,c,d,i,j,x,y; scanf("%lld",&t); while(t--) { scanf("%lld%lld%lld",&a,&b,&c); x=a+b+c-2; printf("%lld\n",x); } return 0; }
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
1e6cbe77e3a646149caca61f921b5eb9
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
#include<stdio.h> #include<math.h> int main(){ int t,a,b,c,i=0,l,u; scanf("%d",&t); while(i<t) { scanf("%d%d%d",&a,&b,&c); l=c-a-b; u=a+b+c; if(l<0){ l=l*(-1); } printf("%d\n",l+1); i++; } return 0; }
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
be0cf8593401be339c21d63519c743b9
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
#include<stdio.h> int max(int a, int b) { return a > b ? a : b; } int main() { int t; scanf("%d", &t); while (t-- > 0) { int a, b, c; scanf("%d%d%d", &a, &b, &c); int ans = max(a, max(b, c)); printf("%d\n", ans+1); } return 0; }
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
6c48bccb66b0822dc8011e5903eefa53
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
#include<stdio.h> int xxx(int a,int b,int c) { if(a>b) { if(a>c) return a; else return c; } else { if(b>c) return b; else return c; } } int main() { int t; scanf("%d",&t); while(t--) { int a,b,c; scanf("%d%d%d",&a,&b,&c); printf("%d\n",xxx(a,b,c)); } return 0; }
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
27c9ec0ca3969de6db3c61848e50fa92
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
#include<stdio.h> int main() { long long a,b,c,d,n; scanf("%lld",&n); for(int i=0;i<n;i++){ scanf("%lld %lld %lld",&a,&b,&c); printf("%lld\n",a+b+c-1); } return 0; }
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
22fe54fa8cd93daabc6a830b07dcceff
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
//bismillah #include<stdio.h> int main() { int tc; scanf("%d",&tc); while(tc--) { unsigned long long int a,b,c; scanf("%llu %llu %llu",&a,&b,&c); printf("%llu\n",a+b+c-1); } return 0; }
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
08ce2227c1b069f3629063e6d2df99fd
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
#include <stdio.h> int findMax(int x, int y, int z) { if(x >= y && x >= z) return x; else if(y >= x && y >= z) return y; else return z; } int main() { long long int t, i, a, b, c, d_1, d_2, d_3, d_low, d_up, A[1000] = {0}; scanf("%lld", &t); for(i = 0 ; i < t ; i++) { scanf("%lld%lld%lld", &a, &b, &c); d_1 = a - b - c; d_2 = c - a - b; d_3 = b - a - c; d_low = findMax(d_1, d_2, d_3); d_up = a + b + c; A[i] = d_up - 2 ; } for(i = 0 ; i < t ; i++) printf("%lld\n", A[i]); return 0; }
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
88d266cde21a3a09c22246fb63907e22
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
// Nothing Special #include <stdio.h> #include <inttypes.h> int main() { #ifdef NothingSpecial freopen("std.in", "r", stdin); freopen("std.out", "w", stdout); #endif short int _; for (scanf("%hd", &_); _; _--) { int64_t a, b, c; scanf("%" PRId64 "%" PRId64 "%" PRId64, &a, &b, &c); printf("%" PRId64 "\n", a + b + c -1); } return 0; }
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
3b254c1d26e38b5059823fa4a160fb41
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
#include<stdio.h> int main() { int t; scanf("%d", &t); long long int a,b,c; while(t--) { scanf("%lld %lld %lld",&a,&b,&c); printf("%lld\n",a+b+c-1); } return 0; }
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
14b251f7b033bb56ac5c81c2028094e3
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
#include<stdio.h> long long int max(long long int x, long long int y); int main() { int t; scanf("%d\n", &t); while(t--) { long long int a,b,c, d, num; scanf("%llu %llu %llu\n", &a, &b, &c); num = a+b+c-1; printf("%llu\n", num); } return 0; } long long int max(long long int x, long long int y) { return (x > y) ? x : y; } //note: it's showing discrepancies in some of the inputs from the test 2 // wrong answer : Maximum value no less than sum other values on 96
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
57b38eebc08c525ca33a5ef9e1fcb0ce
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
#include<stdio.h> unsigned long long int max(unsigned long long int x,unsigned long long int y); int main() { int t; scanf("%d", &t); while(t--) { unsigned long long int a,b,c, d, num; scanf("%llu %llu %llu", &a, &b, &c); num = a+b+c-1; printf("%llu\n", num); } return 0; } unsigned long long int max(unsigned long long int x,unsigned long long int y) { return (x > y) ? x : y; }
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
2982f91b067619650617dcae90e41787
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
#include <stdio.h> int main() { int t; scanf("%d", &t); while (t--) { long long int a, b, c; scanf("%lld %lld %lld", &a, &b, &c); printf("%lld\n", a + b + c - 1); } }
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
f50c3513fa6652de4e2326530ba3a75c
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
#include<stdio.h> int main(){ int test,i,j,k; scanf("%d",&test); while(test--){ scanf("%d %d %d",&i,&j,&k); unsigned long int sum=i+j+k; printf("%u\n",sum-1); } }
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
b5efbf36c1dd2a5bc81887e7f372e3a6
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
#include<stdio.h> int main() { int t; scanf("%d", &t); long long int a, b, c; for (; t > 0; t--) { scanf("%lld %lld %lld", &a, &b, &c); printf("%lld\n", a + b + c - 1); } return 0; }
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
089920bae89065de8e5fbd2a732937bb
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
#include<stdio.h> #include<math.h> long long int min(long long int a,long long int b) { if(a<=b) return(a); return(b); } long long int mod(int a) { if(a<0) return(-a); else return(a); } int main() { int t;scanf("%d",&t); while(t--) { long long int a,b,c;scanf("%lld %lld %lld",&a,&b,&c); printf("%lld\n",(a+b+c)-1); } return 0; }
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
C
40d679f53417ba058144c745e7a2c76d
e3e5072e732a581795c52ac5ae04466b
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "geometry", "math" ]
1601827500
["2\n1 2 3\n12 34 56"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
PASSED
800
standard input
1 second
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
["4\n42"]
#include<stdio.h> int max(int a ,int b) { return a>b?a:b; } int main() { int t; scanf("%d",&t); while(t--) { int a,b,c,p; scanf("%d%d%d",&a,&b,&c); p=max(a,max(b,c)); printf("%d\n",p); } }
One day Masha came home and noticed n mice in the corridor of her flat. Of course, she shouted loudly, so scared mice started to run to the holes in the corridor.The corridor can be represeted as a numeric axis with n mice and m holes on it. ith mouse is at the coordinate xi, and jth hole β€” at coordinate pj. jth hole has enough room for cj mice, so not more than cj mice can enter this hole.What is the minimum sum of distances that mice have to go through so that they all can hide in the holes? If ith mouse goes to the hole j, then its distance is |xi - pj|.Print the minimum sum of distances.
Print one integer number β€” the minimum sum of distances. If there is no solution, print -1 instead.
C
d9adb80515689c6939f8e010005f7208
f8f8ecc1df8612bd7e1eab6483007be2
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "dp", "sortings", "greedy", "data structures" ]
1492266900
["4 5\n6 2 8 9\n3 6\n2 1\n3 6\n4 7\n4 7", "7 2\n10 20 30 40 50 45 35\n-1000000000 10\n1000000000 1"]
null
PASSED
2,600
standard input
1.5 seconds
The first line contains two integer numbers n, m (1 ≀ n, m ≀ 5000) β€” the number of mice and the number of holes, respectively. The second line contains n integers x1, x2, ..., xn ( - 109 ≀ xi ≀ 109), where xi is the coordinate of ith mouse. Next m lines contain pairs of integer numbers pj, cj ( - 109 ≀ pj ≀ 109, 1 ≀ cj ≀ 5000), where pj is the coordinate of jth hole, and cj is the maximum number of mice that can hide in the hole j.
["11", "7000000130"]
#include <stdio.h> #include <stdlib.h> #include <string.h> #define N 5000 #define M 5000 #define INF 0x3f3f3f3f3f3f3f3fLL int compare(const void *a, const void *b) { int ia = *(int *) a; int ib = *(int *) b; return ia - ib; } struct V { int x, c; } vv[M]; int compare_V(const void *a, const void *b) { struct V *u = (struct V *) a; struct V *v = (struct V *) b; return u->x - v->x; } int main() { static int xx[N], qu[N + 1]; static long long pr[N + 1], dp[N + 1], dq[N + 1]; int n, m, i, j, head, cnt; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) scanf("%d", &xx[i]); qsort(xx, n, sizeof *xx, compare); for (j = 0; j < m; j++) { struct V *v = &vv[j]; scanf("%d%d", &v->x, &v->c); } qsort(vv, m, sizeof *vv, compare_V); memset(dp, 0x3f, (n + 1) * sizeof *dp), dp[0] = 0; for (j = 0; j < m; j++) { struct V *v = &vv[j]; for (i = 0; i < n; i++) pr[i + 1] = pr[i] + abs(xx[i] - v->x); head = cnt = 0; for (i = 0; i <= n; i++) { while (cnt && dp[qu[head + cnt - 1]] - pr[qu[head + cnt - 1]] > dp[i] - pr[i]) cnt--; qu[head + cnt++] = i; dq[i] = dp[qu[head]] - pr[qu[head]] + pr[i]; if (qu[head] == i - v->c) head++, cnt--; } for (i = 0; i <= n; i++) dp[i] = dq[i]; } printf("%lld\n", dp[n] == INF ? -1 : dp[n]); return 0; }
It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one..There is a glob pattern in the statements (a string consisting of lowercase English letters, characters "?" and "*"). It is known that character "*" occurs no more than once in the pattern.Also, n query strings are given, it is required to determine for each of them if the pattern matches it or not.Everything seemed easy to Petya, but then he discovered that the special pattern characters differ from their usual meaning.A pattern matches a string if it is possible to replace each character "?" with one good lowercase English letter, and the character "*" (if there is one) with any, including empty, string of bad lowercase English letters, so that the resulting string is the same as the given string.The good letters are given to Petya. All the others are bad.
Print n lines: in the i-th of them print "YES" if the pattern matches the i-th query string, and "NO" otherwise. You can choose the case (lower or upper) for each letter arbitrary.
C
c6633581d7424d670eaa0f8a5c8cc366
e50038d81fdd6a9e6ac2c8cf9383e602
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "strings" ]
1500906900
["ab\na?a\n2\naaa\naab", "abc\na?a?a*\n4\nabacaba\nabaca\napapa\naaaaax"]
NoteIn the first example we can replace "?" with good letters "a" and "b", so we can see that the answer for the first query is "YES", and the answer for the second query is "NO", because we can't match the third letter.Explanation of the second example. The first query: "NO", because character "*" can be replaced with a string of bad letters only, but the only way to match the query string is to replace it with the string "ba", in which both letters are good. The second query: "YES", because characters "?" can be replaced with corresponding good letters, and character "*" can be replaced with empty string, and the strings will coincide. The third query: "NO", because characters "?" can't be replaced with bad letters. The fourth query: "YES", because characters "?" can be replaced with good letters "a", and character "*" can be replaced with a string of bad letters "x".
PASSED
1,600
standard input
2 seconds
The first line contains a string with length from 1 to 26 consisting of distinct lowercase English letters. These letters are good letters, all the others are bad. The second line contains the patternΒ β€” a string s of lowercase English letters, characters "?" and "*" (1 ≀ |s| ≀ 105). It is guaranteed that character "*" occurs in s no more than once. The third line contains integer n (1 ≀ n ≀ 105)Β β€” the number of query strings. n lines follow, each of them contains single non-empty string consisting of lowercase English lettersΒ β€” a query string. It is guaranteed that the total length of all query strings is not greater than 105.
["YES\nNO", "NO\nYES\nNO\nYES"]
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> int main() { char good[27]; int goodi[27]={0},n,i,m,pos1,pos2,flag,sl,ql,ql2,j,star; char s[100005],q[100005]; scanf("%s", good); scanf("%s", s); scanf("%d", &n); m = strlen(good); sl = strlen(s); star=0; for (i=0; i<sl; i++) if (s[i] == '*') star=1; for (i=0; i<m; i++) goodi[good[i]-'a'] = 1; for (j=0; j<n; j++) { scanf("%s", q); ql = strlen(q); if (star && ql < sl-1) flag = 0; else if (!star && ql!=sl) flag=0; else { pos1=0; flag=1; while (s[pos1] != '*' && pos1 <sl) { if (s[pos1] == '?') { if (goodi[q[pos1]-'a'] == 0) flag=0; } else if (s[pos1] != q[pos1]) flag=0; pos1++; } pos2=sl-1; ql2=ql-1; while (s[pos2] != '*' && pos2 >=0) { if (s[pos2] == '?') { if (goodi[q[ql2]-'a'] == 0) flag=0; } else if (s[pos2] != q[ql2]) flag=0; pos2--; ql2--; } if (s[pos1]=='*' && pos1<=ql2) { for (i=pos1; i<=ql2; i++) if (goodi[q[i]-'a'] == 1) flag=0; } } if (flag) printf("YES\n"); else printf("NO\n"); } return 0; }
It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one..There is a glob pattern in the statements (a string consisting of lowercase English letters, characters "?" and "*"). It is known that character "*" occurs no more than once in the pattern.Also, n query strings are given, it is required to determine for each of them if the pattern matches it or not.Everything seemed easy to Petya, but then he discovered that the special pattern characters differ from their usual meaning.A pattern matches a string if it is possible to replace each character "?" with one good lowercase English letter, and the character "*" (if there is one) with any, including empty, string of bad lowercase English letters, so that the resulting string is the same as the given string.The good letters are given to Petya. All the others are bad.
Print n lines: in the i-th of them print "YES" if the pattern matches the i-th query string, and "NO" otherwise. You can choose the case (lower or upper) for each letter arbitrary.
C
c6633581d7424d670eaa0f8a5c8cc366
98ef4bb8c34dfaf41faaa51a5681d676
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "strings" ]
1500906900
["ab\na?a\n2\naaa\naab", "abc\na?a?a*\n4\nabacaba\nabaca\napapa\naaaaax"]
NoteIn the first example we can replace "?" with good letters "a" and "b", so we can see that the answer for the first query is "YES", and the answer for the second query is "NO", because we can't match the third letter.Explanation of the second example. The first query: "NO", because character "*" can be replaced with a string of bad letters only, but the only way to match the query string is to replace it with the string "ba", in which both letters are good. The second query: "YES", because characters "?" can be replaced with corresponding good letters, and character "*" can be replaced with empty string, and the strings will coincide. The third query: "NO", because characters "?" can't be replaced with bad letters. The fourth query: "YES", because characters "?" can be replaced with good letters "a", and character "*" can be replaced with a string of bad letters "x".
PASSED
1,600
standard input
2 seconds
The first line contains a string with length from 1 to 26 consisting of distinct lowercase English letters. These letters are good letters, all the others are bad. The second line contains the patternΒ β€” a string s of lowercase English letters, characters "?" and "*" (1 ≀ |s| ≀ 105). It is guaranteed that character "*" occurs in s no more than once. The third line contains integer n (1 ≀ n ≀ 105)Β β€” the number of query strings. n lines follow, each of them contains single non-empty string consisting of lowercase English lettersΒ β€” a query string. It is guaranteed that the total length of all query strings is not greater than 105.
["YES\nNO", "NO\nYES\nNO\nYES"]
#include<stdio.h> char GoodLetters[30], Pattern[1000000], Query[1000000]; int good(char a) { int i; for (i = 0; GoodLetters[i] != '\0'; i++) { if (GoodLetters[i] == a) return 1; } return 0; } int l(char *A) { int i; for (i = 0; A[i] != '\0'; i++) ; return i; } int ch(char Q, char P) { if (P == '?') return good(Q); return P == Q; } int StringSame(int p, int q) { int i; for (i = p; i <= q; i++) { if (ch(Query[i], Pattern[i]) == 0) return 0; } return 1; } int ReverseSame(int StarIndex) { int Qi,Pi, Qn, Pn; Qn = l(Query); Pn = l(Pattern); if (StarIndex == Pn - 1) return 1; for (Qi = Qn - 1, Pi = Pn - 1; Pi > StarIndex; Qi--, Pi--) { if (ch(Query[Qi], Pattern[Pi]) == 0) return 0; } return 1; } int xin() { int i; for (i = 0; Pattern[i] != '\0'; i++) { if (Pattern[i] == '*') return i; } return -1; } int main(void) { int n, i, j, Qn,Pn,StarIndex; scanf("%s", GoodLetters); scanf("%s", Pattern); scanf("%d", &n); StarIndex = xin(); Pn = l(Pattern); for (i = 0; i < n; i++) { scanf("%s", Query); Qn = l(Query); if (StarIndex == -1) { if (Pn != Qn) { printf("NO\n"); continue; } for (j = 0; Pattern[j] != '\0'; j++) { if (ch(Query[j], Pattern[j]) == 0) { printf("NO\n"); break; } } if (Pattern[j] == '\0') printf("YES\n"); } else { if (Pn-1 > Qn) { printf("NO\n"); continue; } if (StringSame(0, StarIndex - 1) && ReverseSame(StarIndex)) { for (j = StarIndex; j < Qn - (Pn - StarIndex)+1; j++) { if (good(Query[j]) == 1) { printf("NO\n"); break; } } if (j == Qn - (Pn - StarIndex)+1) printf("YES\n"); } else printf("NO\n"); } } return 0; }
User ainta has a permutation p1, p2, ..., pn. As the New Year is coming, he wants to make his permutation as pretty as possible.Permutation a1, a2, ..., an is prettier than permutation b1, b2, ..., bn, if and only if there exists an integer k (1 ≀ k ≀ n) where a1 = b1, a2 = b2, ..., ak - 1 = bk - 1 and ak &lt; bk all holds.As known, permutation p is so sensitive that it could be only modified by swapping two distinct elements. But swapping two elements is harder than you think. Given an n × n binary matrix A, user ainta can swap the values of pi and pj (1 ≀ i, j ≀ n, i ≠ j) if and only if Ai, j = 1.Given the permutation p and the matrix A, user ainta wants to know the prettiest permutation that he can obtain.
In the first and only line, print n space-separated integers, describing the prettiest permutation that can be obtained.
C
a67ea891cd6084ceeaace8894cf18e60
17e619b9d6131c90b22070d414375690
GNU C
standard output
256 megabytes
train_002.jsonl
[ "greedy", "graphs", "math", "dsu", "sortings", "dfs and similar" ]
1419951600
["7\n5 2 4 3 6 7 1\n0001001\n0000000\n0000010\n1000001\n0000000\n0010000\n1001000", "5\n4 2 1 5 3\n00100\n00011\n10010\n01101\n01010"]
NoteIn the first sample, the swap needed to obtain the prettiest permutation is: (p1, p7).In the second sample, the swaps needed to obtain the prettiest permutation is (p1, p3), (p4, p5), (p3, p4). A permutation p is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. The i-th element of the permutation p is denoted as pi. The size of the permutation p is denoted as n.
PASSED
1,600
standard input
2 seconds
The first line contains an integer n (1 ≀ n ≀ 300) β€” the size of the permutation p. The second line contains n space-separated integers p1, p2, ..., pn β€” the permutation p that user ainta has. Each integer between 1 and n occurs exactly once in the given permutation. Next n lines describe the matrix A. The i-th line contains n characters '0' or '1' and describes the i-th row of A. The j-th character of the i-th line Ai, j is the element on the intersection of the i-th row and the j-th column of A. It is guaranteed that, for all integers i, j where 1 ≀ i &lt; j ≀ n, Ai, j = Aj, i holds. Also, for all integers i where 1 ≀ i ≀ n, Ai, i = 0 holds.
["1 2 4 3 6 7 5", "1 2 3 4 5"]
#include<stdio.h> int ara[300]; char mat[300][301]; int col[300]; int tempara[300]; int idxara[300]; int start; int end; void Quick_sort(int *ara,int ini_indx,int fin_indx) { if(ini_indx>fin_indx) return; int l1=ini_indx-1,l,tmp; for(l=ini_indx;l<fin_indx;l++) { if(ara[l]<ara[fin_indx]){ l1++; tmp=ara[l]; ara[l]=ara[l1]; ara[l1]=tmp; } } l1++; tmp=ara[l]; ara[l]=ara[l1]; ara[l1]=tmp; Quick_sort(ara,ini_indx,l1-1); Quick_sort(ara,l1+1,fin_indx); } void dfs(int root,int n) { int l,tmp; col[root]=1; idxara[end]=root; tempara[end]=ara[root]; end++; for(l=0;l<n;l++) { if(mat[root][l]=='1' && col[l]==0){ dfs(l,n); } } } int main() { int n; int l,l1; while(1==scanf("%d",&n)) { for(l=0;l<n;scanf("%d",&ara[l]),col[l]=0,l++); for(l=0;l<n;scanf("%s",mat[l]),l++); for(l=0,start=0,end=0;start<n;l++){ if(!col[l]) dfs(l,n); Quick_sort(tempara,start,end-1); Quick_sort(idxara,start,end-1); for(l1=start;l1<end;ara[idxara[l1]]=tempara[l1],l1++); start=end; } for(l=0;l<n;l++) printf("%d ",ara[l]); putchar('\n'); } return 0; }
User ainta has a permutation p1, p2, ..., pn. As the New Year is coming, he wants to make his permutation as pretty as possible.Permutation a1, a2, ..., an is prettier than permutation b1, b2, ..., bn, if and only if there exists an integer k (1 ≀ k ≀ n) where a1 = b1, a2 = b2, ..., ak - 1 = bk - 1 and ak &lt; bk all holds.As known, permutation p is so sensitive that it could be only modified by swapping two distinct elements. But swapping two elements is harder than you think. Given an n × n binary matrix A, user ainta can swap the values of pi and pj (1 ≀ i, j ≀ n, i ≠ j) if and only if Ai, j = 1.Given the permutation p and the matrix A, user ainta wants to know the prettiest permutation that he can obtain.
In the first and only line, print n space-separated integers, describing the prettiest permutation that can be obtained.
C
a67ea891cd6084ceeaace8894cf18e60
582fb1f20efac44b57cf14cd0b607a97
GNU C
standard output
256 megabytes
train_002.jsonl
[ "greedy", "graphs", "math", "dsu", "sortings", "dfs and similar" ]
1419951600
["7\n5 2 4 3 6 7 1\n0001001\n0000000\n0000010\n1000001\n0000000\n0010000\n1001000", "5\n4 2 1 5 3\n00100\n00011\n10010\n01101\n01010"]
NoteIn the first sample, the swap needed to obtain the prettiest permutation is: (p1, p7).In the second sample, the swaps needed to obtain the prettiest permutation is (p1, p3), (p4, p5), (p3, p4). A permutation p is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. The i-th element of the permutation p is denoted as pi. The size of the permutation p is denoted as n.
PASSED
1,600
standard input
2 seconds
The first line contains an integer n (1 ≀ n ≀ 300) β€” the size of the permutation p. The second line contains n space-separated integers p1, p2, ..., pn β€” the permutation p that user ainta has. Each integer between 1 and n occurs exactly once in the given permutation. Next n lines describe the matrix A. The i-th line contains n characters '0' or '1' and describes the i-th row of A. The j-th character of the i-th line Ai, j is the element on the intersection of the i-th row and the j-th column of A. It is guaranteed that, for all integers i, j where 1 ≀ i &lt; j ≀ n, Ai, j = Aj, i holds. Also, for all integers i where 1 ≀ i ≀ n, Ai, i = 0 holds.
["1 2 4 3 6 7 5", "1 2 3 4 5"]
#include<stdio.h> #define SZ 302 char mat[SZ][SZ]; int a[SZ]; int vis[SZ]; int route[SZ],sz; int n; int fixed[SZ]; void dfs(int v,int dest) { vis[v]=1; int i; for(i=1;i<=n;i++) { if(mat[v][i]=='1' && !vis[i]) { route[sz++]=i; if(i==dest) { vis[i]=1; return;//found! } dfs(i,dest); sz--; } } } int path(int dest,int src) { // printf("finding path from %d to %d\n",src,dest); memset(vis,0,sizeof(vis)); sz=0; dfs(src,dest); // printf("path found=%d\n",vis[dest]); return vis[dest]; } int next(int s) { int i; for(i=s+1;i<=n;i++) { if(!fixed[i])return i; } return -1; } int getel(int pos) { int i; for(i=1;i<=n;i++) if(a[i]==pos)return i; } int main() { scanf("%d",&n); //int a[n+1]; int i,j,k,from,z,c; for(i=0;i<n;i++) { scanf("%d",&j); a[j]=i+1; } //int mat[n][n]; for(i=1;i<=n;i++) //scanf("%s",mat[i]); for(j=1;j<=n;j++) scanf(" %c ",&mat[i][j]); /* for(i=1;i<=n;i++) { for(j=1;j<=n;j++) printf("%c",mat[i][j]); puts(""); }*/ int ans[SZ]; c=0; i=0; int tp; for(z=1;z<=n;z++)//fixing for position z { // printf("FOR POS %d\n",z); i=next(i); // printf("next = %d\n",i); if(i==-1) { i=getel(z); ans[z]=i; fixed[i]=1; i=0; continue; } j=a[i];//locate pos of i if(j==z) { ans[z]=i; fixed[i]=1; i=0; continue; } if(path(z,j)) { //perform swaps from=j; //printf("swap starts from %d\n",from); for(k=0;k<sz;k++) { //printf("swapping %d and %d\n",from,route[k]); a[getel(from)]=route[k]; a[getel(route[k])]=from;//to from=route[k]; } ans[z]=i; fixed[i]=1; i=0;//restart //printf("new locations \n"); //for(k=1;k<=n;k++) //{ // printf("%d=%d\n",k,a[k]); //} } else { z--; } } for(i=1;i<=n;i++)printf("%d ",ans[i]); return 0; }
User ainta has a permutation p1, p2, ..., pn. As the New Year is coming, he wants to make his permutation as pretty as possible.Permutation a1, a2, ..., an is prettier than permutation b1, b2, ..., bn, if and only if there exists an integer k (1 ≀ k ≀ n) where a1 = b1, a2 = b2, ..., ak - 1 = bk - 1 and ak &lt; bk all holds.As known, permutation p is so sensitive that it could be only modified by swapping two distinct elements. But swapping two elements is harder than you think. Given an n × n binary matrix A, user ainta can swap the values of pi and pj (1 ≀ i, j ≀ n, i ≠ j) if and only if Ai, j = 1.Given the permutation p and the matrix A, user ainta wants to know the prettiest permutation that he can obtain.
In the first and only line, print n space-separated integers, describing the prettiest permutation that can be obtained.
C
a67ea891cd6084ceeaace8894cf18e60
260551192803f440b1486252dc89b495
GNU C
standard output
256 megabytes
train_002.jsonl
[ "greedy", "graphs", "math", "dsu", "sortings", "dfs and similar" ]
1419951600
["7\n5 2 4 3 6 7 1\n0001001\n0000000\n0000010\n1000001\n0000000\n0010000\n1001000", "5\n4 2 1 5 3\n00100\n00011\n10010\n01101\n01010"]
NoteIn the first sample, the swap needed to obtain the prettiest permutation is: (p1, p7).In the second sample, the swaps needed to obtain the prettiest permutation is (p1, p3), (p4, p5), (p3, p4). A permutation p is a sequence of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. The i-th element of the permutation p is denoted as pi. The size of the permutation p is denoted as n.
PASSED
1,600
standard input
2 seconds
The first line contains an integer n (1 ≀ n ≀ 300) β€” the size of the permutation p. The second line contains n space-separated integers p1, p2, ..., pn β€” the permutation p that user ainta has. Each integer between 1 and n occurs exactly once in the given permutation. Next n lines describe the matrix A. The i-th line contains n characters '0' or '1' and describes the i-th row of A. The j-th character of the i-th line Ai, j is the element on the intersection of the i-th row and the j-th column of A. It is guaranteed that, for all integers i, j where 1 ≀ i &lt; j ≀ n, Ai, j = Aj, i holds. Also, for all integers i where 1 ≀ i ≀ n, Ai, i = 0 holds.
["1 2 4 3 6 7 5", "1 2 3 4 5"]
#include<stdio.h> #include<string.h> int main(){ int n, a[307]={0}; char b[307][307]={0}; int i, j, k, h, temp, t, yes; while( scanf("%d", &n) != EOF){ getchar(); memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); for(i = 1; i <= n; i ++){ scanf("%d",&a[i]); } getchar(); for(i = 1; i <= n; i ++){ for(j = 1; j <= n; j ++){ scanf("%c",&b[i][j]); if(j == n) getchar(); } } for(h = 1 ; h <= n; h ++){ yes = 1; for(i = 1; i <= n; i ++){ for(j = 1; j <= n; j ++){ if(b[i][j]=='1') for( k = 1; k <=n; k ++){ if(b[i][j]=='1'&&b[j][k]=='1'&&b[i][k]!='1'&&i!=k) { b[i][k]='1'; b[k][i]='1'; yes = 0; } } else continue; } } if(yes) break; } while(1){ yes = 1; for(i = 1; i <= n; i ++){ temp = i; for(j = i + 1; j <= n; j ++){ if(b[i][j] == '1' && a[j] < a[temp]) temp = j; } if(temp != i) { t = a[temp]; a[temp] = a[i]; a[i] = t; yes = 0; } } if(yes) break; } for(i = 1; i <= n ; i ++ ){ printf("%d",a[i]); if(i != n) printf(" "); else printf("\n"); } } return 0; }
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $$$n - 2$$$ intermediate planets. Formally: we number all the planets from $$$1$$$ to $$$n$$$. $$$1$$$ is Earth, $$$n$$$ is Mars. Natasha will make exactly $$$n$$$ flights: $$$1 \to 2 \to \ldots n \to 1$$$.Flight from $$$x$$$ to $$$y$$$ consists of two phases: take-off from planet $$$x$$$ and landing to planet $$$y$$$. This way, the overall itinerary of the trip will be: the $$$1$$$-st planet $$$\to$$$ take-off from the $$$1$$$-st planet $$$\to$$$ landing to the $$$2$$$-nd planet $$$\to$$$ $$$2$$$-nd planet $$$\to$$$ take-off from the $$$2$$$-nd planet $$$\to$$$ $$$\ldots$$$ $$$\to$$$ landing to the $$$n$$$-th planet $$$\to$$$ the $$$n$$$-th planet $$$\to$$$ take-off from the $$$n$$$-th planet $$$\to$$$ landing to the $$$1$$$-st planet $$$\to$$$ the $$$1$$$-st planet.The mass of the rocket together with all the useful cargo (but without fuel) is $$$m$$$ tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that $$$1$$$ ton of fuel can lift off $$$a_i$$$ tons of rocket from the $$$i$$$-th planet or to land $$$b_i$$$ tons of rocket onto the $$$i$$$-th planet. For example, if the weight of rocket is $$$9$$$ tons, weight of fuel is $$$3$$$ tons and take-off coefficient is $$$8$$$ ($$$a_i = 8$$$), then $$$1.5$$$ tons of fuel will be burnt (since $$$1.5 \cdot 8 = 9 + 3$$$). The new weight of fuel after take-off will be $$$1.5$$$ tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well.Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly.
If Natasha can fly to Mars through $$$(n - 2)$$$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $$$-1$$$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. Formally, let your answer be $$$p$$$, and the jury's answer be $$$q$$$. Your answer is considered correct if $$$\frac{|p - q|}{\max{(1, |q|)}} \le 10^{-6}$$$.
C
d9bd63e03bf51ed87ba73cd15e8ce58d
a4c0cc07e591539070533a9282b6e52a
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "math" ]
1532617500
["2\n12\n11 8\n7 5", "3\n1\n1 4 1\n2 5 3", "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3"]
NoteLet's consider the first example.Initially, the mass of a rocket with fuel is $$$22$$$ tons. At take-off from Earth one ton of fuel can lift off $$$11$$$ tons of cargo, so to lift off $$$22$$$ tons you need to burn $$$2$$$ tons of fuel. Remaining weight of the rocket with fuel is $$$20$$$ tons. During landing on Mars, one ton of fuel can land $$$5$$$ tons of cargo, so for landing $$$20$$$ tons you will need to burn $$$4$$$ tons of fuel. There will be $$$16$$$ tons of the rocket with fuel remaining. While taking off from Mars, one ton of fuel can raise $$$8$$$ tons of cargo, so to lift off $$$16$$$ tons you will need to burn $$$2$$$ tons of fuel. There will be $$$14$$$ tons of rocket with fuel after that. During landing on Earth, one ton of fuel can land $$$7$$$ tons of cargo, so for landing $$$14$$$ tons you will need to burn $$$2$$$ tons of fuel. Remaining weight is $$$12$$$ tons, that is, a rocket without any fuel.In the second case, the rocket will not be able even to take off from Earth.
PASSED
1,500
standard input
1 second
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$)Β β€” number of planets. The second line contains the only integer $$$m$$$ ($$$1 \le m \le 1000$$$)Β β€” weight of the payload. The third line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$), where $$$a_i$$$ is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$), where $$$b_i$$$ is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel.
["10.0000000000", "-1", "85.4800000000"]
#include<stdio.h> int main(){ int n,m; scanf("%d",&n); scanf("%d",&m); int a[n],b[n],j,k; for(int i=0;i<n;i++){ scanf("%d",&a[i]); } for(int i=0;i<n;i++){ scanf("%d",&b[i]); } int c[2*n]; c[0]=a[0]; c[2*n-1]=b[0]; j=1; k=1; while(j<(2*n-1)){ c[j]=a[k]; c[j+1]=b[k]; k++; j=j+2; } float x,y=0.0; for(j=0;j<2*n;j++){ if(c[j]<=1){ y=-1; break; } x=(m+y)/(c[j]-1); y=y+x; } printf("%f",y); return 0; }
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $$$n - 2$$$ intermediate planets. Formally: we number all the planets from $$$1$$$ to $$$n$$$. $$$1$$$ is Earth, $$$n$$$ is Mars. Natasha will make exactly $$$n$$$ flights: $$$1 \to 2 \to \ldots n \to 1$$$.Flight from $$$x$$$ to $$$y$$$ consists of two phases: take-off from planet $$$x$$$ and landing to planet $$$y$$$. This way, the overall itinerary of the trip will be: the $$$1$$$-st planet $$$\to$$$ take-off from the $$$1$$$-st planet $$$\to$$$ landing to the $$$2$$$-nd planet $$$\to$$$ $$$2$$$-nd planet $$$\to$$$ take-off from the $$$2$$$-nd planet $$$\to$$$ $$$\ldots$$$ $$$\to$$$ landing to the $$$n$$$-th planet $$$\to$$$ the $$$n$$$-th planet $$$\to$$$ take-off from the $$$n$$$-th planet $$$\to$$$ landing to the $$$1$$$-st planet $$$\to$$$ the $$$1$$$-st planet.The mass of the rocket together with all the useful cargo (but without fuel) is $$$m$$$ tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that $$$1$$$ ton of fuel can lift off $$$a_i$$$ tons of rocket from the $$$i$$$-th planet or to land $$$b_i$$$ tons of rocket onto the $$$i$$$-th planet. For example, if the weight of rocket is $$$9$$$ tons, weight of fuel is $$$3$$$ tons and take-off coefficient is $$$8$$$ ($$$a_i = 8$$$), then $$$1.5$$$ tons of fuel will be burnt (since $$$1.5 \cdot 8 = 9 + 3$$$). The new weight of fuel after take-off will be $$$1.5$$$ tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well.Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly.
If Natasha can fly to Mars through $$$(n - 2)$$$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $$$-1$$$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. Formally, let your answer be $$$p$$$, and the jury's answer be $$$q$$$. Your answer is considered correct if $$$\frac{|p - q|}{\max{(1, |q|)}} \le 10^{-6}$$$.
C
d9bd63e03bf51ed87ba73cd15e8ce58d
33a169f7086e56db438ded18e05ae9b4
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "math" ]
1532617500
["2\n12\n11 8\n7 5", "3\n1\n1 4 1\n2 5 3", "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3"]
NoteLet's consider the first example.Initially, the mass of a rocket with fuel is $$$22$$$ tons. At take-off from Earth one ton of fuel can lift off $$$11$$$ tons of cargo, so to lift off $$$22$$$ tons you need to burn $$$2$$$ tons of fuel. Remaining weight of the rocket with fuel is $$$20$$$ tons. During landing on Mars, one ton of fuel can land $$$5$$$ tons of cargo, so for landing $$$20$$$ tons you will need to burn $$$4$$$ tons of fuel. There will be $$$16$$$ tons of the rocket with fuel remaining. While taking off from Mars, one ton of fuel can raise $$$8$$$ tons of cargo, so to lift off $$$16$$$ tons you will need to burn $$$2$$$ tons of fuel. There will be $$$14$$$ tons of rocket with fuel after that. During landing on Earth, one ton of fuel can land $$$7$$$ tons of cargo, so for landing $$$14$$$ tons you will need to burn $$$2$$$ tons of fuel. Remaining weight is $$$12$$$ tons, that is, a rocket without any fuel.In the second case, the rocket will not be able even to take off from Earth.
PASSED
1,500
standard input
1 second
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$)Β β€” number of planets. The second line contains the only integer $$$m$$$ ($$$1 \le m \le 1000$$$)Β β€” weight of the payload. The third line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$), where $$$a_i$$$ is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$), where $$$b_i$$$ is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel.
["10.0000000000", "-1", "85.4800000000"]
#include <stdio.h> int main () { int n, m, i; double c = 1.0, x; scanf ("%d%d", &n, &m); for (i = 0; i < n * 2; i++) { scanf ("%lf", &x); c *= 1 - 1 / x; } printf ("%.10lf", c > 0 ? m / c - m : -1); return 0; }
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $$$n - 2$$$ intermediate planets. Formally: we number all the planets from $$$1$$$ to $$$n$$$. $$$1$$$ is Earth, $$$n$$$ is Mars. Natasha will make exactly $$$n$$$ flights: $$$1 \to 2 \to \ldots n \to 1$$$.Flight from $$$x$$$ to $$$y$$$ consists of two phases: take-off from planet $$$x$$$ and landing to planet $$$y$$$. This way, the overall itinerary of the trip will be: the $$$1$$$-st planet $$$\to$$$ take-off from the $$$1$$$-st planet $$$\to$$$ landing to the $$$2$$$-nd planet $$$\to$$$ $$$2$$$-nd planet $$$\to$$$ take-off from the $$$2$$$-nd planet $$$\to$$$ $$$\ldots$$$ $$$\to$$$ landing to the $$$n$$$-th planet $$$\to$$$ the $$$n$$$-th planet $$$\to$$$ take-off from the $$$n$$$-th planet $$$\to$$$ landing to the $$$1$$$-st planet $$$\to$$$ the $$$1$$$-st planet.The mass of the rocket together with all the useful cargo (but without fuel) is $$$m$$$ tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that $$$1$$$ ton of fuel can lift off $$$a_i$$$ tons of rocket from the $$$i$$$-th planet or to land $$$b_i$$$ tons of rocket onto the $$$i$$$-th planet. For example, if the weight of rocket is $$$9$$$ tons, weight of fuel is $$$3$$$ tons and take-off coefficient is $$$8$$$ ($$$a_i = 8$$$), then $$$1.5$$$ tons of fuel will be burnt (since $$$1.5 \cdot 8 = 9 + 3$$$). The new weight of fuel after take-off will be $$$1.5$$$ tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well.Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly.
If Natasha can fly to Mars through $$$(n - 2)$$$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $$$-1$$$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. Formally, let your answer be $$$p$$$, and the jury's answer be $$$q$$$. Your answer is considered correct if $$$\frac{|p - q|}{\max{(1, |q|)}} \le 10^{-6}$$$.
C
d9bd63e03bf51ed87ba73cd15e8ce58d
b718587a348c0170a29216ed53903242
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "math" ]
1532617500
["2\n12\n11 8\n7 5", "3\n1\n1 4 1\n2 5 3", "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3"]
NoteLet's consider the first example.Initially, the mass of a rocket with fuel is $$$22$$$ tons. At take-off from Earth one ton of fuel can lift off $$$11$$$ tons of cargo, so to lift off $$$22$$$ tons you need to burn $$$2$$$ tons of fuel. Remaining weight of the rocket with fuel is $$$20$$$ tons. During landing on Mars, one ton of fuel can land $$$5$$$ tons of cargo, so for landing $$$20$$$ tons you will need to burn $$$4$$$ tons of fuel. There will be $$$16$$$ tons of the rocket with fuel remaining. While taking off from Mars, one ton of fuel can raise $$$8$$$ tons of cargo, so to lift off $$$16$$$ tons you will need to burn $$$2$$$ tons of fuel. There will be $$$14$$$ tons of rocket with fuel after that. During landing on Earth, one ton of fuel can land $$$7$$$ tons of cargo, so for landing $$$14$$$ tons you will need to burn $$$2$$$ tons of fuel. Remaining weight is $$$12$$$ tons, that is, a rocket without any fuel.In the second case, the rocket will not be able even to take off from Earth.
PASSED
1,500
standard input
1 second
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$)Β β€” number of planets. The second line contains the only integer $$$m$$$ ($$$1 \le m \le 1000$$$)Β β€” weight of the payload. The third line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$), where $$$a_i$$$ is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$), where $$$b_i$$$ is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel.
["10.0000000000", "-1", "85.4800000000"]
#include <stdio.h> #include <stdlib.h> #define MAX 1000 void read(double *vec, int size) { for (int i = 0; i < size; i++) { scanf("%lf", vec + i); } } double calculate(double correlation, double weight) { if (correlation - 1.0 <= 0) return -1; else return weight / (correlation - 1.0); } void doer(double *a, double *b, double weight, int n) { double temp; double total = weight; for (int i = n - 1; i >= 0; i--) { temp = calculate(b[i], total); if (temp == -1) { printf("-1\n"); return; } total += temp; temp = calculate(a[i], total); if (temp == -1) { printf("-1\n"); return; } total += temp; } printf("%.6lf\n", total - weight); } int main() { int n; double m; double a[MAX], b[MAX]; scanf("%d %lf", &n, &m); read(a, n); read(b, n); doer(a, b, m, n); return 0; }
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $$$n - 2$$$ intermediate planets. Formally: we number all the planets from $$$1$$$ to $$$n$$$. $$$1$$$ is Earth, $$$n$$$ is Mars. Natasha will make exactly $$$n$$$ flights: $$$1 \to 2 \to \ldots n \to 1$$$.Flight from $$$x$$$ to $$$y$$$ consists of two phases: take-off from planet $$$x$$$ and landing to planet $$$y$$$. This way, the overall itinerary of the trip will be: the $$$1$$$-st planet $$$\to$$$ take-off from the $$$1$$$-st planet $$$\to$$$ landing to the $$$2$$$-nd planet $$$\to$$$ $$$2$$$-nd planet $$$\to$$$ take-off from the $$$2$$$-nd planet $$$\to$$$ $$$\ldots$$$ $$$\to$$$ landing to the $$$n$$$-th planet $$$\to$$$ the $$$n$$$-th planet $$$\to$$$ take-off from the $$$n$$$-th planet $$$\to$$$ landing to the $$$1$$$-st planet $$$\to$$$ the $$$1$$$-st planet.The mass of the rocket together with all the useful cargo (but without fuel) is $$$m$$$ tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that $$$1$$$ ton of fuel can lift off $$$a_i$$$ tons of rocket from the $$$i$$$-th planet or to land $$$b_i$$$ tons of rocket onto the $$$i$$$-th planet. For example, if the weight of rocket is $$$9$$$ tons, weight of fuel is $$$3$$$ tons and take-off coefficient is $$$8$$$ ($$$a_i = 8$$$), then $$$1.5$$$ tons of fuel will be burnt (since $$$1.5 \cdot 8 = 9 + 3$$$). The new weight of fuel after take-off will be $$$1.5$$$ tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well.Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly.
If Natasha can fly to Mars through $$$(n - 2)$$$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $$$-1$$$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. Formally, let your answer be $$$p$$$, and the jury's answer be $$$q$$$. Your answer is considered correct if $$$\frac{|p - q|}{\max{(1, |q|)}} \le 10^{-6}$$$.
C
d9bd63e03bf51ed87ba73cd15e8ce58d
a981ce263bbde7082530252f06d633da
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "math" ]
1532617500
["2\n12\n11 8\n7 5", "3\n1\n1 4 1\n2 5 3", "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3"]
NoteLet's consider the first example.Initially, the mass of a rocket with fuel is $$$22$$$ tons. At take-off from Earth one ton of fuel can lift off $$$11$$$ tons of cargo, so to lift off $$$22$$$ tons you need to burn $$$2$$$ tons of fuel. Remaining weight of the rocket with fuel is $$$20$$$ tons. During landing on Mars, one ton of fuel can land $$$5$$$ tons of cargo, so for landing $$$20$$$ tons you will need to burn $$$4$$$ tons of fuel. There will be $$$16$$$ tons of the rocket with fuel remaining. While taking off from Mars, one ton of fuel can raise $$$8$$$ tons of cargo, so to lift off $$$16$$$ tons you will need to burn $$$2$$$ tons of fuel. There will be $$$14$$$ tons of rocket with fuel after that. During landing on Earth, one ton of fuel can land $$$7$$$ tons of cargo, so for landing $$$14$$$ tons you will need to burn $$$2$$$ tons of fuel. Remaining weight is $$$12$$$ tons, that is, a rocket without any fuel.In the second case, the rocket will not be able even to take off from Earth.
PASSED
1,500
standard input
1 second
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$)Β β€” number of planets. The second line contains the only integer $$$m$$$ ($$$1 \le m \le 1000$$$)Β β€” weight of the payload. The third line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$), where $$$a_i$$$ is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$), where $$$b_i$$$ is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel.
["10.0000000000", "-1", "85.4800000000"]
#include <stdio.h> int main() { int n, m, i; double c = 1.0, x; scanf("%d%d", &n, &m); for (i = 0; i < 2 * n; i++) { scanf("%lf", &x); c = c * (1 - 1 / x); } float w = m / c - m; if (c>0) printf("%.10lf",w); else printf("-1"); }
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $$$n - 2$$$ intermediate planets. Formally: we number all the planets from $$$1$$$ to $$$n$$$. $$$1$$$ is Earth, $$$n$$$ is Mars. Natasha will make exactly $$$n$$$ flights: $$$1 \to 2 \to \ldots n \to 1$$$.Flight from $$$x$$$ to $$$y$$$ consists of two phases: take-off from planet $$$x$$$ and landing to planet $$$y$$$. This way, the overall itinerary of the trip will be: the $$$1$$$-st planet $$$\to$$$ take-off from the $$$1$$$-st planet $$$\to$$$ landing to the $$$2$$$-nd planet $$$\to$$$ $$$2$$$-nd planet $$$\to$$$ take-off from the $$$2$$$-nd planet $$$\to$$$ $$$\ldots$$$ $$$\to$$$ landing to the $$$n$$$-th planet $$$\to$$$ the $$$n$$$-th planet $$$\to$$$ take-off from the $$$n$$$-th planet $$$\to$$$ landing to the $$$1$$$-st planet $$$\to$$$ the $$$1$$$-st planet.The mass of the rocket together with all the useful cargo (but without fuel) is $$$m$$$ tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that $$$1$$$ ton of fuel can lift off $$$a_i$$$ tons of rocket from the $$$i$$$-th planet or to land $$$b_i$$$ tons of rocket onto the $$$i$$$-th planet. For example, if the weight of rocket is $$$9$$$ tons, weight of fuel is $$$3$$$ tons and take-off coefficient is $$$8$$$ ($$$a_i = 8$$$), then $$$1.5$$$ tons of fuel will be burnt (since $$$1.5 \cdot 8 = 9 + 3$$$). The new weight of fuel after take-off will be $$$1.5$$$ tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well.Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly.
If Natasha can fly to Mars through $$$(n - 2)$$$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $$$-1$$$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. Formally, let your answer be $$$p$$$, and the jury's answer be $$$q$$$. Your answer is considered correct if $$$\frac{|p - q|}{\max{(1, |q|)}} \le 10^{-6}$$$.
C
d9bd63e03bf51ed87ba73cd15e8ce58d
8dafe771c551e02e5df8fe50cecc0fdc
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "math" ]
1532617500
["2\n12\n11 8\n7 5", "3\n1\n1 4 1\n2 5 3", "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3"]
NoteLet's consider the first example.Initially, the mass of a rocket with fuel is $$$22$$$ tons. At take-off from Earth one ton of fuel can lift off $$$11$$$ tons of cargo, so to lift off $$$22$$$ tons you need to burn $$$2$$$ tons of fuel. Remaining weight of the rocket with fuel is $$$20$$$ tons. During landing on Mars, one ton of fuel can land $$$5$$$ tons of cargo, so for landing $$$20$$$ tons you will need to burn $$$4$$$ tons of fuel. There will be $$$16$$$ tons of the rocket with fuel remaining. While taking off from Mars, one ton of fuel can raise $$$8$$$ tons of cargo, so to lift off $$$16$$$ tons you will need to burn $$$2$$$ tons of fuel. There will be $$$14$$$ tons of rocket with fuel after that. During landing on Earth, one ton of fuel can land $$$7$$$ tons of cargo, so for landing $$$14$$$ tons you will need to burn $$$2$$$ tons of fuel. Remaining weight is $$$12$$$ tons, that is, a rocket without any fuel.In the second case, the rocket will not be able even to take off from Earth.
PASSED
1,500
standard input
1 second
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$)Β β€” number of planets. The second line contains the only integer $$$m$$$ ($$$1 \le m \le 1000$$$)Β β€” weight of the payload. The third line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$), where $$$a_i$$$ is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$), where $$$b_i$$$ is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel.
["10.0000000000", "-1", "85.4800000000"]
#include<stdio.h> main() { int n, mass; double ans; scanf("%d %d",&n,&mass); int i,a[n],b[n]; for(i=0;i<n;i++)scanf("%d",&a[i]); for(i=0;i<n;i++)scanf("%d",&b[i]); ans=a[0]-1; for(i=1;i<n;i++) { ans=ans-(ans/b[i]); ans=ans-(ans/a[i]); } ans=ans-(ans/b[0]); if(ans==0) { printf("-1"); return 0; } ans=((mass/ans)*a[0])-mass; printf("%lf",ans); }
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $$$n - 2$$$ intermediate planets. Formally: we number all the planets from $$$1$$$ to $$$n$$$. $$$1$$$ is Earth, $$$n$$$ is Mars. Natasha will make exactly $$$n$$$ flights: $$$1 \to 2 \to \ldots n \to 1$$$.Flight from $$$x$$$ to $$$y$$$ consists of two phases: take-off from planet $$$x$$$ and landing to planet $$$y$$$. This way, the overall itinerary of the trip will be: the $$$1$$$-st planet $$$\to$$$ take-off from the $$$1$$$-st planet $$$\to$$$ landing to the $$$2$$$-nd planet $$$\to$$$ $$$2$$$-nd planet $$$\to$$$ take-off from the $$$2$$$-nd planet $$$\to$$$ $$$\ldots$$$ $$$\to$$$ landing to the $$$n$$$-th planet $$$\to$$$ the $$$n$$$-th planet $$$\to$$$ take-off from the $$$n$$$-th planet $$$\to$$$ landing to the $$$1$$$-st planet $$$\to$$$ the $$$1$$$-st planet.The mass of the rocket together with all the useful cargo (but without fuel) is $$$m$$$ tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that $$$1$$$ ton of fuel can lift off $$$a_i$$$ tons of rocket from the $$$i$$$-th planet or to land $$$b_i$$$ tons of rocket onto the $$$i$$$-th planet. For example, if the weight of rocket is $$$9$$$ tons, weight of fuel is $$$3$$$ tons and take-off coefficient is $$$8$$$ ($$$a_i = 8$$$), then $$$1.5$$$ tons of fuel will be burnt (since $$$1.5 \cdot 8 = 9 + 3$$$). The new weight of fuel after take-off will be $$$1.5$$$ tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well.Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly.
If Natasha can fly to Mars through $$$(n - 2)$$$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $$$-1$$$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. Formally, let your answer be $$$p$$$, and the jury's answer be $$$q$$$. Your answer is considered correct if $$$\frac{|p - q|}{\max{(1, |q|)}} \le 10^{-6}$$$.
C
d9bd63e03bf51ed87ba73cd15e8ce58d
d535174854bb2c6578bd7cf2a33b1b2d
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "math" ]
1532617500
["2\n12\n11 8\n7 5", "3\n1\n1 4 1\n2 5 3", "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3"]
NoteLet's consider the first example.Initially, the mass of a rocket with fuel is $$$22$$$ tons. At take-off from Earth one ton of fuel can lift off $$$11$$$ tons of cargo, so to lift off $$$22$$$ tons you need to burn $$$2$$$ tons of fuel. Remaining weight of the rocket with fuel is $$$20$$$ tons. During landing on Mars, one ton of fuel can land $$$5$$$ tons of cargo, so for landing $$$20$$$ tons you will need to burn $$$4$$$ tons of fuel. There will be $$$16$$$ tons of the rocket with fuel remaining. While taking off from Mars, one ton of fuel can raise $$$8$$$ tons of cargo, so to lift off $$$16$$$ tons you will need to burn $$$2$$$ tons of fuel. There will be $$$14$$$ tons of rocket with fuel after that. During landing on Earth, one ton of fuel can land $$$7$$$ tons of cargo, so for landing $$$14$$$ tons you will need to burn $$$2$$$ tons of fuel. Remaining weight is $$$12$$$ tons, that is, a rocket without any fuel.In the second case, the rocket will not be able even to take off from Earth.
PASSED
1,500
standard input
1 second
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$)Β β€” number of planets. The second line contains the only integer $$$m$$$ ($$$1 \le m \le 1000$$$)Β β€” weight of the payload. The third line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$), where $$$a_i$$$ is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$), where $$$b_i$$$ is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel.
["10.0000000000", "-1", "85.4800000000"]
#include <stdio.h> int main () { int n, m, i; double c = 1.0, x; scanf ("%d%d", &n, &m); for (i = 0; i < n * 2; i++) { scanf ("%lf", &x); c *= 1 - 1 / x; } printf ("%.10f\n", c > 0 ? m / c - m : -1); return 0; }
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $$$n - 2$$$ intermediate planets. Formally: we number all the planets from $$$1$$$ to $$$n$$$. $$$1$$$ is Earth, $$$n$$$ is Mars. Natasha will make exactly $$$n$$$ flights: $$$1 \to 2 \to \ldots n \to 1$$$.Flight from $$$x$$$ to $$$y$$$ consists of two phases: take-off from planet $$$x$$$ and landing to planet $$$y$$$. This way, the overall itinerary of the trip will be: the $$$1$$$-st planet $$$\to$$$ take-off from the $$$1$$$-st planet $$$\to$$$ landing to the $$$2$$$-nd planet $$$\to$$$ $$$2$$$-nd planet $$$\to$$$ take-off from the $$$2$$$-nd planet $$$\to$$$ $$$\ldots$$$ $$$\to$$$ landing to the $$$n$$$-th planet $$$\to$$$ the $$$n$$$-th planet $$$\to$$$ take-off from the $$$n$$$-th planet $$$\to$$$ landing to the $$$1$$$-st planet $$$\to$$$ the $$$1$$$-st planet.The mass of the rocket together with all the useful cargo (but without fuel) is $$$m$$$ tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that $$$1$$$ ton of fuel can lift off $$$a_i$$$ tons of rocket from the $$$i$$$-th planet or to land $$$b_i$$$ tons of rocket onto the $$$i$$$-th planet. For example, if the weight of rocket is $$$9$$$ tons, weight of fuel is $$$3$$$ tons and take-off coefficient is $$$8$$$ ($$$a_i = 8$$$), then $$$1.5$$$ tons of fuel will be burnt (since $$$1.5 \cdot 8 = 9 + 3$$$). The new weight of fuel after take-off will be $$$1.5$$$ tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well.Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly.
If Natasha can fly to Mars through $$$(n - 2)$$$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $$$-1$$$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. Formally, let your answer be $$$p$$$, and the jury's answer be $$$q$$$. Your answer is considered correct if $$$\frac{|p - q|}{\max{(1, |q|)}} \le 10^{-6}$$$.
C
d9bd63e03bf51ed87ba73cd15e8ce58d
3c03de8e2e46c39d51e44a5e43c65dc4
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "math" ]
1532617500
["2\n12\n11 8\n7 5", "3\n1\n1 4 1\n2 5 3", "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3"]
NoteLet's consider the first example.Initially, the mass of a rocket with fuel is $$$22$$$ tons. At take-off from Earth one ton of fuel can lift off $$$11$$$ tons of cargo, so to lift off $$$22$$$ tons you need to burn $$$2$$$ tons of fuel. Remaining weight of the rocket with fuel is $$$20$$$ tons. During landing on Mars, one ton of fuel can land $$$5$$$ tons of cargo, so for landing $$$20$$$ tons you will need to burn $$$4$$$ tons of fuel. There will be $$$16$$$ tons of the rocket with fuel remaining. While taking off from Mars, one ton of fuel can raise $$$8$$$ tons of cargo, so to lift off $$$16$$$ tons you will need to burn $$$2$$$ tons of fuel. There will be $$$14$$$ tons of rocket with fuel after that. During landing on Earth, one ton of fuel can land $$$7$$$ tons of cargo, so for landing $$$14$$$ tons you will need to burn $$$2$$$ tons of fuel. Remaining weight is $$$12$$$ tons, that is, a rocket without any fuel.In the second case, the rocket will not be able even to take off from Earth.
PASSED
1,500
standard input
1 second
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$)Β β€” number of planets. The second line contains the only integer $$$m$$$ ($$$1 \le m \le 1000$$$)Β β€” weight of the payload. The third line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$), where $$$a_i$$$ is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$), where $$$b_i$$$ is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel.
["10.0000000000", "-1", "85.4800000000"]
#include <stdio.h> int main () { int n, m, i; double c = 1.0, x; scanf ("%d%d", &n, &m); for (i = 0; i < n * 2; i++) { scanf ("%lf", &x); c *= 1 - 1 / x; } printf ("%.10lf", c > 0 ? m / c - m : -1); return 0; }
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $$$n - 2$$$ intermediate planets. Formally: we number all the planets from $$$1$$$ to $$$n$$$. $$$1$$$ is Earth, $$$n$$$ is Mars. Natasha will make exactly $$$n$$$ flights: $$$1 \to 2 \to \ldots n \to 1$$$.Flight from $$$x$$$ to $$$y$$$ consists of two phases: take-off from planet $$$x$$$ and landing to planet $$$y$$$. This way, the overall itinerary of the trip will be: the $$$1$$$-st planet $$$\to$$$ take-off from the $$$1$$$-st planet $$$\to$$$ landing to the $$$2$$$-nd planet $$$\to$$$ $$$2$$$-nd planet $$$\to$$$ take-off from the $$$2$$$-nd planet $$$\to$$$ $$$\ldots$$$ $$$\to$$$ landing to the $$$n$$$-th planet $$$\to$$$ the $$$n$$$-th planet $$$\to$$$ take-off from the $$$n$$$-th planet $$$\to$$$ landing to the $$$1$$$-st planet $$$\to$$$ the $$$1$$$-st planet.The mass of the rocket together with all the useful cargo (but without fuel) is $$$m$$$ tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that $$$1$$$ ton of fuel can lift off $$$a_i$$$ tons of rocket from the $$$i$$$-th planet or to land $$$b_i$$$ tons of rocket onto the $$$i$$$-th planet. For example, if the weight of rocket is $$$9$$$ tons, weight of fuel is $$$3$$$ tons and take-off coefficient is $$$8$$$ ($$$a_i = 8$$$), then $$$1.5$$$ tons of fuel will be burnt (since $$$1.5 \cdot 8 = 9 + 3$$$). The new weight of fuel after take-off will be $$$1.5$$$ tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well.Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly.
If Natasha can fly to Mars through $$$(n - 2)$$$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $$$-1$$$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. Formally, let your answer be $$$p$$$, and the jury's answer be $$$q$$$. Your answer is considered correct if $$$\frac{|p - q|}{\max{(1, |q|)}} \le 10^{-6}$$$.
C
d9bd63e03bf51ed87ba73cd15e8ce58d
b87060b15e52ed0291e2388ad99bddd3
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "math" ]
1532617500
["2\n12\n11 8\n7 5", "3\n1\n1 4 1\n2 5 3", "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3"]
NoteLet's consider the first example.Initially, the mass of a rocket with fuel is $$$22$$$ tons. At take-off from Earth one ton of fuel can lift off $$$11$$$ tons of cargo, so to lift off $$$22$$$ tons you need to burn $$$2$$$ tons of fuel. Remaining weight of the rocket with fuel is $$$20$$$ tons. During landing on Mars, one ton of fuel can land $$$5$$$ tons of cargo, so for landing $$$20$$$ tons you will need to burn $$$4$$$ tons of fuel. There will be $$$16$$$ tons of the rocket with fuel remaining. While taking off from Mars, one ton of fuel can raise $$$8$$$ tons of cargo, so to lift off $$$16$$$ tons you will need to burn $$$2$$$ tons of fuel. There will be $$$14$$$ tons of rocket with fuel after that. During landing on Earth, one ton of fuel can land $$$7$$$ tons of cargo, so for landing $$$14$$$ tons you will need to burn $$$2$$$ tons of fuel. Remaining weight is $$$12$$$ tons, that is, a rocket without any fuel.In the second case, the rocket will not be able even to take off from Earth.
PASSED
1,500
standard input
1 second
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$)Β β€” number of planets. The second line contains the only integer $$$m$$$ ($$$1 \le m \le 1000$$$)Β β€” weight of the payload. The third line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$), where $$$a_i$$$ is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$), where $$$b_i$$$ is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel.
["10.0000000000", "-1", "85.4800000000"]
#include <stdio.h> int main () { int n, m, i; double c = 1.0, x; scanf ("%d%d", &n, &m); for (i = 0; i < n * 2; i++) { scanf ("%lf", &x); c *= 1 - 1 / x; } printf ("%.10lf\n", c > 0 ? m / c - m : -1); return 0; }
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $$$n - 2$$$ intermediate planets. Formally: we number all the planets from $$$1$$$ to $$$n$$$. $$$1$$$ is Earth, $$$n$$$ is Mars. Natasha will make exactly $$$n$$$ flights: $$$1 \to 2 \to \ldots n \to 1$$$.Flight from $$$x$$$ to $$$y$$$ consists of two phases: take-off from planet $$$x$$$ and landing to planet $$$y$$$. This way, the overall itinerary of the trip will be: the $$$1$$$-st planet $$$\to$$$ take-off from the $$$1$$$-st planet $$$\to$$$ landing to the $$$2$$$-nd planet $$$\to$$$ $$$2$$$-nd planet $$$\to$$$ take-off from the $$$2$$$-nd planet $$$\to$$$ $$$\ldots$$$ $$$\to$$$ landing to the $$$n$$$-th planet $$$\to$$$ the $$$n$$$-th planet $$$\to$$$ take-off from the $$$n$$$-th planet $$$\to$$$ landing to the $$$1$$$-st planet $$$\to$$$ the $$$1$$$-st planet.The mass of the rocket together with all the useful cargo (but without fuel) is $$$m$$$ tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that $$$1$$$ ton of fuel can lift off $$$a_i$$$ tons of rocket from the $$$i$$$-th planet or to land $$$b_i$$$ tons of rocket onto the $$$i$$$-th planet. For example, if the weight of rocket is $$$9$$$ tons, weight of fuel is $$$3$$$ tons and take-off coefficient is $$$8$$$ ($$$a_i = 8$$$), then $$$1.5$$$ tons of fuel will be burnt (since $$$1.5 \cdot 8 = 9 + 3$$$). The new weight of fuel after take-off will be $$$1.5$$$ tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well.Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly.
If Natasha can fly to Mars through $$$(n - 2)$$$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $$$-1$$$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. Formally, let your answer be $$$p$$$, and the jury's answer be $$$q$$$. Your answer is considered correct if $$$\frac{|p - q|}{\max{(1, |q|)}} \le 10^{-6}$$$.
C
d9bd63e03bf51ed87ba73cd15e8ce58d
6046eb5449554a6868114016edc20d84
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "math" ]
1532617500
["2\n12\n11 8\n7 5", "3\n1\n1 4 1\n2 5 3", "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3"]
NoteLet's consider the first example.Initially, the mass of a rocket with fuel is $$$22$$$ tons. At take-off from Earth one ton of fuel can lift off $$$11$$$ tons of cargo, so to lift off $$$22$$$ tons you need to burn $$$2$$$ tons of fuel. Remaining weight of the rocket with fuel is $$$20$$$ tons. During landing on Mars, one ton of fuel can land $$$5$$$ tons of cargo, so for landing $$$20$$$ tons you will need to burn $$$4$$$ tons of fuel. There will be $$$16$$$ tons of the rocket with fuel remaining. While taking off from Mars, one ton of fuel can raise $$$8$$$ tons of cargo, so to lift off $$$16$$$ tons you will need to burn $$$2$$$ tons of fuel. There will be $$$14$$$ tons of rocket with fuel after that. During landing on Earth, one ton of fuel can land $$$7$$$ tons of cargo, so for landing $$$14$$$ tons you will need to burn $$$2$$$ tons of fuel. Remaining weight is $$$12$$$ tons, that is, a rocket without any fuel.In the second case, the rocket will not be able even to take off from Earth.
PASSED
1,500
standard input
1 second
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$)Β β€” number of planets. The second line contains the only integer $$$m$$$ ($$$1 \le m \le 1000$$$)Β β€” weight of the payload. The third line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$), where $$$a_i$$$ is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$), where $$$b_i$$$ is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel.
["10.0000000000", "-1", "85.4800000000"]
#include<stdio.h> int main() { int n,m,i; double c=1.0,x; scanf("%d%d",&n,&m); for(i=0;i<2*n;i++){ scanf("%lf",&x); c=c*(1-1/x); } float w=m/c-m; c>0?printf("%.10lf",w):printf("-1"); }
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $$$n - 2$$$ intermediate planets. Formally: we number all the planets from $$$1$$$ to $$$n$$$. $$$1$$$ is Earth, $$$n$$$ is Mars. Natasha will make exactly $$$n$$$ flights: $$$1 \to 2 \to \ldots n \to 1$$$.Flight from $$$x$$$ to $$$y$$$ consists of two phases: take-off from planet $$$x$$$ and landing to planet $$$y$$$. This way, the overall itinerary of the trip will be: the $$$1$$$-st planet $$$\to$$$ take-off from the $$$1$$$-st planet $$$\to$$$ landing to the $$$2$$$-nd planet $$$\to$$$ $$$2$$$-nd planet $$$\to$$$ take-off from the $$$2$$$-nd planet $$$\to$$$ $$$\ldots$$$ $$$\to$$$ landing to the $$$n$$$-th planet $$$\to$$$ the $$$n$$$-th planet $$$\to$$$ take-off from the $$$n$$$-th planet $$$\to$$$ landing to the $$$1$$$-st planet $$$\to$$$ the $$$1$$$-st planet.The mass of the rocket together with all the useful cargo (but without fuel) is $$$m$$$ tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that $$$1$$$ ton of fuel can lift off $$$a_i$$$ tons of rocket from the $$$i$$$-th planet or to land $$$b_i$$$ tons of rocket onto the $$$i$$$-th planet. For example, if the weight of rocket is $$$9$$$ tons, weight of fuel is $$$3$$$ tons and take-off coefficient is $$$8$$$ ($$$a_i = 8$$$), then $$$1.5$$$ tons of fuel will be burnt (since $$$1.5 \cdot 8 = 9 + 3$$$). The new weight of fuel after take-off will be $$$1.5$$$ tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well.Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly.
If Natasha can fly to Mars through $$$(n - 2)$$$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $$$-1$$$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. Formally, let your answer be $$$p$$$, and the jury's answer be $$$q$$$. Your answer is considered correct if $$$\frac{|p - q|}{\max{(1, |q|)}} \le 10^{-6}$$$.
C
d9bd63e03bf51ed87ba73cd15e8ce58d
c4acce5cc11f0c693e90bd0a711af957
GNU C
standard output
256 megabytes
train_002.jsonl
[ "binary search", "math" ]
1532617500
["2\n12\n11 8\n7 5", "3\n1\n1 4 1\n2 5 3", "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3"]
NoteLet's consider the first example.Initially, the mass of a rocket with fuel is $$$22$$$ tons. At take-off from Earth one ton of fuel can lift off $$$11$$$ tons of cargo, so to lift off $$$22$$$ tons you need to burn $$$2$$$ tons of fuel. Remaining weight of the rocket with fuel is $$$20$$$ tons. During landing on Mars, one ton of fuel can land $$$5$$$ tons of cargo, so for landing $$$20$$$ tons you will need to burn $$$4$$$ tons of fuel. There will be $$$16$$$ tons of the rocket with fuel remaining. While taking off from Mars, one ton of fuel can raise $$$8$$$ tons of cargo, so to lift off $$$16$$$ tons you will need to burn $$$2$$$ tons of fuel. There will be $$$14$$$ tons of rocket with fuel after that. During landing on Earth, one ton of fuel can land $$$7$$$ tons of cargo, so for landing $$$14$$$ tons you will need to burn $$$2$$$ tons of fuel. Remaining weight is $$$12$$$ tons, that is, a rocket without any fuel.In the second case, the rocket will not be able even to take off from Earth.
PASSED
1,500
standard input
1 second
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$)Β β€” number of planets. The second line contains the only integer $$$m$$$ ($$$1 \le m \le 1000$$$)Β β€” weight of the payload. The third line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$), where $$$a_i$$$ is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$), where $$$b_i$$$ is the number of tons, which can be landed by one ton of fuel. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel.
["10.0000000000", "-1", "85.4800000000"]
//codechef tutorial multiplication #include<stdio.h> int main() { long long i,j,k,l,c,n,m,mul,sum; double x,y,z,w; scanf("%lld%lld",&n,&m); int a[2][n]; c=0; y=1; for(i=0;i<2;i++) { for(j=0;j<n;j++) { scanf("%d",&a[i][j]); if(a[i][j]==1) c++; } } if(c!=0) printf("-1"); else { for(k=0;k<2;k++) { for(l=0;l<n;l++) { w=(double)(a[k][l])/(double)(a[k][l]-1); y=y*w; } } z=(y-1)*(m); printf("%lf",z); } return 0; }
A sequence $$$a_1, a_2, \dots, a_k$$$ is called an arithmetic progression if for each $$$i$$$ from $$$1$$$ to $$$k$$$ elements satisfy the condition $$$a_i = a_1 + c \cdot (i - 1)$$$ for some fixed $$$c$$$.For example, these five sequences are arithmetic progressions: $$$[5, 7, 9, 11]$$$, $$$[101]$$$, $$$[101, 100, 99]$$$, $$$[13, 97]$$$ and $$$[5, 5, 5, 5, 5]$$$. And these four sequences aren't arithmetic progressions: $$$[3, 1, 2]$$$, $$$[1, 2, 4, 8]$$$, $$$[1, -1, 1, -1]$$$ and $$$[1, 2, 3, 3, 3]$$$.You are given a sequence of integers $$$b_1, b_2, \dots, b_n$$$. Find any index $$$j$$$ ($$$1 \le j \le n$$$), such that if you delete $$$b_j$$$ from the sequence, you can reorder the remaining $$$n-1$$$ elements, so that you will get an arithmetic progression. If there is no such index, output the number -1.
Print such index $$$j$$$ ($$$1 \le j \le n$$$), so that if you delete the $$$j$$$-th element from the sequence, you can reorder the remaining elements, so that you will get an arithmetic progression. If there are multiple solutions, you are allowed to print any of them. If there is no such index, print -1.
C
6946f088e462d12da47419f492ad51ea
ab04ebd8f1081ba7882a23f67c82ac1b
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "math" ]
1560955500
["5\n2 6 8 7 4", "8\n1 2 3 4 5 6 7 8", "4\n1 2 4 8"]
NoteNote to the first example. If you delete the $$$4$$$-th element, you can get the arithmetic progression $$$[2, 4, 6, 8]$$$.Note to the second example. The original sequence is already arithmetic progression, so you can delete $$$1$$$-st or last element and you will get an arithmetical progression again.
PASSED
1,700
standard input
2 seconds
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) β€” length of the sequence $$$b$$$. The second line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$-10^9 \le b_i \le 10^9$$$) β€” elements of the sequence $$$b$$$.
["4", "1", "-1"]
#include<stdio.h> #include<stdlib.h> int cmpfunc (const void * a, const void * b) { return ( *(int*)a - *(int*)b ); } long long find(long long a[],long long n,long long x){ long long i; for(i=0;i<n;i++) { if(a[i]==x) return i+1; } } long long check(long long b[],long long n,long long i){ long long int c[n]; long long int temp=0; for(long long int k=0;k<n;k++){ if(k!=i){ c[temp]=b[k]; temp++; } } long long int cnt=0; long long int d=c[1]-c[0]; for(long long int k=1;k<(n-1);k++){ if((c[k]-c[k-1])==d) cnt++; } return cnt; } int main(){ long long int n,x; scanf("%I64d",&n); long long int a[n]; long long int b[n]; long long int i; for(i=0;i<n;i++){ scanf("%I64d",&a[i]); b[i]=a[i]; } qsort(b,n,sizeof(long long int),cmpfunc); long d; if(n==2 || n==3){ printf("1"); return 0; } d=b[1]-b[0]; for(i=2;i<n;i++){ if((b[i]-b[i-1])!=d) break; } if(i==n) x=find(a,n,b[0]); else if(i==n-1) x=find(a,n,b[n-1]); else { int p,q,r; x=-1; if((p=check(b,n,i)==n-2)) x=find(a,n,b[i]); if((q=check(b,n,i-1)==n-2)) x=find(a,n,b[i-1]); if((r=check(b,n,i-2)==n-2)) x=find(a,n,b[i-2]);} printf("%d",x); }
A sequence $$$a_1, a_2, \dots, a_k$$$ is called an arithmetic progression if for each $$$i$$$ from $$$1$$$ to $$$k$$$ elements satisfy the condition $$$a_i = a_1 + c \cdot (i - 1)$$$ for some fixed $$$c$$$.For example, these five sequences are arithmetic progressions: $$$[5, 7, 9, 11]$$$, $$$[101]$$$, $$$[101, 100, 99]$$$, $$$[13, 97]$$$ and $$$[5, 5, 5, 5, 5]$$$. And these four sequences aren't arithmetic progressions: $$$[3, 1, 2]$$$, $$$[1, 2, 4, 8]$$$, $$$[1, -1, 1, -1]$$$ and $$$[1, 2, 3, 3, 3]$$$.You are given a sequence of integers $$$b_1, b_2, \dots, b_n$$$. Find any index $$$j$$$ ($$$1 \le j \le n$$$), such that if you delete $$$b_j$$$ from the sequence, you can reorder the remaining $$$n-1$$$ elements, so that you will get an arithmetic progression. If there is no such index, output the number -1.
Print such index $$$j$$$ ($$$1 \le j \le n$$$), so that if you delete the $$$j$$$-th element from the sequence, you can reorder the remaining elements, so that you will get an arithmetic progression. If there are multiple solutions, you are allowed to print any of them. If there is no such index, print -1.
C
6946f088e462d12da47419f492ad51ea
847d18274bc000cf8bb5da45fbc1910d
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "math" ]
1560955500
["5\n2 6 8 7 4", "8\n1 2 3 4 5 6 7 8", "4\n1 2 4 8"]
NoteNote to the first example. If you delete the $$$4$$$-th element, you can get the arithmetic progression $$$[2, 4, 6, 8]$$$.Note to the second example. The original sequence is already arithmetic progression, so you can delete $$$1$$$-st or last element and you will get an arithmetical progression again.
PASSED
1,700
standard input
2 seconds
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) β€” length of the sequence $$$b$$$. The second line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$-10^9 \le b_i \le 10^9$$$) β€” elements of the sequence $$$b$$$.
["4", "1", "-1"]
#include<stdio.h> #define MAX 200000 int temp[MAX]; void mergesort(int a[],int indices[],int first,int last) { if(first==last) return; int middle=(first+last)/2; mergesort(a,indices,first,middle); mergesort(a,indices,middle+1,last); int i,j,k; for(i=first,j=first,k=middle+1; i<=last; i++) { if(j==middle+1) temp[i]=indices[k++]; else if(k==last+1) temp[i]=indices[j++]; else if(a[indices[k]]<a[indices[j]]) temp[i]=indices[k++]; else temp[i]=indices[j++]; } for(i=first; i<=last; i++) { indices[i]=temp[i]; } } int main() { int n,i,j; scanf("%d",&n); int a[n],indices[n],nindices[n-1]; for(i=0;i<n;i++) { scanf("%d",&a[i]); indices[i]=i; } mergesort(a,indices,0,n-1); for(i=2;i<n&&a[indices[i]]-a[indices[i-1]]==a[indices[i-1]]-a[indices[i-2]];i++); if(i>=n-1) { printf("%d",indices[n-1]+1); return 0; } for(i=n-3;i>=0&&a[indices[i]]-a[indices[i+1]]==a[indices[i+1]]-a[indices[i+2]];i--); if(i<=0) { printf("%d",indices[0]+1); return 0; } for(i=1;i<n-1&&a[indices[i]]-a[indices[i-1]]==a[indices[i+1]]-a[indices[i]];i++); int skip=i+1; for(i=0,j=0;j<n-1;i++) { if(i==skip) continue; nindices[j++]=indices[i]; } for(i=2;i<n-1&&a[nindices[i]]-a[nindices[i-1]]==a[nindices[i-1]]-a[nindices[i-2]];i++); if(i==n-1) { printf("%d",indices[skip]+1); return 0; } for(i=n-2;i>0&&a[indices[i]]-a[indices[i+1]]==a[indices[i-1]]-a[indices[i]];i--); skip=i-1; for(i=0,j=0;j<n-1;i++) { if(i==skip) continue; nindices[j++]=indices[i]; } for(i=n-4;i>=0&&a[nindices[i]]-a[nindices[i+1]]==a[nindices[i+1]]-a[nindices[i+2]];i--); if(i<0) { printf("%d",indices[skip]+1); return 0; } else { printf("-1"); } return 0; }
A sequence $$$a_1, a_2, \dots, a_k$$$ is called an arithmetic progression if for each $$$i$$$ from $$$1$$$ to $$$k$$$ elements satisfy the condition $$$a_i = a_1 + c \cdot (i - 1)$$$ for some fixed $$$c$$$.For example, these five sequences are arithmetic progressions: $$$[5, 7, 9, 11]$$$, $$$[101]$$$, $$$[101, 100, 99]$$$, $$$[13, 97]$$$ and $$$[5, 5, 5, 5, 5]$$$. And these four sequences aren't arithmetic progressions: $$$[3, 1, 2]$$$, $$$[1, 2, 4, 8]$$$, $$$[1, -1, 1, -1]$$$ and $$$[1, 2, 3, 3, 3]$$$.You are given a sequence of integers $$$b_1, b_2, \dots, b_n$$$. Find any index $$$j$$$ ($$$1 \le j \le n$$$), such that if you delete $$$b_j$$$ from the sequence, you can reorder the remaining $$$n-1$$$ elements, so that you will get an arithmetic progression. If there is no such index, output the number -1.
Print such index $$$j$$$ ($$$1 \le j \le n$$$), so that if you delete the $$$j$$$-th element from the sequence, you can reorder the remaining elements, so that you will get an arithmetic progression. If there are multiple solutions, you are allowed to print any of them. If there is no such index, print -1.
C
6946f088e462d12da47419f492ad51ea
4739ebb2a693bb3d4cfebce43c22baa0
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "math" ]
1560955500
["5\n2 6 8 7 4", "8\n1 2 3 4 5 6 7 8", "4\n1 2 4 8"]
NoteNote to the first example. If you delete the $$$4$$$-th element, you can get the arithmetic progression $$$[2, 4, 6, 8]$$$.Note to the second example. The original sequence is already arithmetic progression, so you can delete $$$1$$$-st or last element and you will get an arithmetical progression again.
PASSED
1,700
standard input
2 seconds
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) β€” length of the sequence $$$b$$$. The second line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$-10^9 \le b_i \le 10^9$$$) β€” elements of the sequence $$$b$$$.
["4", "1", "-1"]
#include<stdio.h> #include<stdlib.h> int cmpfunc (const void * a, const void * b) { return ( *(int*)a - *(int*)b ); } long long find(long long a[],long long n,long long x){ long long i; for(i=0;i<n;i++) { if(a[i]==x) return i+1; } } long long check(long long b[],long long n,long long i){ long long int c[n]; long long int temp=0; for(long long int k=0;k<n;k++){ if(k!=i){ c[temp]=b[k]; temp++; } } long long int cnt=0; long long int d=c[1]-c[0]; for(long long int k=1;k<(n-1);k++){ if((c[k]-c[k-1])==d) cnt++; } return cnt; } int main(){ long long int n,x; scanf("%I64d",&n); long long int a[n]; long long int b[n]; long long int i; for(i=0;i<n;i++){ scanf("%I64d",&a[i]); b[i]=a[i]; } qsort(b,n,sizeof(long long int),cmpfunc); long d; if(n==2 || n==3){ printf("1"); return 0; } d=b[1]-b[0]; for(i=2;i<n;i++){ if((b[i]-b[i-1])!=d) break; } if(i==n) x=find(a,n,b[0]); else if(i==n-1) x=find(a,n,b[n-1]); else { int p,q,r; x=-1; if((p=check(b,n,i)==n-2)) x=find(a,n,b[i]); if((q=check(b,n,i-1)==n-2)) x=find(a,n,b[i-1]); if((r=check(b,n,i-2)==n-2)) x=find(a,n,b[i-2]);} printf("%d",x); }
A sequence $$$a_1, a_2, \dots, a_k$$$ is called an arithmetic progression if for each $$$i$$$ from $$$1$$$ to $$$k$$$ elements satisfy the condition $$$a_i = a_1 + c \cdot (i - 1)$$$ for some fixed $$$c$$$.For example, these five sequences are arithmetic progressions: $$$[5, 7, 9, 11]$$$, $$$[101]$$$, $$$[101, 100, 99]$$$, $$$[13, 97]$$$ and $$$[5, 5, 5, 5, 5]$$$. And these four sequences aren't arithmetic progressions: $$$[3, 1, 2]$$$, $$$[1, 2, 4, 8]$$$, $$$[1, -1, 1, -1]$$$ and $$$[1, 2, 3, 3, 3]$$$.You are given a sequence of integers $$$b_1, b_2, \dots, b_n$$$. Find any index $$$j$$$ ($$$1 \le j \le n$$$), such that if you delete $$$b_j$$$ from the sequence, you can reorder the remaining $$$n-1$$$ elements, so that you will get an arithmetic progression. If there is no such index, output the number -1.
Print such index $$$j$$$ ($$$1 \le j \le n$$$), so that if you delete the $$$j$$$-th element from the sequence, you can reorder the remaining elements, so that you will get an arithmetic progression. If there are multiple solutions, you are allowed to print any of them. If there is no such index, print -1.
C
6946f088e462d12da47419f492ad51ea
0c46fd6613b76ff7330d9f40666207e6
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "math" ]
1560955500
["5\n2 6 8 7 4", "8\n1 2 3 4 5 6 7 8", "4\n1 2 4 8"]
NoteNote to the first example. If you delete the $$$4$$$-th element, you can get the arithmetic progression $$$[2, 4, 6, 8]$$$.Note to the second example. The original sequence is already arithmetic progression, so you can delete $$$1$$$-st or last element and you will get an arithmetical progression again.
PASSED
1,700
standard input
2 seconds
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) β€” length of the sequence $$$b$$$. The second line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$-10^9 \le b_i \le 10^9$$$) β€” elements of the sequence $$$b$$$.
["4", "1", "-1"]
#include<stdio.h> #include<string.h> void merge(long long int a[],int p,int q,int r){ int i,j,k; int n1=q-p+1; int n2=r-q; long long int L[n1]; long long int R[n2]; for(i=0;i<n1;i++) L[i]=a[p+i]; for(j=0;j<n2;j++) R[j]=a[q+j+1]; i=0; j=0; k=p; while(i<n1 && j<n2){ if(L[i]<=R[j]) { a[k]=L[i]; i++; } else{ a[k]=R[j]; j++; } k++; } while(i<n1){ a[k]=L[i]; i++; k++; } while(j<n2){ a[k]=R[j]; j++; k++; } return; } void merge_sort(long long int a[],int p,int r){ if(r>p){ int q; q=(p+r)/2; merge_sort(a,p,q); merge_sort(a,q+1,r); merge(a,p,q,r); } return; } long long int remo(long long int b[],long long int i,long long int n){ long long int c[n]; long long int temp=0; for(long long int k=0;k<n;k++){ if(k!=i){ c[temp]=b[k]; temp++; } } long long int cnt=0; long long int d=c[1]-c[0]; for(long long int k=1;k<(n-1);k++){ if((c[k]-c[k-1])==d) cnt++; } return cnt; } long long int search(long long int a[],long long int v,long long int n){ for(long long int i=0;i<n;i++){ if(a[i]==v){ return i+1; } } return ; } int main(){ long long int n; scanf("%lld",&n); long long int a[n]; long long int b[n]; long long int i; for(i=0;i<n;i++){ scanf("%lld ",&a[i]); b[i]=a[i]; } merge_sort(b,0,n-1); if(n==2 || n==3) printf("1"); else{ int d=b[1]-b[0]; for(i=2;i<n;i++){ if((b[i]-b[i-1])!=d) break; } if(i==n){ long long int x=search(a,b[0],n); printf("%lld",x); } else if(i==(n-1)){ long long int x=search(a,b[n-1],n); printf("%lld",x); } else{ long long int cnt1=remo(b,i,n); long long int cnt2=remo(b,i-1,n); long long int cnt3=remo(b,i-2,n); long long int s=-1; if(cnt1==(n-2)){ s=search(a,b[i],n); } else if(cnt2==(n-2)){ s=search(a,b[i-1],n); } else if(cnt3==(n-2)){ s=search(a,b[i-2],n); } printf("%lld",s); } } return 0; }
A sequence $$$a_1, a_2, \dots, a_k$$$ is called an arithmetic progression if for each $$$i$$$ from $$$1$$$ to $$$k$$$ elements satisfy the condition $$$a_i = a_1 + c \cdot (i - 1)$$$ for some fixed $$$c$$$.For example, these five sequences are arithmetic progressions: $$$[5, 7, 9, 11]$$$, $$$[101]$$$, $$$[101, 100, 99]$$$, $$$[13, 97]$$$ and $$$[5, 5, 5, 5, 5]$$$. And these four sequences aren't arithmetic progressions: $$$[3, 1, 2]$$$, $$$[1, 2, 4, 8]$$$, $$$[1, -1, 1, -1]$$$ and $$$[1, 2, 3, 3, 3]$$$.You are given a sequence of integers $$$b_1, b_2, \dots, b_n$$$. Find any index $$$j$$$ ($$$1 \le j \le n$$$), such that if you delete $$$b_j$$$ from the sequence, you can reorder the remaining $$$n-1$$$ elements, so that you will get an arithmetic progression. If there is no such index, output the number -1.
Print such index $$$j$$$ ($$$1 \le j \le n$$$), so that if you delete the $$$j$$$-th element from the sequence, you can reorder the remaining elements, so that you will get an arithmetic progression. If there are multiple solutions, you are allowed to print any of them. If there is no such index, print -1.
C
6946f088e462d12da47419f492ad51ea
4e35899f0e9a6f7563e0fc2838f8acd3
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "math" ]
1560955500
["5\n2 6 8 7 4", "8\n1 2 3 4 5 6 7 8", "4\n1 2 4 8"]
NoteNote to the first example. If you delete the $$$4$$$-th element, you can get the arithmetic progression $$$[2, 4, 6, 8]$$$.Note to the second example. The original sequence is already arithmetic progression, so you can delete $$$1$$$-st or last element and you will get an arithmetical progression again.
PASSED
1,700
standard input
2 seconds
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) β€” length of the sequence $$$b$$$. The second line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$-10^9 \le b_i \le 10^9$$$) β€” elements of the sequence $$$b$$$.
["4", "1", "-1"]
/* upsolve with Dukkha */ #include <stdio.h> #include <stdlib.h> #define N 200000 int aa[N], ii[N]; int compare(const void *a, const void *b) { int i = *(int *) a; int j = *(int *) b; return aa[i] - aa[j]; } int check(int a0, int a1, int l, int r) { int c, a, i; c = a1 - a0, a = a1; for (i = l; i < r; i++) if (aa[ii[i]] != (a += c)) return i; return -1; } int main() { int n, i, j; scanf("%d", &n); if (n == 2) { printf("1\n"); return 0; } for (i = 0; i < n; i++) { scanf("%d", &aa[i]); ii[i] = i; } qsort(ii, n, sizeof *ii, compare); if (check(aa[ii[1]], aa[ii[2]], 3, n) == -1) { printf("%d\n", ii[0] + 1); return 0; } if (check(aa[ii[0]], aa[ii[2]], 3, n) == -1) { printf("%d\n", ii[1] + 1); return 0; } i = check(aa[ii[0]], aa[ii[1]], 2, n); for (j = i; j + 1 < n; j++) aa[ii[j]] = aa[ii[j + 1]]; if (check(aa[ii[0]], aa[ii[1]], 2, n - 1) == -1) { printf("%d\n", ii[i] + 1); return 0; } printf("-1\n"); return 0; }
A sequence $$$a_1, a_2, \dots, a_k$$$ is called an arithmetic progression if for each $$$i$$$ from $$$1$$$ to $$$k$$$ elements satisfy the condition $$$a_i = a_1 + c \cdot (i - 1)$$$ for some fixed $$$c$$$.For example, these five sequences are arithmetic progressions: $$$[5, 7, 9, 11]$$$, $$$[101]$$$, $$$[101, 100, 99]$$$, $$$[13, 97]$$$ and $$$[5, 5, 5, 5, 5]$$$. And these four sequences aren't arithmetic progressions: $$$[3, 1, 2]$$$, $$$[1, 2, 4, 8]$$$, $$$[1, -1, 1, -1]$$$ and $$$[1, 2, 3, 3, 3]$$$.You are given a sequence of integers $$$b_1, b_2, \dots, b_n$$$. Find any index $$$j$$$ ($$$1 \le j \le n$$$), such that if you delete $$$b_j$$$ from the sequence, you can reorder the remaining $$$n-1$$$ elements, so that you will get an arithmetic progression. If there is no such index, output the number -1.
Print such index $$$j$$$ ($$$1 \le j \le n$$$), so that if you delete the $$$j$$$-th element from the sequence, you can reorder the remaining elements, so that you will get an arithmetic progression. If there are multiple solutions, you are allowed to print any of them. If there is no such index, print -1.
C
6946f088e462d12da47419f492ad51ea
f390932e320342d889d49075d9e1fdd6
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "math" ]
1560955500
["5\n2 6 8 7 4", "8\n1 2 3 4 5 6 7 8", "4\n1 2 4 8"]
NoteNote to the first example. If you delete the $$$4$$$-th element, you can get the arithmetic progression $$$[2, 4, 6, 8]$$$.Note to the second example. The original sequence is already arithmetic progression, so you can delete $$$1$$$-st or last element and you will get an arithmetical progression again.
PASSED
1,700
standard input
2 seconds
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) β€” length of the sequence $$$b$$$. The second line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$-10^9 \le b_i \le 10^9$$$) β€” elements of the sequence $$$b$$$.
["4", "1", "-1"]
#include<stdio.h> #include<stdlib.h> typedef struct{ int num, pos; } Num; int comp(const void * a, const void * b){ return ((Num*)a)->num-((Num*)b)->num; } Num b[200000]; int main(){ int n, i, c, torf; scanf("%d", &n); if(n<4){ printf("1\n"); return 0; } for(i=0;i<n;++i){ scanf("%d", &b[i].num); b[i].pos=i+1; } qsort(b, n, sizeof(Num), comp); c=b[2].num-b[1].num; torf=1; for(i=3;i<n;++i){ if(c!=b[i].num-b[i-1].num){ torf=0; break; } } if(torf){ printf("%d\n", b[0].pos); return 0; } torf=1; c=b[2].num-b[0].num; for(i=3;i<n;++i){ if(c!=b[i].num-b[i-1].num){ torf=0; break; } } if(torf){ printf("%d\n", b[1].pos); return 0; } torf=-1; c=b[1].num-b[0].num; for(i=2;i<n;++i){ if(c!=b[i].num-b[i-1].num){ if(torf==-1){ if(i+1==n){ printf("%d\n", b[i].pos); return 0; } torf=i; } else{ if(torf+1!=i){ printf("-1\n"); return 0; } else if(c!=b[i].num-b[i-2].num){ printf("-1\n"); return 0; } } } if(torf+1==i && c!=b[i].num-b[i-2].num){ printf("-1\n"); return 0; } } printf("%d\n", b[torf].pos); return 0; }
A sequence $$$a_1, a_2, \dots, a_k$$$ is called an arithmetic progression if for each $$$i$$$ from $$$1$$$ to $$$k$$$ elements satisfy the condition $$$a_i = a_1 + c \cdot (i - 1)$$$ for some fixed $$$c$$$.For example, these five sequences are arithmetic progressions: $$$[5, 7, 9, 11]$$$, $$$[101]$$$, $$$[101, 100, 99]$$$, $$$[13, 97]$$$ and $$$[5, 5, 5, 5, 5]$$$. And these four sequences aren't arithmetic progressions: $$$[3, 1, 2]$$$, $$$[1, 2, 4, 8]$$$, $$$[1, -1, 1, -1]$$$ and $$$[1, 2, 3, 3, 3]$$$.You are given a sequence of integers $$$b_1, b_2, \dots, b_n$$$. Find any index $$$j$$$ ($$$1 \le j \le n$$$), such that if you delete $$$b_j$$$ from the sequence, you can reorder the remaining $$$n-1$$$ elements, so that you will get an arithmetic progression. If there is no such index, output the number -1.
Print such index $$$j$$$ ($$$1 \le j \le n$$$), so that if you delete the $$$j$$$-th element from the sequence, you can reorder the remaining elements, so that you will get an arithmetic progression. If there are multiple solutions, you are allowed to print any of them. If there is no such index, print -1.
C
6946f088e462d12da47419f492ad51ea
f35f8af3b8f5494e9422934223985567
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "math" ]
1560955500
["5\n2 6 8 7 4", "8\n1 2 3 4 5 6 7 8", "4\n1 2 4 8"]
NoteNote to the first example. If you delete the $$$4$$$-th element, you can get the arithmetic progression $$$[2, 4, 6, 8]$$$.Note to the second example. The original sequence is already arithmetic progression, so you can delete $$$1$$$-st or last element and you will get an arithmetical progression again.
PASSED
1,700
standard input
2 seconds
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) β€” length of the sequence $$$b$$$. The second line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$-10^9 \le b_i \le 10^9$$$) β€” elements of the sequence $$$b$$$.
["4", "1", "-1"]
#include<stdio.h> #include<stdlib.h> #include<stdint.h> void msort_memcpy (uint8_t * restrict dst, uint8_t * restrict src, size_t size) { while (size--) { *dst++ = *src++; } } void msort (void * const array, const size_t num, const size_t size, int (* const cmp) (const void *, const void *)) { typedef struct operation { size_t l; size_t r; int32_t type; } op; uint8_t * const a = (uint8_t *) array; uint8_t * const tmp = (uint8_t *) malloc (size * num); op stack[64]; int32_t top = 0; stack[top++] = (op) {0, num, 0}; while (top > 0) { const op t = stack[--top]; if (t.l + 1 >= t.r) continue; const size_t m = (t.l + t.r) / 2; if (t.type == 0) { stack[top++] = (op) {t.l, t.r, 1}; stack[top++] = (op) {t.l, m , 0}; stack[top++] = (op) {m , t.r, 0}; continue; } msort_memcpy (tmp, a + t.l * size, (m - t.l) * size); size_t i = 0; size_t j = m * size; size_t k = t.l * size; while (i < (m - t.l) * size && j < t.r * size) { if (cmp (tmp + i, a + j) <= 0) { msort_memcpy (a + k, tmp + i, size); i += size; } else { msort_memcpy (a + k, a + j, size); j += size; } k += size; } msort_memcpy (a + k, tmp + i, (m - t.l) * size - i); } free (tmp); } 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;} #define ALLOC(size,type) ((type*)calloc((size),sizeof(type))) #define SORT(a,n,cmp) msort((a),(n),sizeof(*(a)),cmp) typedef struct node { i32 v, k; } node; int cmp_node (const void *a, const void *b) { i32 d = ((node *)a)->v - ((node *)b)->v; return d == 0 ? 0 : d < 0 ? -1 : 1; } void run (void) { i32 n = read_int(); if (n <= 3) { puts ("1"); return; } node *p = ALLOC (n, node); for (i32 i = 0; i < n; ++i) { p[i].v = read_int(); p[i].k = i + 1; } SORT (p, n, cmp_node); i64 d = p[1].v - p[0].v; i64 x = p[0].v + 2 * d; i32 hit = 0; i32 k = 0; for (i32 i = 2; i < n; ++i) { if (p[i].v == x) { x += d; } else { hit++; k = i; } } if (hit <= 1) { print_int (p[k].k); puts (""); return; } d = p[2].v - p[0].v; x = p[0].v + 2 * d; hit = 1; k = 1; for (i32 i = 3; i < n; ++i) { if (p[i].v == x) { x += d; } else { hit++; k = i; } } if (hit <= 1) { print_int (p[k].k); puts (""); return; } d = p[2].v - p[1].v; x = p[1].v + 2 * d; hit = 1; k = 0; for (i32 i = 3; i < n; ++i) { if (p[i].v == x) { x += d; } else { hit++; k = i; } } if (hit <= 1) { print_int (p[k].k); puts (""); return; } puts ("-1"); } int main (void) { run (); return 0; }
A sequence $$$a_1, a_2, \dots, a_k$$$ is called an arithmetic progression if for each $$$i$$$ from $$$1$$$ to $$$k$$$ elements satisfy the condition $$$a_i = a_1 + c \cdot (i - 1)$$$ for some fixed $$$c$$$.For example, these five sequences are arithmetic progressions: $$$[5, 7, 9, 11]$$$, $$$[101]$$$, $$$[101, 100, 99]$$$, $$$[13, 97]$$$ and $$$[5, 5, 5, 5, 5]$$$. And these four sequences aren't arithmetic progressions: $$$[3, 1, 2]$$$, $$$[1, 2, 4, 8]$$$, $$$[1, -1, 1, -1]$$$ and $$$[1, 2, 3, 3, 3]$$$.You are given a sequence of integers $$$b_1, b_2, \dots, b_n$$$. Find any index $$$j$$$ ($$$1 \le j \le n$$$), such that if you delete $$$b_j$$$ from the sequence, you can reorder the remaining $$$n-1$$$ elements, so that you will get an arithmetic progression. If there is no such index, output the number -1.
Print such index $$$j$$$ ($$$1 \le j \le n$$$), so that if you delete the $$$j$$$-th element from the sequence, you can reorder the remaining elements, so that you will get an arithmetic progression. If there are multiple solutions, you are allowed to print any of them. If there is no such index, print -1.
C
6946f088e462d12da47419f492ad51ea
0c6556442ea1c804a3c6b7c80768cc8a
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "math" ]
1560955500
["5\n2 6 8 7 4", "8\n1 2 3 4 5 6 7 8", "4\n1 2 4 8"]
NoteNote to the first example. If you delete the $$$4$$$-th element, you can get the arithmetic progression $$$[2, 4, 6, 8]$$$.Note to the second example. The original sequence is already arithmetic progression, so you can delete $$$1$$$-st or last element and you will get an arithmetical progression again.
PASSED
1,700
standard input
2 seconds
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) β€” length of the sequence $$$b$$$. The second line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$-10^9 \le b_i \le 10^9$$$) β€” elements of the sequence $$$b$$$.
["4", "1", "-1"]
#include <stdio.h> #include <stdlib.h> #include <math.h> typedef struct { int number; int value; } element; typedef const element * Element; int compare(const void *p1, const void *p2) { if (((Element)p1)->value != ((Element)p2)->value) return ((Element)p1)->value - ((Element)p2)->value; return ((Element)p1)->number - ((Element)p2)->number; } int main(void) { int i, j, n, x, y, z; element b[200000]; scanf("%d", &n); if (n > 3) { for (i = 0; i < n; i++) { b[i].number = i+1; scanf("%d", &b[i].value); } qsort (b, n, sizeof(element), compare); // for (i = 0; i < n; i++) // printf("%d %d\n", b[i].number, b[i].value); x = b[1].value - b[0].value; y = b[2].value - b[1].value; z = b[3].value - b[2].value; if (x == y) { if (y == z) { if (n == 4) { printf("%d", b[0].number); return 0; } for (i = 4; i < n; i++) { //Ссли Π²ΡΡ‚Ρ€Π΅Ρ‚ΠΈΠ»ΠΈΡΡŒ 2 сосСдних элСмСнта ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΠΈ, Ρ€Π°Π·Π½ΠΎΡΡ‚ΡŒ ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Ρ… Π½Π΅ Ρ€Π°Π²Π½Π° x if (b[i].value - b[i-1].value != x) { //Ссли это ΡƒΠΆΠ΅ ΠΊΠΎΠ½Π΅Ρ† ΠΏΠΎΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΠΈ if (i == n-1) { printf("%d", b[n-1].number); return 0; } //Ссли Π½Π΅ ΠΊΠΎΠ½Π΅Ρ† ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΠΈ, провСряСм, Π±ΡƒΠ΄Π΅Ρ‚ Π»ΠΈ Ρ€Π°Π·Π½ΠΎΡΡ‚ΡŒ x ΠΌΠ΅ΠΆΠ΄Ρƒ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΌ Π·Π° элСмСнтом, Π½Π°Ρ€ΡƒΡˆΠΈΠ²ΡˆΠΈΠΌ порядок ΠΈ ΠΏΡ€Π΅Π΄Ρ‹Π΄ΡƒΡ‰ΠΈΠΌ if (b[i+1].value - b[i-1].value != x) //Ссли Π½Π΅ Π±ΡƒΠ΄Π΅Ρ‚, Ρ‚ΠΎ всё ΠΏΠ»ΠΎΡ…ΠΎ... { puts("-1"); return 0; } else //Ссли эта Ρ€Π°Π·Π½ΠΎΡΡ‚ΡŒ ΠΊΠ°ΠΊ Ρ€Π°Π· Ρ€Π°Π²Π½Π° x { j = i+1; if (j == n-1) //Ссли это ΠΊΠΎΠ½Π΅Ρ† ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΠΈ { printf("%d", b[i].number);//выводится прСдпослСдний элСмСнт ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΠΈ return 0; } //Ссли ΠΆΠ΅ Π½Π΅Ρ‚ for (i = j+1; i < n; i++) //просто провСряСм, Π±ΡƒΠ΄Π΅Ρ‚ Π»ΠΈ дальшС Π½Π°Ρ€ΡƒΡˆΠ°Ρ‚ΡŒΡΡ порядок. Если Π±ΡƒΠ΄Π΅Ρ‚, Ρ‚ΠΎ всё ΠΏΠ»ΠΎΡ…ΠΎ... { if (b[i].value - b[i-1].value != x) { puts("-1"); return 0; } } //ΠΈΠ½Π°Ρ‡Π΅ Π²Ρ‹Π²ΠΎΠ΄ΠΈΠΌ Π½ΠΎΠΌΠ΅Ρ€ элСмСнта, Π½Π°Ρ€ΡƒΡˆΠΈΠ²ΡˆΠ΅Π³ΠΎ порядок printf("%d", b[j-1].number); return 0; } } } //ΠΈΠ½Π°Ρ‡Π΅, Ссли ΠΏΠΎΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΡŒ являСтся арифмСтичСской прогрСссиСй printf("%d", b[0].number); return 0; } else //if (y != z) { //Ρ‚ΠΎΠ³Π΄Π° арифмСтичСская прогрСссия ΠΌΠΎΠΆΠ΅Ρ‚ ΠΏΠΎΠ»ΡƒΡ‡ΠΈΡ‚ΡŒΡΡ Π»ΠΈΠ±ΠΎ ΠΏΡ€ΠΈ Π²Ρ‹Ρ‡Ρ‘Ρ€ΠΊΠΈΠ²Π°Π½ΠΈΠΈ 2-Π³ΠΎ, Π»ΠΈΠ±ΠΎ ΠΏΡ€ΠΈ Π²Ρ‹Ρ‡Ρ‘Ρ€ΠΊΠΈΠ²Π°Π½ΠΈΠΈ 4-Π³ΠΎ элСмСнта if (n == 4) { printf("%d", b[3].number); return 0; } if (b[4].value - b[2].value == x) { if (n == 5) { printf("%d", b[3].number); return 0; } for (i = 5; i < n; i++) { if (b[i].value - b[i-1].value != x) { puts("-1"); return 0; } } printf("%d", b[2].number); return 0; } if (x+y == z) { if (n == 4) { printf("%d", b[1].number); return 0; } for (i = 4; i < n; i++) { if (b[i].value - b[i-1].value != z) { puts("-1"); return 0; } } printf("%d", b[1].number); return 0; } puts("-1"); } } else //if (x != y) { if (n == 3) { printf("%d", b[2].number); return 0; } if (b[3].value - b[2].value == x+y) { if (n == 4) { printf("%d", b[1].number); return 0; } z = x+y; for (i = 4; i < n; i++) { if (b[i].value - b[i-1].value != z) { puts("-1"); return 0; } } printf("%d", b[1].number); return 0; } if (b[3].value - b[2].value == y) { if (n == 4) { printf("%d", b[1].number); return 0; } for (i = 3; i < n; i++) { if (b[i].value - b[i-1].value != y) { puts("-1"); return 0; } } printf("%d", b[0].number); return 0; } if (b[3].value - b[1].value == x) { if (n == 4) { printf("%d", b[2].number); return 0; } for (i = 4; i < n; i++) { if (b[i].value - b[i-1].value != x) { puts("-1"); return 0; } } printf("%d", b[2].number); return 0; } puts("-1"); return 0; } } else puts("1"); return 0; }
A sequence $$$a_1, a_2, \dots, a_k$$$ is called an arithmetic progression if for each $$$i$$$ from $$$1$$$ to $$$k$$$ elements satisfy the condition $$$a_i = a_1 + c \cdot (i - 1)$$$ for some fixed $$$c$$$.For example, these five sequences are arithmetic progressions: $$$[5, 7, 9, 11]$$$, $$$[101]$$$, $$$[101, 100, 99]$$$, $$$[13, 97]$$$ and $$$[5, 5, 5, 5, 5]$$$. And these four sequences aren't arithmetic progressions: $$$[3, 1, 2]$$$, $$$[1, 2, 4, 8]$$$, $$$[1, -1, 1, -1]$$$ and $$$[1, 2, 3, 3, 3]$$$.You are given a sequence of integers $$$b_1, b_2, \dots, b_n$$$. Find any index $$$j$$$ ($$$1 \le j \le n$$$), such that if you delete $$$b_j$$$ from the sequence, you can reorder the remaining $$$n-1$$$ elements, so that you will get an arithmetic progression. If there is no such index, output the number -1.
Print such index $$$j$$$ ($$$1 \le j \le n$$$), so that if you delete the $$$j$$$-th element from the sequence, you can reorder the remaining elements, so that you will get an arithmetic progression. If there are multiple solutions, you are allowed to print any of them. If there is no such index, print -1.
C
6946f088e462d12da47419f492ad51ea
e245ab6dcaea4b8af54d7988c32e8a06
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "math" ]
1560955500
["5\n2 6 8 7 4", "8\n1 2 3 4 5 6 7 8", "4\n1 2 4 8"]
NoteNote to the first example. If you delete the $$$4$$$-th element, you can get the arithmetic progression $$$[2, 4, 6, 8]$$$.Note to the second example. The original sequence is already arithmetic progression, so you can delete $$$1$$$-st or last element and you will get an arithmetical progression again.
PASSED
1,700
standard input
2 seconds
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) β€” length of the sequence $$$b$$$. The second line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$-10^9 \le b_i \le 10^9$$$) β€” elements of the sequence $$$b$$$.
["4", "1", "-1"]
#include <stdio.h> #include <stdlib.h> int lcmp(const void* a, const void *b) { return *(int*)a - *(int*)b; } int k; int *v, *ov; int first(int skip) { return skip==0?1:0; } int next(int i, int skip) { if (++i == skip) ++i; return i; } int walk(int *skip) { int c, n, d; c = first(*skip); d = v[next(c, *skip)] - v[c]; while (1) { n = next(c, *skip); if (n > k -1) return 1; if (v[n] - v[c] != d) { if (*skip == -1) { *skip = n; continue; } return 0; } c = n; } } int find(int v) { for (int i = 0; i < k; i++) if (ov[i] == v) return i + 1; return -2; } int main() { scanf("%d", &k); v = (int*)malloc((k + 1) * sizeof(int)); ov = (int*)malloc((k + 1) * sizeof(int)); for (int i = 0; i < k; i++) { scanf("%ld", &v[i]); ov[i] = v[i]; } qsort(v, k, sizeof(int), lcmp); int sk[] = {1, 0, -1, -1}; int skip; for (int i = 0; i < 3; i++) { skip = sk[i]; if (walk(&skip)) break; else skip = -1; } printf("%d\n", skip >= 0 ? find(v[skip]) : -1); return 0; }
A sequence $$$a_1, a_2, \dots, a_k$$$ is called an arithmetic progression if for each $$$i$$$ from $$$1$$$ to $$$k$$$ elements satisfy the condition $$$a_i = a_1 + c \cdot (i - 1)$$$ for some fixed $$$c$$$.For example, these five sequences are arithmetic progressions: $$$[5, 7, 9, 11]$$$, $$$[101]$$$, $$$[101, 100, 99]$$$, $$$[13, 97]$$$ and $$$[5, 5, 5, 5, 5]$$$. And these four sequences aren't arithmetic progressions: $$$[3, 1, 2]$$$, $$$[1, 2, 4, 8]$$$, $$$[1, -1, 1, -1]$$$ and $$$[1, 2, 3, 3, 3]$$$.You are given a sequence of integers $$$b_1, b_2, \dots, b_n$$$. Find any index $$$j$$$ ($$$1 \le j \le n$$$), such that if you delete $$$b_j$$$ from the sequence, you can reorder the remaining $$$n-1$$$ elements, so that you will get an arithmetic progression. If there is no such index, output the number -1.
Print such index $$$j$$$ ($$$1 \le j \le n$$$), so that if you delete the $$$j$$$-th element from the sequence, you can reorder the remaining elements, so that you will get an arithmetic progression. If there are multiple solutions, you are allowed to print any of them. If there is no such index, print -1.
C
6946f088e462d12da47419f492ad51ea
cad83c7e4c26ea6d67641ba50db3b5a8
GNU C11
standard output
256 megabytes
train_002.jsonl
[ "implementation", "math" ]
1560955500
["5\n2 6 8 7 4", "8\n1 2 3 4 5 6 7 8", "4\n1 2 4 8"]
NoteNote to the first example. If you delete the $$$4$$$-th element, you can get the arithmetic progression $$$[2, 4, 6, 8]$$$.Note to the second example. The original sequence is already arithmetic progression, so you can delete $$$1$$$-st or last element and you will get an arithmetical progression again.
PASSED
1,700
standard input
2 seconds
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) β€” length of the sequence $$$b$$$. The second line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$-10^9 \le b_i \le 10^9$$$) β€” elements of the sequence $$$b$$$.
["4", "1", "-1"]
#include<stdio.h> #include<stdlib.h> int cmpfunc (const void * a, const void * b) { return ( *(int*)a - *(int*)b ); } long long find(long long a[],long long n,long long x){ long long i; for(i=0;i<n;i++) { if(a[i]==x) return i+1; } } long long check(long long b[],long long n,long long i){ long long int c[n]; long long int temp=0; for(long long int k=0;k<n;k++){ if(k!=i){ c[temp]=b[k]; temp++; } } long long int cnt=0; long long int d=c[1]-c[0]; for(long long int k=1;k<(n-1);k++){ if((c[k]-c[k-1])==d) cnt++; } return cnt; } int main(){ long long int n,x; scanf("%I64d",&n); long long int a[n]; long long int b[n]; long long int i; for(i=0;i<n;i++){ scanf("%I64d",&a[i]); b[i]=a[i]; } qsort(b,n,sizeof(long long int),cmpfunc); long d; if(n==2 || n==3){ printf("1"); return 0; } d=b[1]-b[0]; for(i=2;i<n;i++){ if((b[i]-b[i-1])!=d) break; } if(i==n) x=find(a,n,b[0]); else if(i==n-1) x=find(a,n,b[n-1]); else { int p,q,r; x=-1; if((p=check(b,n,i)==n-2)) x=find(a,n,b[i]); if((q=check(b,n,i-1)==n-2)) x=find(a,n,b[i-1]); if((r=check(b,n,i-2)==n-2)) x=find(a,n,b[i-2]);} printf("%d",x); }
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 &gt; a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy.
Print a single integer β€” the number of games Maxim will buy.
C
c3f080681e3da5e1290ef935ff91f364
417ea6fff4fdbf7d70d5210e5e0d2e95
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation" ]
1531578900
["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"]
NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet.
PASSED
800
standard input
1 second
The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) β€” the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet.
["3", "0", "4"]
#include <stdio.h> int main() { int n , m , a , b , p = 0 ; scanf("%d %d",&n,&m) ; int games[n] , bills[m] ; for(a=0;a<n;a++) { scanf("%d",&games[a]) ; } for(b=0;b<m;b++) { scanf("%d",&bills[b]) ; } int x,y , flag = 1 , count = 0 ; for( x=0; x<m && flag ; x++) { for( y=p ; y<n ; y++,p++ ) { if( bills[x] >= games[y] && ( games[y] != 0 ) ) { games[y] = 0 ; count++ ; break ; } } if( y == n ) { flag = 0 ; } } printf("%d\n",count) ; return 0 ; }
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 &gt; a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy.
Print a single integer β€” the number of games Maxim will buy.
C
c3f080681e3da5e1290ef935ff91f364
af16e9cbbca76fdf60607afe17918408
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation" ]
1531578900
["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"]
NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet.
PASSED
800
standard input
1 second
The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) β€” the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet.
["3", "0", "4"]
#include<stdio.h> int main() { int n,m,a[1500],b[1500],i,j; scanf("%d%d",&n,&m); for(i=0;i<n;i++) scanf("%d",&a[i]); for(j=0;j<m;j++) scanf("%d",&b[j]); j=0; for(i=0;i<n;i++) { if(a[i]<=b[j]) { j++; if(j==m)break; } } printf("%d",j); return 0; }
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 &gt; a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy.
Print a single integer β€” the number of games Maxim will buy.
C
c3f080681e3da5e1290ef935ff91f364
cd21fc15e4910f6a53f210042a0626d1
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation" ]
1531578900
["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"]
NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet.
PASSED
800
standard input
1 second
The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) β€” the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet.
["3", "0", "4"]
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> #define MIN(X, Y) (((X) < (Y)) ? (X) : (Y)) #define MAX(X, Y) (((X) > (Y)) ? (X) : (Y)) #define ll long long int main(void) { int game[1001],bil[1001],n,m,cn,i,j; scanf("%d%d",&n,&m); for(i=0;i<n;i++) scanf("%d",game+i); for(i=0;i<m;i++) scanf("%d",bil+i); cn=0; for(i=0,j=0;i<n&&j<m;i++) { if(bil[j]>=game[i]) { j++; cn++; } } printf("%d",cn); return 0; }
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 &gt; a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy.
Print a single integer β€” the number of games Maxim will buy.
C
c3f080681e3da5e1290ef935ff91f364
e758a8c4a5c98579ba4fda40da6033e9
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation" ]
1531578900
["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"]
NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet.
PASSED
800
standard input
1 second
The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) β€” the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet.
["3", "0", "4"]
#include<stdio.h> int main() { int a[1010],c[1010],n,m,i,j,cnt=0,o,p; scanf("%d %d",&n,&m); for(i=1;i<=n;i++) scanf("%d",&c[i]); for(j=1;j<=m;j++) scanf("%d",&a[j]); o=1; p=1; for( ;((o<=m)&&(p<=n)); ) { if(a[o]>=c[p]) { o++; p++; cnt++; } else if(a[o]<c[p]) { p++; } } printf("%d\n",cnt); return 0; }
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 &gt; a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy.
Print a single integer β€” the number of games Maxim will buy.
C
c3f080681e3da5e1290ef935ff91f364
316df4057db2ee61a20b44febbf04897
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation" ]
1531578900
["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"]
NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet.
PASSED
800
standard input
1 second
The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) β€” the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet.
["3", "0", "4"]
#include <stdio.h> #include <stdlib.h> int main() { int i, x, y,c=0, no=0; scanf("%d%d", &x, &y); int a[x], b[y]; for(i=0;i<x;i++) { scanf("%d", &a[i]); } for(i=0;i<y;i++) { scanf("%d", &b[i]); } for(i=0;i<x;i++) { if(a[i]<=b[no]) { no++; } if(no==y) { break; } } printf("%d", no); return 0; }
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 &gt; a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy.
Print a single integer β€” the number of games Maxim will buy.
C
c3f080681e3da5e1290ef935ff91f364
a10ac50c35e57228c6b523054ace7416
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation" ]
1531578900
["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"]
NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet.
PASSED
800
standard input
1 second
The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) β€” the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet.
["3", "0", "4"]
/****************************************************************************** Online C Compiler. Code, Compile, Run and Debug C program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <stdio.h> int main() { int n,m,i,j; int count=0; scanf("%d %d",&n,&m); int A[n],B[m]; for(i=0;i<n;i++) scanf("%d",&A[i]); for(j=0;j<m;j++) scanf("%d",&B[j]); i=0; j=0; while(i<n && j<m) { if(A[i]<=B[j]) { count++; i++; j++; } else i++; } printf("%d\n",count); return 0; }
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 &gt; a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy.
Print a single integer β€” the number of games Maxim will buy.
C
c3f080681e3da5e1290ef935ff91f364
5478ef2df88f0a6e76ef0ec540f2e3da
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation" ]
1531578900
["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"]
NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet.
PASSED
800
standard input
1 second
The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) β€” the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet.
["3", "0", "4"]
#include<stdio.h> int main() { int i,j,k,l,n,m,t; scanf("%d%d",&n,&m); int a[n]; for(i=0;i<n;i++) scanf("%d",&a[i]); int b[m]; for(t=0;t<m;t++) scanf("%d",&b[t]); l=0; k=0; j=0; while(j<m&&k<n) { if(b[j]>=a[k]) { j++; k++; l++; } else k++; } printf("%d",l); return 0; }
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 &gt; a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy.
Print a single integer β€” the number of games Maxim will buy.
C
c3f080681e3da5e1290ef935ff91f364
2c6568667f8bf6d4c692e701ce7ac4f6
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation" ]
1531578900
["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"]
NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet.
PASSED
800
standard input
1 second
The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) β€” the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet.
["3", "0", "4"]
#include<stdio.h> #include<conio.h> int main(){ int g,b; scanf("%d",&g); scanf("%d",&b); int gl[g]; int bl[b]; int k; for(k=0;k<g;k++){ scanf("%d",&gl[k]); } for(k=0;k<b;k++){ scanf("%d",&bl[k]); } int i=0,j=0,counter = 0; while(i < g & j < b){ if(bl[j] >= gl[i]){ j++; i++; counter++; } else if(gl[i] > bl[j]){ i++; } } printf("%d",counter); }
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 &gt; a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy.
Print a single integer β€” the number of games Maxim will buy.
C
c3f080681e3da5e1290ef935ff91f364
f731e576db664109e118e5aa984c9c93
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation" ]
1531578900
["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"]
NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet.
PASSED
800
standard input
1 second
The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) β€” the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet.
["3", "0", "4"]
#include <stdio.h> int main() { int n,m,i,j=0,T=0; scanf("%d%d",&n,&m); int c[n],a[m]; for (i=0; i<n; i++) scanf("%d",&c[i]); for (i=0; i<m; i++) scanf("%d",&a[i]); for (i=0; i<n; i++) { if(a[j]>=c[i]) { T++; j++; if(j>=m) break; } } printf("%d\n",T); return 0; }
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 &gt; a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy.
Print a single integer β€” the number of games Maxim will buy.
C
c3f080681e3da5e1290ef935ff91f364
8711fb2055461385db54ef76c059bc86
GNU C
standard output
256 megabytes
train_002.jsonl
[ "implementation" ]
1531578900
["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"]
NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet.
PASSED
800
standard input
1 second
The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) β€” the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet.
["3", "0", "4"]
#include<stdio.h> int main(){ int n, m, i, k, cont; scanf("%d%d", &n, &m); int v[n], x[m]; for(i = 0; i < n; i++) scanf("%d", &v[i]); for(i = 0; i < m; i++) scanf("%d", &x[i]); i = k = cont = 0; while(k < m && i < n){ if(v[i] <= x[k]){ cont++; i++; k++; }else{ i++; } } printf("%d", cont); return 0; }