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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced. | Print the k-th pronounced identifier (assume that the numeration starts from 1). | C | 9ad07b42358e7f7cfa15ea382495a8a1 | b409a55a7e9889f23887da14b3e0dad4 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1462464300 | ["2 2\n1 2", "4 5\n10 4 18 3"] | NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | PASSED | 1,000 | standard input | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different. | ["1", "4"] | #include <stdio.h>
int main()
{
int i, n, k, a[100005];
scanf("%d %d", &n, &k);
for (i = 1; i <= n; i++)
scanf("%d", &a[i]);
for (i = 1; i <= 2000000000; i++)
{
if (k - i > 0)k -= i;
else
{
printf("%d", a[k]);
break;
}
}
} | |
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced. | Print the k-th pronounced identifier (assume that the numeration starts from 1). | C | 9ad07b42358e7f7cfa15ea382495a8a1 | f90d6fe1babcc16e3e5d3808d193152a | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1462464300 | ["2 2\n1 2", "4 5\n10 4 18 3"] | NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | PASSED | 1,000 | standard input | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different. | ["1", "4"] | #include <stdio.h>
#define N 100000
int main() {
static int aa[N];
int n, i;
long long k;
scanf("%d%lld", &n, &k), k--;
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
for (i = 1; i <= n; i++)
if (k >= i)
k -= i;
else {
printf("%d\n", aa[k]);
return 0;
}
return 0;
}
| |
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced. | Print the k-th pronounced identifier (assume that the numeration starts from 1). | C | 9ad07b42358e7f7cfa15ea382495a8a1 | 22978e109a90581a702c86e3928859a9 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1462464300 | ["2 2\n1 2", "4 5\n10 4 18 3"] | NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | PASSED | 1,000 | standard input | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different. | ["1", "4"] | #include<stdio.h>
#include<math.h>
int main()
{
long long int n, k, s, i, y;
double x;
scanf("%lld %lld", &n, &k);
long long int a[n+1];
for(i=0; i<n; i++)
{
scanf("%lld", &a[i]);
}
x=(-1+sqrt(1+(8*k)))/2;
s=x/1;
y=s;
s=k-((s*(s+1))/2);
if(s==0)
{
printf("%lld", a[y-1]);
}
else
{
printf("%lld", a[s-1]);
}
return 0;
} | |
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced. | Print the k-th pronounced identifier (assume that the numeration starts from 1). | C | 9ad07b42358e7f7cfa15ea382495a8a1 | 1d4401ceca0abbfce28b0fda7e23b1a5 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1462464300 | ["2 2\n1 2", "4 5\n10 4 18 3"] | NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | PASSED | 1,000 | standard input | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different. | ["1", "4"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
long long int k,sum,sum2,n,i;
int pos;
scanf("%lld %lld",&n ,&k);
int ara[100000];
for(i=0;i<n;i++)
scanf("%lld",&ara[i]);
for(i=1;i<=n;i++){
sum=i*(i+1);
sum=sum/2;
if(sum>=k)
{sum2=(i-1)*i;
sum2=sum2/2;
pos=k-sum2-1;
break;
}
}
printf("%d\n",ara[pos]);
return 0;
}
| |
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced. | Print the k-th pronounced identifier (assume that the numeration starts from 1). | C | 9ad07b42358e7f7cfa15ea382495a8a1 | cf387ef2460c7b042359d7fc7c7f952a | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1462464300 | ["2 2\n1 2", "4 5\n10 4 18 3"] | NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | PASSED | 1,000 | standard input | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different. | ["1", "4"] | #include <stdio.h>
int main()
{
long int n,k;
scanf("%ld%ld",&n,&k);
long int a[1000000],b[1000000];
long int i;
for(i=0;i<n;i++)
scanf("%ld",&a[i]);
long int d=0,j;
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
b[j]=a[j];
d++;
if(d==k)
break;
}
if(d==k)
break;
}
printf("%ld",b[j]);
return 0;
} | |
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced. | Print the k-th pronounced identifier (assume that the numeration starts from 1). | C | 9ad07b42358e7f7cfa15ea382495a8a1 | 60186e621234ae05fd272b6864c2d9d7 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1462464300 | ["2 2\n1 2", "4 5\n10 4 18 3"] | NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | PASSED | 1,000 | standard input | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different. | ["1", "4"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int a[10000002],n,i;
long long int k;
scanf("%d%lld",&n,&k);
k--;
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=1;i<=n;i++)
{
if(k>=i)
k=k-i;
else
{
printf("%d\n",a[k]);
return 0;
}
}
return 0;
}
| |
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced. | Print the k-th pronounced identifier (assume that the numeration starts from 1). | C | 9ad07b42358e7f7cfa15ea382495a8a1 | 685cc9c28d3b14e1c1732d5b0008e641 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1462464300 | ["2 2\n1 2", "4 5\n10 4 18 3"] | NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | PASSED | 1,000 | standard input | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different. | ["1", "4"] | #include<stdio.h>
int main()
{
long long int n,k,i,x,y;
scanf("%lld %lld",&n,&k);
long long int a[n];
for(i=0;i<n;i++)
scanf("%lld",&a[i]);
x=(sqrt(1+8*k)-1)/2;
y=x*(x+1)/2;
if(y==k)
printf("%lld",a[x-1]);
else
printf("%lld",a[k-y-1]);
} | |
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced. | Print the k-th pronounced identifier (assume that the numeration starts from 1). | C | 9ad07b42358e7f7cfa15ea382495a8a1 | 359635ae08f5ade0c8a1b9b28c60616e | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1462464300 | ["2 2\n1 2", "4 5\n10 4 18 3"] | NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | PASSED | 1,000 | standard input | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different. | ["1", "4"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
long long int n,k,i,j,temp=0,flag=0,sub,res;
long long int a[100004];
scanf("%I64d%I64d",&n,&k);
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(j=1;j<=n;j++)
{
temp=((j*(j-1))/2)+1;
if(temp<=k)
{
flag=temp;
sub=k-flag;
}
else
{
break;
}
}
printf("%d\n",a[1+sub]);
return 0;
}
| |
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced. | Print the k-th pronounced identifier (assume that the numeration starts from 1). | C | 9ad07b42358e7f7cfa15ea382495a8a1 | e2cc38fbd5ee124e046ba00d242f7532 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1462464300 | ["2 2\n1 2", "4 5\n10 4 18 3"] | NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | PASSED | 1,000 | standard input | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different. | ["1", "4"] | #include <stdio.h>
#include <stdlib.h>
int main()
{long long int n,k, i, j, sum = 0, robot, sum2 = 0;
scanf("%I64d %I64d",&n,&k);
long long int identifier[n];
for(i = 0; i < n; i++)
{
scanf("%I64d",&identifier[i]);
}
for(i = 1; sum < k ;i++)
{
sum = (((i)*(i+1)) / 2) ;
}
robot = i - 1;
//printf("robot = %I64d, sum = %I64d, k = %I64d and i = %I64d",robot, sum, k, i);
sum2= (((robot-1)*(robot)) / 2);
printf("%I64d",identifier[k - sum2 - 1]);
return 0;
}
| |
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced. | Print the k-th pronounced identifier (assume that the numeration starts from 1). | C | 9ad07b42358e7f7cfa15ea382495a8a1 | 599811c65931c4d3af5029496399d96a | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1462464300 | ["2 2\n1 2", "4 5\n10 4 18 3"] | NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | PASSED | 1,000 | standard input | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different. | ["1", "4"] | #include<stdio.h>
int main()
{
long long int n,k, j = 1,i,a;
scanf("%I64d %I64d", &n, &k);
long long int ara[n + 1];
ara[0] = 0;
for(i = 1; i <= n; i++)
{
scanf("%I64d", &ara[i]);
}
while(1)
{
a = j * (j + 1) / 2;
if(a > k)
{
j = j - 1;
a = j * (j + 1) / 2;
printf("%I64d", ara[k - a]);
break;
}
else if(a == k)
{
printf("%I64d", ara[j]);
break;
}
else j++;
}
return 0;
}
| |
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced. | Print the k-th pronounced identifier (assume that the numeration starts from 1). | C | 9ad07b42358e7f7cfa15ea382495a8a1 | f3c31335605a8ef4791644b313fc4fc7 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1462464300 | ["2 2\n1 2", "4 5\n10 4 18 3"] | NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | PASSED | 1,000 | standard input | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different. | ["1", "4"] | #include<stdio.h>
#include<stdlib.h>
int main()
{
long long int n,k,p;
scanf("%lld %lld",&n,&k);
long long int a[n+2],i,id[n];
for(i=1;i<=n+1;i++)
{a[i]=(i*(i+1))/2;}
for(i=0;i<n;i++)
{scanf("%lld",&id[i]);}
for(i=1;i<=n+1;i++)
{long long int w=(k/a[i]);
if(w==0)
{
if(a[i-1]==k)
{printf("%lld",id[i-2]);
break;}
else
{p=a[i-1];
printf("%lld",id[k-p-1]);
break;}
}
}
//printf("%lld",id[k-p-1]);
return 0;
} | |
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced. | Print the k-th pronounced identifier (assume that the numeration starts from 1). | C | 9ad07b42358e7f7cfa15ea382495a8a1 | a9f7ef17dff7b2fb77017ad21eaad722 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1462464300 | ["2 2\n1 2", "4 5\n10 4 18 3"] | NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | PASSED | 1,000 | standard input | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different. | ["1", "4"] | #include<stdio.h>
int main(void)
{
long long int n,k,x=0;
scanf("%lld%lld",&n,&k);
long long int a[n+1];
long long int j,i;
for(i=0;i<n;i++)
{
scanf("%lld",&a[i]);
}
for(i=1;i<=n;i++)
{
x=i*(i+1)/2;
if(x>=k)
break;
}
i=i-1;
x=i*(i+1)/2;
k=k-x;
if(k==0)
printf("%lld",a[i-1]);
//printf("%ld i \n %ld x\n %ld k\n",i,x,k);
else
printf("%lld",a[k-1]);
}
/*
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
x++;
if(k==x)
{
printf("%ld",a[j-1]);
break;
}
}
}
*/
//} | |
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced. | Print the k-th pronounced identifier (assume that the numeration starts from 1). | C | 9ad07b42358e7f7cfa15ea382495a8a1 | 5c00cb28b5633346033b36c88cfb886b | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1462464300 | ["2 2\n1 2", "4 5\n10 4 18 3"] | NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | PASSED | 1,000 | standard input | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different. | ["1", "4"] | #include <stdio.h>
#include <stdlib.h>
int main(){
int n, k, i, j, aux;
scanf("%d %d", &n, &k);
int v[n], v1[100];
for(i=0;i<n;i++){
scanf("%d", &j);
v[i]=j;
}
i=0;
aux=1;
while(i<k){
for(j=0;j<aux;j++){
v[j];
if(i==k){
break;
}
else i++;
}
aux++;
}
/*for(i=0;i<100;i++){
printf("%d\n", v1[i]);
}*/
printf("%d", v[j-1]);
}
| |
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced. | Print the k-th pronounced identifier (assume that the numeration starts from 1). | C | 9ad07b42358e7f7cfa15ea382495a8a1 | d8d7a804e10b4c527afeea5f89991a3d | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1462464300 | ["2 2\n1 2", "4 5\n10 4 18 3"] | NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | PASSED | 1,000 | standard input | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different. | ["1", "4"] | #include <stdio.h>
long long maiornum(long long k){
long long num, i;
i = 0;
num = 1;
while(num < k){
i++;
num = i*(i+1)/2;
}
if(k != (i-1)*i/2) return k - (i-1)*i/2 - 1;
else return i-1;
}
long long robot[111111];
int main(){
long long n, k, i, cont, l;
cont = 0;
scanf("%lld %lld" , &n, &k);
for(i = 0 ; i < n ; i++) scanf("%lld" , &robot[i]);
l = maiornum(k);
printf("%lld\n", robot[l]);
return 0;
} | |
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced. | Print the k-th pronounced identifier (assume that the numeration starts from 1). | C | 9ad07b42358e7f7cfa15ea382495a8a1 | f5538e411bed264a38b91478d96586a2 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1462464300 | ["2 2\n1 2", "4 5\n10 4 18 3"] | NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | PASSED | 1,000 | standard input | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different. | ["1", "4"] | #include<stdio.h>
#include<math.h>
int main()
{
int n,k,i,ara[100000];
scanf("%d%d",&n,&k);
for(i=0;i<n;i++)
scanf("%d",&ara[i]);
i=1;
while(i<k)
{
k-=i;
i++;
}
printf("%d\n",ara[k-1]);
return 0;
}
| |
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced. | Print the k-th pronounced identifier (assume that the numeration starts from 1). | C | 9ad07b42358e7f7cfa15ea382495a8a1 | e5104d684488bdcff616173384e2a7b7 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1462464300 | ["2 2\n1 2", "4 5\n10 4 18 3"] | NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | PASSED | 1,000 | standard input | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different. | ["1", "4"] | #include<stdio.h>
int main()
{
int n,k,a[1000009],i,x;
scanf("%d %d",&n,&k);
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
x=k;
// printf("%d\n",x);
for(i=1;i<=n;i++)
{
// printf("*");
k=k-i;
if(k==0)
{
// printf("&");
printf("%d\n",a[k+i]);
break;
}
if(k<0)
{
// printf("!");
k=k+i;
printf("%d\n",a[k]);
break;
}
}
return 0;
}
| |
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced. | Print the k-th pronounced identifier (assume that the numeration starts from 1). | C | 9ad07b42358e7f7cfa15ea382495a8a1 | 76462ff045ad159305911ce83df09ef0 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1462464300 | ["2 2\n1 2", "4 5\n10 4 18 3"] | NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | PASSED | 1,000 | standard input | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different. | ["1", "4"] | #include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<complex.h>
#include<string.h>
#define prime 1000000007
int main()
{
long long temp,lol,i,num,find,arr[100005];
scanf("%lli %lli",&num,&find);
for(i=0;i<num;i++)
{
scanf("%lli",&arr[i]);
}
long long count=0;
for(i=0;i<100005;i++)
{
lol=(i*(i+1))/2;
if(find==lol)
{
printf("%lli\n",arr[i-1]);
break;
}
else if(find<lol)
{
temp=find-((i*(i-1))/2);
printf("%lli\n",arr[temp-1]);
break;
}
else
count++;
}
return 0;
}
| |
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced. | Print the k-th pronounced identifier (assume that the numeration starts from 1). | C | 9ad07b42358e7f7cfa15ea382495a8a1 | 231080d01b74fdec912a428b14f8b61b | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1462464300 | ["2 2\n1 2", "4 5\n10 4 18 3"] | NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | PASSED | 1,000 | standard input | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different. | ["1", "4"] | #include<stdio.h>
#include<math.h>
int main()
{
int n;
scanf("%d",&n);
long k;
scanf("%ld",&k);
long a[n+1];
for(int i=1;i<n+1;i++)
scanf("%ld",&a[i]);
long root=(long)sqrt(k);
long t=((root)*(root+1))/2;
long i=root+1;
while(k>t)
{
t+=i;
i++;
}
i--;
t-=i;
k-=t;
printf("%ld",a[(int) k]);
}
| |
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced. | Print the k-th pronounced identifier (assume that the numeration starts from 1). | C | 9ad07b42358e7f7cfa15ea382495a8a1 | 4afadcd626eade46c528a7a2bf4f5879 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1462464300 | ["2 2\n1 2", "4 5\n10 4 18 3"] | NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | PASSED | 1,000 | standard input | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different. | ["1", "4"] | /* 20160721 JJA Codeforces #350 B.Game of Robots */
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main() {
int n;
int k=0;
int *arr;
int tmp;
int no;
scanf("%d %d", &n, &k);
arr = (int*)malloc(sizeof(int)*n);
for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
tmp = k;
no = 1;
while (tmp > 0) {
tmp -= no;
no++;
}
no--;
tmp = k - ((no*(no - 1) / 2)) - 1;
printf("%d", arr[tmp]);
return 0;
} | |
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced. | Print the k-th pronounced identifier (assume that the numeration starts from 1). | C | 9ad07b42358e7f7cfa15ea382495a8a1 | db19329732a1210ccb614a557af91936 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1462464300 | ["2 2\n1 2", "4 5\n10 4 18 3"] | NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | PASSED | 1,000 | standard input | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different. | ["1", "4"] | #include<stdio.h>
int main()
{
long long n,p=0;
int f=0;
long long k,sum=0;
scanf("%lld%lld",&n,&k);
long long ar[n];
for(long long i=0;i<n;i++)
scanf("%lld",&ar[i]);
for(long long i=1;i<=n&&sum<k;i++)
{
sum=((i+1)*i)/2;
// printf("%lld\n",sum);
if(sum==k)
{
f=1;
p=i;
break;
}
else if(sum>k)
{
f=-1;
p=i;
break;
}
}
if(f==1)
{
printf("%lld",ar[p-1]);
}
else if(f==-1)
{
long long d=k-((p-1)*p)/2;
printf("%lld",ar[d-1]);
}
return 0;
} | |
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced. | Print the k-th pronounced identifier (assume that the numeration starts from 1). | C | 9ad07b42358e7f7cfa15ea382495a8a1 | eaf4533e6542243fcc5b90b7dee9ba6f | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1462464300 | ["2 2\n1 2", "4 5\n10 4 18 3"] | NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | PASSED | 1,000 | standard input | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different. | ["1", "4"] | #include <stdio.h>
#include <stdlib.h>
int n, i;
long long k, j, step;
long long id[100000];
long long result;
//B
int main()
{
scanf("%d", &n);
scanf("%I64d", &k);
for (i = 0; i < n; i++)
scanf("%I64d", &id[i]);
result = 0;
for (j = 1; j <= k; j++)
{
result += j;
step = j;
if (result >= k)
break;
}
while (result > k)
{
result--;
step--;
}
printf("%I64d", id[step-1]);
return 0;
}
| |
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced. | Print the k-th pronounced identifier (assume that the numeration starts from 1). | C | 9ad07b42358e7f7cfa15ea382495a8a1 | e36202364a12af475a072cee80646efe | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1462464300 | ["2 2\n1 2", "4 5\n10 4 18 3"] | NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | PASSED | 1,000 | standard input | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different. | ["1", "4"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int n,k,i,done=0;
scanf("%d%d",&n,&k);
int ide[100005];
for(i=0;i<n;i++)
scanf("%d",&ide[i]);
for(i=0;i<n;i++)
{
done=done+(i+1);
if(done>=k)
break;
}
done=done-(i+1);
i=k-done-1;
printf("%d",ide[i]);
return 0;
}
| |
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced. | Print the k-th pronounced identifier (assume that the numeration starts from 1). | C | 9ad07b42358e7f7cfa15ea382495a8a1 | 1d5748cc7f7000472dc74060557bdc5d | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1462464300 | ["2 2\n1 2", "4 5\n10 4 18 3"] | NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | PASSED | 1,000 | standard input | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different. | ["1", "4"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int n,k,i,done=0;
scanf("%d%d",&n,&k);
int ide[n];
for(i=0;i<n;i++)
scanf("%d",&ide[i]);
for(i=0;i<n;i++)
{
done=done+(i+1);
if(done>=k)
break;
}
done=done-(i+1);
i=k-done-1;
printf("%d",ide[i]);
return 0;
}
| |
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced. | Print the k-th pronounced identifier (assume that the numeration starts from 1). | C | 9ad07b42358e7f7cfa15ea382495a8a1 | 7c3a0bcac68ee155af647e579becfdea | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1462464300 | ["2 2\n1 2", "4 5\n10 4 18 3"] | NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | PASSED | 1,000 | standard input | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different. | ["1", "4"] | #include<stdio.h>
int main()
{
long n,k,i,j,t,sum=0;
long a[100005]={0};
scanf("%ld %ld",&n,&k);
for(i=1;i<=n;i++)
{
scanf("%ld",&a[i]);
}
for(i=0;i<=n;i++)
{
if((sum+i)>=k)
break;
else
sum+=i;
}
printf("%ld",a[k-sum]);
return 0;
} | |
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced. | Print the k-th pronounced identifier (assume that the numeration starts from 1). | C | 9ad07b42358e7f7cfa15ea382495a8a1 | 95688e22a1609a5ee4e9039b466fd546 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1462464300 | ["2 2\n1 2", "4 5\n10 4 18 3"] | NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | PASSED | 1,000 | standard input | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different. | ["1", "4"] | #include<stdio.h>
#include<math.h>
int main()
{
int n,k,i,ara[100000];
scanf("%d%d",&n,&k);
for(i=0;i<n;i++)
scanf("%d",&ara[i]);
i=1;
while(i<k)
{
k-=i;
i++;
}
printf("%d\n",ara[k-1]);
return 0;
}
| |
In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced. | Print the k-th pronounced identifier (assume that the numeration starts from 1). | C | 9ad07b42358e7f7cfa15ea382495a8a1 | 737a591f2c13cac313943587e3b1ccc6 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1462464300 | ["2 2\n1 2", "4 5\n10 4 18 3"] | NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | PASSED | 1,000 | standard input | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different. | ["1", "4"] | #include<stdio.h>
#include<string.h>
int main(void)
{
int i=0,a[100006],n,k,temp = 0;
int sum[100006]={0};
scanf("%d%d",&n,&k);
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
i=1;
sum[0]=0;
for(i=1;i<=n;i++)
{
sum[i] = sum[i-1] + i;
}
for(i=1;i<=n;i++)
{
if(sum[i]>=k)
{
temp = k-sum[i-1];
break;
}
}
printf("%d",a[temp]);
return 0;
}
| |
There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights. Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1] Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly k consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such k consecutive planks that the sum of their heights is minimal possible.Write the program that finds the indexes of k consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). | Print such integer j that the sum of the heights of planks j, j + 1, ..., j + k - 1 is the minimum possible. If there are multiple such j's, print any of them. | C | 69f4e340b3f6e1d807e0545ebea1fe2f | 52cf712d6607f30070e32073e03698d1 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"brute force"
] | 1384156800 | ["7 3\n1 2 6 1 1 7 1"] | NoteIn the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains integers n and k (1 ≤ n ≤ 1.5·105, 1 ≤ k ≤ n) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 100), where hi is the height of the i-th plank of the fence. | ["3"] | #include <stdio.h>
int main( void ) {
int i;
int n, k, h[ 150000 ], sum, min, idx;
scanf( "%d %d", &n, &k );
for ( i = 0; i < n; i++ )
scanf( "%d", h + i );
sum = 0;
for ( i = n - k; i < n; i++ )
sum += h[ i ];
min = sum;
idx = n - k;
for ( i = n - k - 1; i >= 0; i-- ) {
sum += h[ i ] - h[ i + k ];
if ( min > sum ) {
min = sum;
idx = i;
}
}
printf( "%d\n", idx + 1 );
return 0;
} | |
There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights. Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1] Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly k consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such k consecutive planks that the sum of their heights is minimal possible.Write the program that finds the indexes of k consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). | Print such integer j that the sum of the heights of planks j, j + 1, ..., j + k - 1 is the minimum possible. If there are multiple such j's, print any of them. | C | 69f4e340b3f6e1d807e0545ebea1fe2f | a1fdd12cf9953cec1f2c12ea1aeb3d77 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"brute force"
] | 1384156800 | ["7 3\n1 2 6 1 1 7 1"] | NoteIn the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains integers n and k (1 ≤ n ≤ 1.5·105, 1 ≤ k ≤ n) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 100), where hi is the height of the i-th plank of the fence. | ["3"] | #include <stdio.h>
int sum[ 150000 ];
int main( void ) {
int i;
int n, k, h[ 150000 ], min, idx;
scanf( "%d %d", &n, &k );
for ( i = 0; i < n; i++ )
scanf( "%d", h + i );
for ( i = n - k; i < n; i++ )
sum[ n - k ] += h[ i ];
for ( i = n - k - 1; i >= 0; i-- )
sum[ i ] = sum[ i + 1 ] - h[ i + k ] + h[ i ];
min = sum[ 0 ];
idx = 0;
for ( i = 1; i < n - k + 1; i++ )
if ( min > sum[ i ] ) {
min = sum[ i ];
idx = i;
}
printf( "%d\n", idx + 1 );
return 0;
} | |
There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights. Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1] Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly k consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such k consecutive planks that the sum of their heights is minimal possible.Write the program that finds the indexes of k consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). | Print such integer j that the sum of the heights of planks j, j + 1, ..., j + k - 1 is the minimum possible. If there are multiple such j's, print any of them. | C | 69f4e340b3f6e1d807e0545ebea1fe2f | 7654b361acf08df059bdfa48fb3cd22a | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"brute force"
] | 1384156800 | ["7 3\n1 2 6 1 1 7 1"] | NoteIn the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains integers n and k (1 ≤ n ≤ 1.5·105, 1 ≤ k ≤ n) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 100), where hi is the height of the i-th plank of the fence. | ["3"] | #include <stdio.h>
int main()
{
int num[200000], n, k, i, j, min=0, sum=0, index=1;
scanf("%d %d", &n, &k);
for(i=0;i<n;i++)
{
scanf("%d", &num[i]);
}
if(n==1)
{
printf("%d", n);
}
else
{
for(i=0;i<k;i++)
{
min+=num[i];
}
//printf("min %d\n", min);
sum=min;
for(i=k;i<n;i++)
{
sum=sum-num[i-k]+num[i];
//printf("sum %d, i %d\n", sum, i);
if(sum<min)
{
min=sum;
index=i-(k-2);
}
}
printf("%d", index);
}
return 0;
}
| |
There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights. Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1] Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly k consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such k consecutive planks that the sum of their heights is minimal possible.Write the program that finds the indexes of k consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). | Print such integer j that the sum of the heights of planks j, j + 1, ..., j + k - 1 is the minimum possible. If there are multiple such j's, print any of them. | C | 69f4e340b3f6e1d807e0545ebea1fe2f | 43e855bd5c19bf312f29360902c415fa | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"brute force"
] | 1384156800 | ["7 3\n1 2 6 1 1 7 1"] | NoteIn the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains integers n and k (1 ≤ n ≤ 1.5·105, 1 ≤ k ≤ n) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 100), where hi is the height of the i-th plank of the fence. | ["3"] | #include<stdio.h>
#include<stdlib.h>
int main() {
int nPlanks;
int piano;
int *plankHeights = malloc(150000 * sizeof(int));
int start;
int sum;
int i;
int windowSum;
scanf("%d%d", &nPlanks, &piano);
for (i=0; i<nPlanks; i++)
scanf("%d", plankHeights+i);
for (windowSum=0, start=1, i=0; i<piano; i++)
windowSum += plankHeights[i];
sum = windowSum;
for (i=1; i<=(nPlanks-piano); i++){
windowSum = windowSum - plankHeights[i-1] + plankHeights[i+piano-1];
if(windowSum < sum){
sum = windowSum;
start = i+1;
}
}
printf("%d\n",start);
return 0;
}
| |
There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights. Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1] Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly k consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such k consecutive planks that the sum of their heights is minimal possible.Write the program that finds the indexes of k consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). | Print such integer j that the sum of the heights of planks j, j + 1, ..., j + k - 1 is the minimum possible. If there are multiple such j's, print any of them. | C | 69f4e340b3f6e1d807e0545ebea1fe2f | 8fd8e1d738560a2372802726c7c75f5a | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"brute force"
] | 1384156800 | ["7 3\n1 2 6 1 1 7 1"] | NoteIn the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains integers n and k (1 ≤ n ≤ 1.5·105, 1 ≤ k ≤ n) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 100), where hi is the height of the i-th plank of the fence. | ["3"] | #include "stdio.h"
int main()
{
int n,k,i,x=0;
scanf("%d%d",&n,&k);
int h[n];long long sum[n+1],dp[n-k+2],minimum=10000000000000;sum[0]=0;
for(i=0;i<n;i++)
scanf("%d",&h[i]);
for(i=1;i<=n;i++)
sum[i]=sum[i-1]+h[i-1];
for(i=1;i<n-k+2;i++)
dp[i]=sum[i+k-1]-sum[i-1];
for(i=1;i<n-k+2;i++)
if(minimum>dp[i])
{
minimum=dp[i];
x=i;
}
printf("%d\n",x);
return 0;
} | |
There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights. Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1] Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly k consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such k consecutive planks that the sum of their heights is minimal possible.Write the program that finds the indexes of k consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). | Print such integer j that the sum of the heights of planks j, j + 1, ..., j + k - 1 is the minimum possible. If there are multiple such j's, print any of them. | C | 69f4e340b3f6e1d807e0545ebea1fe2f | 2c429cd16050e7632cf76a451019fa7d | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"brute force"
] | 1384156800 | ["7 3\n1 2 6 1 1 7 1"] | NoteIn the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains integers n and k (1 ≤ n ≤ 1.5·105, 1 ≤ k ≤ n) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 100), where hi is the height of the i-th plank of the fence. | ["3"] | #include<stdio.h>
#include<stdlib.h>
int planks[150009],sum[150009];
int main()
{
int i,n,k,sum1=0,min=100000000,res;
scanf("%d%d",&n,&k);
sum[0]=0;
for(i=1;i<=n;i++)
{
scanf("%d",&planks[i]);
}
for(i=1;i<k;i++){sum1=sum1+planks[i];sum[i]=0;}
for(i=k;i<=n;i++)
{
sum1=sum1+planks[i];
sum[i]=sum1;
sum1=sum1-planks[i-k+1];
}
for(i=k;i<=n;i++)
{
if(sum[i]<min){min=sum[i];res=i-k+1;}
}
printf("%d\n",res);
//system("pause");
return 0;
}
| |
There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights. Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1] Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly k consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such k consecutive planks that the sum of their heights is minimal possible.Write the program that finds the indexes of k consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). | Print such integer j that the sum of the heights of planks j, j + 1, ..., j + k - 1 is the minimum possible. If there are multiple such j's, print any of them. | C | 69f4e340b3f6e1d807e0545ebea1fe2f | 95a9e5901d0068cd65c024ba2537a33a | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"brute force"
] | 1384156800 | ["7 3\n1 2 6 1 1 7 1"] | NoteIn the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains integers n and k (1 ≤ n ≤ 1.5·105, 1 ≤ k ≤ n) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 100), where hi is the height of the i-th plank of the fence. | ["3"] | #include <stdio.h>
#include <limits.h>
int main()
{
int n, k, min, mini, i, sum;
scanf("%d %d", &n, &k);
int cdf[n+1];
cdf[0] = 0;
for (i = 1; i < n+1; i++) {
scanf("%d", &cdf[i]);
cdf[i] += cdf[i-1];
}
min = INT_MAX;
i = 1;
do {
sum = cdf[i+k-1] - cdf[i-1];
if (sum < min) {
mini = i;
min = sum;
}
i++;
} while (i <= (n+1)-k);
printf("%d\n", mini);
return 0;
}
| |
There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights. Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1] Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly k consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such k consecutive planks that the sum of their heights is minimal possible.Write the program that finds the indexes of k consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). | Print such integer j that the sum of the heights of planks j, j + 1, ..., j + k - 1 is the minimum possible. If there are multiple such j's, print any of them. | C | 69f4e340b3f6e1d807e0545ebea1fe2f | 6569a85b58cd1be2461854e3124afedb | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"brute force"
] | 1384156800 | ["7 3\n1 2 6 1 1 7 1"] | NoteIn the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains integers n and k (1 ≤ n ≤ 1.5·105, 1 ≤ k ≤ n) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 100), where hi is the height of the i-th plank of the fence. | ["3"] | #include<stdio.h>
int n,k,fnc[150003],min=0,sum=0,strt=0,end;
int main(){
int i,j,temp;
scanf("%d %d",&n,&k);
end=strt+k;
for(i=0;i<n;i++)scanf("%d ",&fnc[i]);
for(i=1;i<=end;i++)sum+=fnc[i];
//
min=sum;
for(i=1;n>end;i++){
sum-=fnc[i-1];
sum+=fnc[end];
/*
for(j=i;j<=end;j++){
sum+=fnc[j];
if(min<sum)break;
}
*/
if(sum<min){
min=sum;
strt=i;
}
//test
//printf("%d %d\n",min,sum);
end++;
}
//test
printf("%d",strt+1);
return 0;
} | |
There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights. Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1] Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly k consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such k consecutive planks that the sum of their heights is minimal possible.Write the program that finds the indexes of k consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). | Print such integer j that the sum of the heights of planks j, j + 1, ..., j + k - 1 is the minimum possible. If there are multiple such j's, print any of them. | C | 69f4e340b3f6e1d807e0545ebea1fe2f | 56664ee307265746f123d074613c2613 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"brute force"
] | 1384156800 | ["7 3\n1 2 6 1 1 7 1"] | NoteIn the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains integers n and k (1 ≤ n ≤ 1.5·105, 1 ≤ k ≤ n) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 100), where hi is the height of the i-th plank of the fence. | ["3"] | #include<stdio.h>
int sum(int a[],int i,int k){
int s=0,j;
for(j=i;j<i+k;j++)
s+=a[j];
return s;
}
int main(){
int n,i,j=0,mn,k,t;
scanf("%d %d",&n,&k);
int a[n];
for(i=0;i<n;i++)
scanf("%d",&a[i]);
t=sum(a,0,k),mn=t;
for(i=1;i+k-1<n;i++){
t=t+a[i+k-1]-a[i-1];
if(t<mn)
mn=t,j=i;
}
printf("%d",j+1);
return 0;
}
| |
There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights. Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1] Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly k consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such k consecutive planks that the sum of their heights is minimal possible.Write the program that finds the indexes of k consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). | Print such integer j that the sum of the heights of planks j, j + 1, ..., j + k - 1 is the minimum possible. If there are multiple such j's, print any of them. | C | 69f4e340b3f6e1d807e0545ebea1fe2f | 9ef384e3b2dc93e6601184ac674df093 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"brute force"
] | 1384156800 | ["7 3\n1 2 6 1 1 7 1"] | NoteIn the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains integers n and k (1 ≤ n ≤ 1.5·105, 1 ≤ k ≤ n) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 100), where hi is the height of the i-th plank of the fence. | ["3"] | #include<stdio.h>
int main(){
int n, k;
int menori, menor;
scanf("%d %d", &n, &k);
int heights[n];
int i;
for(i = 0; i < n; i++){
scanf("%d", &heights[i]);
}
if (k == 1){
menor = heights[1];
menori = 1;
for(i = 0; i < n; i ++){
if (menor > heights[i]){
menori = i;
menor = heights[i];
}
}
printf("%d", menori + 1);
} else {
int dp[n];
int sum;
sum = 0;
for(i = 0; i < k; i++){
sum = sum + heights[i];
}
dp[k - 1] = sum;
for(i = k; i < n; i++){
dp[i] = heights[i] + dp[i - 1] - heights[i - k];
}
menori = k - 1;
menor = sum;
for(i = k - 1; i < n; i ++){
if (menor > dp[i]){
menori = i;
menor = dp[i];
}
}
printf("%d", menori - k + 2);
}
return 0;
}
| |
There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights. Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1] Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly k consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such k consecutive planks that the sum of their heights is minimal possible.Write the program that finds the indexes of k consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). | Print such integer j that the sum of the heights of planks j, j + 1, ..., j + k - 1 is the minimum possible. If there are multiple such j's, print any of them. | C | 69f4e340b3f6e1d807e0545ebea1fe2f | 82bf593f2252e72710c2d6ae26033881 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"brute force"
] | 1384156800 | ["7 3\n1 2 6 1 1 7 1"] | NoteIn the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains integers n and k (1 ≤ n ≤ 1.5·105, 1 ≤ k ≤ n) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 100), where hi is the height of the i-th plank of the fence. | ["3"] | /*B*/
#include<stdio.h>
#define maxn 150000+1000
int main()
{
int n,k;
int h[maxn],s[maxn],a[maxn];
int min;
int ans;
while(scanf("%d%d",&n,&k)!=EOF)
{
int i;
for(i=0;i<n;i++)
scanf("%d",&h[i]);
s[0]=h[0];
for(i=1;i<n;i++)
s[i]=s[i-1]+h[i];
a[0]=s[k-1];
for(i=1;i<=n-k;i++)
a[i]=s[i+k-1]-s[i-1];
min=15000000+100;
for(i=0;i<=n-k;i++)
{
if(a[i]<min)
{
min=a[i];
ans=i;
}
}
printf("%d\n",ans+1);
}
return 0;
}
| |
There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights. Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1] Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly k consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such k consecutive planks that the sum of their heights is minimal possible.Write the program that finds the indexes of k consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). | Print such integer j that the sum of the heights of planks j, j + 1, ..., j + k - 1 is the minimum possible. If there are multiple such j's, print any of them. | C | 69f4e340b3f6e1d807e0545ebea1fe2f | 0d2229910072700aa70e5cc1c5693f17 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"brute force"
] | 1384156800 | ["7 3\n1 2 6 1 1 7 1"] | NoteIn the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains integers n and k (1 ≤ n ≤ 1.5·105, 1 ≤ k ≤ n) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 100), where hi is the height of the i-th plank of the fence. | ["3"] | #include <stdio.h>
int main()
{
long long i,n,k,min=15000001,ans;
int h;
scanf("%I64d %I64d",&n,&k);
long long sum[150005];
sum[0]=0;
for(i=1;i<=n;i++){
scanf("%d",&h);
sum[i]=sum[i-1]+h;
}
for(i=k;i<=n;i++){
if(sum[i]-sum[i-k]<min){
ans=i-k+1;
min=sum[i]-sum[i-k];
}
}
printf("%I64d",ans);
return 0;
} | |
There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights. Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1] Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly k consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such k consecutive planks that the sum of their heights is minimal possible.Write the program that finds the indexes of k consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). | Print such integer j that the sum of the heights of planks j, j + 1, ..., j + k - 1 is the minimum possible. If there are multiple such j's, print any of them. | C | 69f4e340b3f6e1d807e0545ebea1fe2f | e4a82faca80344b019fe3120999de4c6 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"brute force"
] | 1384156800 | ["7 3\n1 2 6 1 1 7 1"] | NoteIn the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains integers n and k (1 ≤ n ≤ 1.5·105, 1 ≤ k ≤ n) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 100), where hi is the height of the i-th plank of the fence. | ["3"] | #include<stdio.h>
int a[150005];
int main(){
int n,k,i;
scanf("%d%d",&n,&k);
for(i = 1;i <= n;i++){
scanf("%d",a+i);
a[i] += a[i-1];
}
int o = k;
for(i = k;i <= n;i++){
if(a[i]-a[i-k] < a[o]-a[o-k])
o = i;
}
printf("%d",o-k+1);
}
| |
There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights. Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1] Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly k consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such k consecutive planks that the sum of their heights is minimal possible.Write the program that finds the indexes of k consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). | Print such integer j that the sum of the heights of planks j, j + 1, ..., j + k - 1 is the minimum possible. If there are multiple such j's, print any of them. | C | 69f4e340b3f6e1d807e0545ebea1fe2f | 7e2b7c6eb0b86da72fd611abd9a114a9 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"brute force"
] | 1384156800 | ["7 3\n1 2 6 1 1 7 1"] | NoteIn the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains integers n and k (1 ≤ n ≤ 1.5·105, 1 ≤ k ≤ n) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 100), where hi is the height of the i-th plank of the fence. | ["3"] | #include <stdio.h>
int main(void)
{
int n,k,i,j,a[150010],sum[150010],flag;
while(scanf("%d%d",&n,&k)!=EOF)
{
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
sum[i]=0;
}
int min;
for(i=0;i<k;i++)
sum[0]+=a[i];
min=sum[0];
flag=0;
for(i=1;i<n-k+1;i++)
{
sum[i]=sum[i-1]-a[i-1]+a[k+i-1];
if(min>sum[i])
{
min=sum[i];
flag=i;
}
}
printf("%d\n",flag+1);
}
return 0;
}
| |
There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights. Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1] Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly k consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such k consecutive planks that the sum of their heights is minimal possible.Write the program that finds the indexes of k consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). | Print such integer j that the sum of the heights of planks j, j + 1, ..., j + k - 1 is the minimum possible. If there are multiple such j's, print any of them. | C | 69f4e340b3f6e1d807e0545ebea1fe2f | d9aa575908193756386f505e57673ffb | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"brute force"
] | 1384156800 | ["7 3\n1 2 6 1 1 7 1"] | NoteIn the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains integers n and k (1 ≤ n ≤ 1.5·105, 1 ≤ k ≤ n) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 100), where hi is the height of the i-th plank of the fence. | ["3"] | #include <stdio.h>
int solve(int n, int k, int a[])
{
int i, j;
i = 1;
j = k;
int sum = 0;
int it;
for (it = 0; it < k; ++it) {
sum += a[it];
}
int min_sum = sum;
int min_pos = 1;
while (j < n) {
sum += a[j];
sum -= a[i-1];
if (sum < min_sum) {
min_sum = sum;
min_pos = i+1;
}
++i;
++j;
}
return min_pos;
}
int main(void)
{
int n, k;
scanf("%d %d", &n, &k);
int a[n];
int i;
for (i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
printf("%d\n", solve(n, k, a));
return 0;
}
| |
There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights. Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1] Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly k consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such k consecutive planks that the sum of their heights is minimal possible.Write the program that finds the indexes of k consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). | Print such integer j that the sum of the heights of planks j, j + 1, ..., j + k - 1 is the minimum possible. If there are multiple such j's, print any of them. | C | 69f4e340b3f6e1d807e0545ebea1fe2f | 4e6222671b2de974fb8de9bc134efede | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"brute force"
] | 1384156800 | ["7 3\n1 2 6 1 1 7 1"] | NoteIn the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains integers n and k (1 ≤ n ≤ 1.5·105, 1 ≤ k ≤ n) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 100), where hi is the height of the i-th plank of the fence. | ["3"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int s[160000];
int main()
{
int n,k,i,j;
int min,sum,temp;
while(scanf("%d%d",&n,&k)!=EOF)
{
for(i=0; i<n; i++)
{
scanf("%d",&s[i]);
}
sum = 0;
for(i=0; i<k; i++)
{
sum += s[i];
temp = 1;
}
min = sum;
for(i=1; i<=n-k; i++)
{
sum -= s[i-1];
sum += s[i+k-1];
if(sum < min)
{
min = sum;
temp = i+1;
}
}
printf("%d\n",temp);
}
return 0;
}
| |
There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights. Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1] Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly k consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such k consecutive planks that the sum of their heights is minimal possible.Write the program that finds the indexes of k consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). | Print such integer j that the sum of the heights of planks j, j + 1, ..., j + k - 1 is the minimum possible. If there are multiple such j's, print any of them. | C | 69f4e340b3f6e1d807e0545ebea1fe2f | 7a03783dfb9fc4b5ae4ab929b6141026 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"brute force"
] | 1384156800 | ["7 3\n1 2 6 1 1 7 1"] | NoteIn the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains integers n and k (1 ≤ n ≤ 1.5·105, 1 ≤ k ≤ n) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 100), where hi is the height of the i-th plank of the fence. | ["3"] | #include <stdio.h>
int a[150005];
int main() {
int n, k;
int mid = 0;
scanf("%d%d", &n, &k);
for(int i = 0; i < n; i++) {
scanf("%d", a + i);
if(i < k)
mid += a[i];
}
int ans = 1, min = mid;
for(int i = k; i < n; i++) {
mid += a[i] - a[i - k];
if(min > mid) {
min = mid;
ans = i - k + 2;
}
}
printf("%d\n", ans);
return 0;
} | |
There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights. Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1] Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly k consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such k consecutive planks that the sum of their heights is minimal possible.Write the program that finds the indexes of k consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). | Print such integer j that the sum of the heights of planks j, j + 1, ..., j + k - 1 is the minimum possible. If there are multiple such j's, print any of them. | C | 69f4e340b3f6e1d807e0545ebea1fe2f | d8d5cd691fec10f57e98d900e76f9037 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"brute force"
] | 1384156800 | ["7 3\n1 2 6 1 1 7 1"] | NoteIn the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains integers n and k (1 ≤ n ≤ 1.5·105, 1 ≤ k ≤ n) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 100), where hi is the height of the i-th plank of the fence. | ["3"] | #include<stdio.h>
#define MAX 1500000
int main(){
long n,k,i,index=-1;
unsigned long long height[MAX],minHeight[MAX];
unsigned long long minHt=10000001;
scanf("%li",&n);
scanf("%li",&k);
for(i=0;i<n;i++)
scanf("%llu",&height[i]);
minHeight[0]=height[0];
for(i=1;i<k;i++){
minHeight[i]=minHeight[i-1]+height[i];
}
minHt=minHeight[k-1];
index=0;
for(i=k;i<n;i++){
minHeight[i]=height[i]+minHeight[i-1]-height[i-k];
if(minHeight[i]<minHt){
minHt=minHeight[i];
index=i-k+1;
}
}
printf("%li\n",(index+1));
return 0;
} | |
There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights. Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1] Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly k consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such k consecutive planks that the sum of their heights is minimal possible.Write the program that finds the indexes of k consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). | Print such integer j that the sum of the heights of planks j, j + 1, ..., j + k - 1 is the minimum possible. If there are multiple such j's, print any of them. | C | 69f4e340b3f6e1d807e0545ebea1fe2f | 0de6f008db2e7ff6bcdafe6e026e0cf7 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"brute force"
] | 1384156800 | ["7 3\n1 2 6 1 1 7 1"] | NoteIn the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains integers n and k (1 ≤ n ≤ 1.5·105, 1 ≤ k ≤ n) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 100), where hi is the height of the i-th plank of the fence. | ["3"] | #include <stdio.h>
#define MAX 150003
#define MIN 999999999
int main(){
int n, k, i, x, sum, poz = -1, min = MIN, j, v[MAX];
scanf("%d %d",&n,&k);
j = 0;
sum = 0;
for(i = 1;i <= n; ++i){
scanf("%d",&v[i]);
sum = sum + v[i];
++j;
if(j == k){
if(sum < min){
min = sum;
poz = i - k + 1;
}
--j;
sum = sum - v[i - k + 1];
}
}
printf("%d",poz);
}
| |
There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights. Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1] Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly k consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such k consecutive planks that the sum of their heights is minimal possible.Write the program that finds the indexes of k consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). | Print such integer j that the sum of the heights of planks j, j + 1, ..., j + k - 1 is the minimum possible. If there are multiple such j's, print any of them. | C | 69f4e340b3f6e1d807e0545ebea1fe2f | e30b6f09a3dbe3442724c9f38b666eb4 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"brute force"
] | 1384156800 | ["7 3\n1 2 6 1 1 7 1"] | NoteIn the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains integers n and k (1 ≤ n ≤ 1.5·105, 1 ≤ k ≤ n) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 100), where hi is the height of the i-th plank of the fence. | ["3"] | #include<stdio.h>
int num[10000005];
int main(){
int i,j,k,sum,n,a,b,temp;
scanf("%d%d",&n,&k);
j=1;
for(i=0;i<k;i++){
scanf("%d",&a);
sum+=a;
num[i]=a;
}
temp=sum;
for(;i<n;i++){
scanf("%d",&a);
num[i]=a;
if(sum+num[i]-num[i-k]<temp){
j=i-k+2;
temp=sum+num[i]-num[i-k];
}
sum=sum-num[i-k]+num[i];
}
printf("%d\n",j);
return 0;
}
| |
There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights. Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1] Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly k consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such k consecutive planks that the sum of their heights is minimal possible.Write the program that finds the indexes of k consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). | Print such integer j that the sum of the heights of planks j, j + 1, ..., j + k - 1 is the minimum possible. If there are multiple such j's, print any of them. | C | 69f4e340b3f6e1d807e0545ebea1fe2f | 2ea34cc5e0d91175e20f6055991e20a4 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"brute force"
] | 1384156800 | ["7 3\n1 2 6 1 1 7 1"] | NoteIn the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains integers n and k (1 ≤ n ≤ 1.5·105, 1 ≤ k ≤ n) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 100), where hi is the height of the i-th plank of the fence. | ["3"] | #include <stdio.h>
#include <stdlib.h>
#include <limits.h>
int a[150000];
int b[150000];
int main() {
int i;
int n, k;
int min = 0;
scanf("%d%d", &n, &k);
for (i = 0; i < n; i++) {
scanf("%d", a+i);
}
b[0] = 0;
for (i = 0; i < k; i++) {
b[0] += a[i];
}
for (i = 1; i < n-k+1; i++) {
b[i] = b[i-1] - a[i-1] + a[i+k-1];
if (b[i] < b[min]) {
min = i;
}
}
printf("%d\n", min+1);
return 0;
}
| |
There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights. Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1] Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly k consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such k consecutive planks that the sum of their heights is minimal possible.Write the program that finds the indexes of k consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). | Print such integer j that the sum of the heights of planks j, j + 1, ..., j + k - 1 is the minimum possible. If there are multiple such j's, print any of them. | C | 69f4e340b3f6e1d807e0545ebea1fe2f | 933a83a7121a24119b54cc787661a8c1 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"brute force"
] | 1384156800 | ["7 3\n1 2 6 1 1 7 1"] | NoteIn the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains integers n and k (1 ≤ n ≤ 1.5·105, 1 ≤ k ≤ n) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers h1, h2, ..., hn (1 ≤ hi ≤ 100), where hi is the height of the i-th plank of the fence. | ["3"] | #include<stdio.h>
int main() {
int sum=0,i,j,k,l,n,m,max=1000000000,a[200005],rem;
scanf("%d%d",&n,&k);
for(i=0;i<n;i++) {
scanf("%d",&a[i]);
sum += a[i];
if(i>=k-1) {
if(sum < max) {
max = sum;
rem = i-k+1;
}
sum -= a[i-k+1];
}
}
printf("%d\n",rem+1);
return 0;
} | |
There are $$$n$$$ left boots and $$$n$$$ right boots. Each boot has a color which is denoted as a lowercase Latin letter or a question mark ('?'). Thus, you are given two strings $$$l$$$ and $$$r$$$, both of length $$$n$$$. The character $$$l_i$$$ stands for the color of the $$$i$$$-th left boot and the character $$$r_i$$$ stands for the color of the $$$i$$$-th right boot.A lowercase Latin letter denotes a specific color, but the question mark ('?') denotes an indefinite color. Two specific colors are compatible if they are exactly the same. An indefinite color is compatible with any (specific or indefinite) color.For example, the following pairs of colors are compatible: ('f', 'f'), ('?', 'z'), ('a', '?') and ('?', '?'). The following pairs of colors are not compatible: ('f', 'g') and ('a', 'z').Compute the maximum number of pairs of boots such that there is one left and one right boot in a pair and their colors are compatible.Print the maximum number of such pairs and the pairs themselves. A boot can be part of at most one pair. | Print $$$k$$$ — the maximum number of compatible left-right pairs of boots, i.e. pairs consisting of one left and one right boot which have compatible colors. The following $$$k$$$ lines should contain pairs $$$a_j, b_j$$$ ($$$1 \le a_j, b_j \le n$$$). The $$$j$$$-th of these lines should contain the index $$$a_j$$$ of the left boot in the $$$j$$$-th pair and index $$$b_j$$$ of the right boot in the $$$j$$$-th pair. All the numbers $$$a_j$$$ should be distinct (unique), all the numbers $$$b_j$$$ should be distinct (unique). If there are many optimal answers, print any of them. | C | 6bf3e5a542ebce81c1e6ce7260644a3c | 9cea7c43c88c2f91833a68623804de2d | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"greedy"
] | 1553006100 | ["10\ncodeforces\ndodivthree", "7\nabaca?b\nzabbbcc", "9\nbambarbia\nhellocode", "10\ncode??????\n??????test"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 150000$$$), denoting the number of boots for each leg (i.e. the number of left boots and the number of right boots). The second line contains the string $$$l$$$ of length $$$n$$$. It contains only lowercase Latin letters or question marks. The $$$i$$$-th character stands for the color of the $$$i$$$-th left boot. The third line contains the string $$$r$$$ of length $$$n$$$. It contains only lowercase Latin letters or question marks. The $$$i$$$-th character stands for the color of the $$$i$$$-th right boot. | ["5\n7 8\n4 9\n2 2\n9 10\n3 1", "5\n6 5\n2 3\n4 6\n7 4\n1 2", "0", "10\n6 2\n1 6\n7 3\n3 5\n4 8\n9 7\n5 1\n2 4\n10 9\n8 10"] | #include<stdio.h>
#include<string.h>
#include<math.h>
struct xuexi {
int zhi;
int xian;
int wei[150000];
}aa[27][2];
int main(){
char a[150001],b[150001];
int chang,i;
int dnm[150000][2]={0},dui=0;
scanf("%d",&chang);
scanf("%s%s",a,b);
for(i=0;i<27;i++){
aa[i][0].zhi=0;
aa[i][1].zhi=0;
aa[i][0].xian=0;
aa[i][1].xian=0;
}
for(i=0;i<chang;i++){
if(a[i]!='?'){
aa[a[i]-'a'][0].wei[aa[a[i]-'a'][0].zhi]=i;
aa[a[i]-'a'][0].zhi++;
}
else if(a[i]=='?'){
aa[26][0].wei[aa[26][0].zhi]=i;
aa[26][0].zhi++;
}
if(b[i]!='?'){
aa[b[i]-'a'][1].wei[aa[b[i]-'a'][1].zhi]=i;
aa[b[i]-'a'][1].zhi++;
}
else if(b[i]=='?'){
aa[26][1].wei[aa[26][1].zhi]=i;
aa[26][1].zhi++;
}
}
for(i=0;i<26;i++){
if(aa[i][0].zhi==0||aa[i][1].zhi==0)continue;
else{
while(aa[i][0].xian<aa[i][0].zhi&&aa[i][1].xian<aa[i][1].zhi){
dnm[dui][0]=aa[i][0].wei[aa[i][0].xian++];
dnm[dui][1]=aa[i][1].wei[aa[i][1].xian++];
dui++;
}
}
}
i=0;
while(aa[26][0].zhi>0&&aa[26][0].xian<aa[26][0].zhi){
if(i==26)break;
if(aa[i][1].zhi==0||aa[i][1].xian==aa[i][1].zhi){
i+=1;
continue;
}
dnm[dui][0]=aa[26][0].wei[aa[26][0].xian++];
dnm[dui][1]=aa[i][1].wei[aa[i][1].xian++];
dui++;
}
i=0;
while(aa[26][1].zhi>0&&aa[26][1].xian<aa[26][1].zhi){
if(i==26)break;
if(aa[i][0].zhi==0||aa[i][0].xian==aa[i][0].zhi){
i+=1;
continue;
}
dnm[dui][1]=aa[26][1].wei[aa[26][1].xian++];
dnm[dui][0]=aa[i][0].wei[aa[i][0].xian++];
dui++;
}
while(aa[26][1].zhi>0&&aa[26][1].xian<aa[26][1].zhi&&aa[26][0].zhi>0&&aa[26][0].xian<aa[26][0].zhi){
dnm[dui][0]=aa[26][0].wei[aa[26][0].xian++];
dnm[dui][1]=aa[26][1].wei[aa[26][1].xian++];
dui++;
}
printf("%d\n",dui);
for(i=0;i<dui;i++){
printf("%d %d\n",dnm[i][0]+1,dnm[i][1]+1);
}
}
| |
There are $$$n$$$ left boots and $$$n$$$ right boots. Each boot has a color which is denoted as a lowercase Latin letter or a question mark ('?'). Thus, you are given two strings $$$l$$$ and $$$r$$$, both of length $$$n$$$. The character $$$l_i$$$ stands for the color of the $$$i$$$-th left boot and the character $$$r_i$$$ stands for the color of the $$$i$$$-th right boot.A lowercase Latin letter denotes a specific color, but the question mark ('?') denotes an indefinite color. Two specific colors are compatible if they are exactly the same. An indefinite color is compatible with any (specific or indefinite) color.For example, the following pairs of colors are compatible: ('f', 'f'), ('?', 'z'), ('a', '?') and ('?', '?'). The following pairs of colors are not compatible: ('f', 'g') and ('a', 'z').Compute the maximum number of pairs of boots such that there is one left and one right boot in a pair and their colors are compatible.Print the maximum number of such pairs and the pairs themselves. A boot can be part of at most one pair. | Print $$$k$$$ — the maximum number of compatible left-right pairs of boots, i.e. pairs consisting of one left and one right boot which have compatible colors. The following $$$k$$$ lines should contain pairs $$$a_j, b_j$$$ ($$$1 \le a_j, b_j \le n$$$). The $$$j$$$-th of these lines should contain the index $$$a_j$$$ of the left boot in the $$$j$$$-th pair and index $$$b_j$$$ of the right boot in the $$$j$$$-th pair. All the numbers $$$a_j$$$ should be distinct (unique), all the numbers $$$b_j$$$ should be distinct (unique). If there are many optimal answers, print any of them. | C | 6bf3e5a542ebce81c1e6ce7260644a3c | 5ad4200caf1b88dd71765f68f50afbf2 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"greedy"
] | 1553006100 | ["10\ncodeforces\ndodivthree", "7\nabaca?b\nzabbbcc", "9\nbambarbia\nhellocode", "10\ncode??????\n??????test"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 150000$$$), denoting the number of boots for each leg (i.e. the number of left boots and the number of right boots). The second line contains the string $$$l$$$ of length $$$n$$$. It contains only lowercase Latin letters or question marks. The $$$i$$$-th character stands for the color of the $$$i$$$-th left boot. The third line contains the string $$$r$$$ of length $$$n$$$. It contains only lowercase Latin letters or question marks. The $$$i$$$-th character stands for the color of the $$$i$$$-th right boot. | ["5\n7 8\n4 9\n2 2\n9 10\n3 1", "5\n6 5\n2 3\n4 6\n7 4\n1 2", "0", "10\n6 2\n1 6\n7 3\n3 5\n4 8\n9 7\n5 1\n2 4\n10 9\n8 10"] | #include<stdio.h>
int aaa[26][150001],bbb[26][150001];aa[26],bb[26],qi[150001],qj[150001],ii,jj,i,j,p[150001],r[150001],k=0,c;
int main()
{
int q;
scanf("%d ",&q);
char a[q+1],b[q+1];
scanf("%s %s",&a,&b);
for(i=0;i<q;i++)
{
if(a[i]=='?')
{
qi[ii++]=i;
}
else
{
aaa[a[i]-'a'][aa[a[i]-'a']++]=i;
}
if(b[i]=='?')
{
qj[jj++]=i;
}
else
{
bbb[b[i]-'a'][bb[b[i]-'a']++]=i;
}
}
for(c=0;c<26;c++)
{
while(aa[c]>0 && bb[c]>0)
{
p[k]=aaa[c][--aa[c]];
r[k]=bbb[c][--bb[c]];
k++;
}
}
for(c=0;c<26 && ii>0;)
{
while(c<26 && bb[c]<=0)
{
c++;
}
if(c<26)
{
r[k]=bbb[c][--bb[c]];
p[k]=qi[--ii];
k++;
}
}
for(c=0;c<26 && jj>0;)
{
while(c<26 && aa[c]<=0)
{
c++;
}
if(c<26)
{
p[k]=aaa[c][--aa[c]];
r[k]=qj[--jj];
k++;
}
}
while(ii>0 && jj>0)
{
p[k]=qi[--ii];
r[k]=qj[--jj];
k++;
}
printf("%d\n",k);
for(i=0;i<k;i++)
{
printf("%d %d\n",p[i]+1,r[i]+1);
}
}
| |
There are $$$n$$$ left boots and $$$n$$$ right boots. Each boot has a color which is denoted as a lowercase Latin letter or a question mark ('?'). Thus, you are given two strings $$$l$$$ and $$$r$$$, both of length $$$n$$$. The character $$$l_i$$$ stands for the color of the $$$i$$$-th left boot and the character $$$r_i$$$ stands for the color of the $$$i$$$-th right boot.A lowercase Latin letter denotes a specific color, but the question mark ('?') denotes an indefinite color. Two specific colors are compatible if they are exactly the same. An indefinite color is compatible with any (specific or indefinite) color.For example, the following pairs of colors are compatible: ('f', 'f'), ('?', 'z'), ('a', '?') and ('?', '?'). The following pairs of colors are not compatible: ('f', 'g') and ('a', 'z').Compute the maximum number of pairs of boots such that there is one left and one right boot in a pair and their colors are compatible.Print the maximum number of such pairs and the pairs themselves. A boot can be part of at most one pair. | Print $$$k$$$ — the maximum number of compatible left-right pairs of boots, i.e. pairs consisting of one left and one right boot which have compatible colors. The following $$$k$$$ lines should contain pairs $$$a_j, b_j$$$ ($$$1 \le a_j, b_j \le n$$$). The $$$j$$$-th of these lines should contain the index $$$a_j$$$ of the left boot in the $$$j$$$-th pair and index $$$b_j$$$ of the right boot in the $$$j$$$-th pair. All the numbers $$$a_j$$$ should be distinct (unique), all the numbers $$$b_j$$$ should be distinct (unique). If there are many optimal answers, print any of them. | C | 6bf3e5a542ebce81c1e6ce7260644a3c | f4617ed53688c0b67228bdf7705ac48e | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"greedy"
] | 1553006100 | ["10\ncodeforces\ndodivthree", "7\nabaca?b\nzabbbcc", "9\nbambarbia\nhellocode", "10\ncode??????\n??????test"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 150000$$$), denoting the number of boots for each leg (i.e. the number of left boots and the number of right boots). The second line contains the string $$$l$$$ of length $$$n$$$. It contains only lowercase Latin letters or question marks. The $$$i$$$-th character stands for the color of the $$$i$$$-th left boot. The third line contains the string $$$r$$$ of length $$$n$$$. It contains only lowercase Latin letters or question marks. The $$$i$$$-th character stands for the color of the $$$i$$$-th right boot. | ["5\n7 8\n4 9\n2 2\n9 10\n3 1", "5\n6 5\n2 3\n4 6\n7 4\n1 2", "0", "10\n6 2\n1 6\n7 3\n3 5\n4 8\n9 7\n5 1\n2 4\n10 9\n8 10"] | #include<stdio.h>
int aaa[26][150001],bbb[26][150000];aa[26],bb[26],qi[150001],qj[150001],ii,jj,i,j,p[150001],r[150001],k,c;
int main()
{
int q;
scanf("%d",&q);
char a[q+1],b[q+1];
scanf("%s %s",&a,&b);
for(i=0;i<q;i++)
{
if(a[i]=='?')
{
qi[ii++]=i;
}
else
{
aaa[a[i]-'a'][aa[a[i]-'a']++]=i;
}
if(b[i]=='?')
{
qj[jj++]=i;
}
else
{
bbb[b[i]-'a'][bb[b[i]-'a']++]=i;
}
}
for(c=0;c<26;c++)
{
while(aa[c]>0 && bb[c]>0)
{
p[k]=aaa[c][--aa[c]];
r[k]=bbb[c][--bb[c]];
k++;
}
}
for(c=0;c<26;c++)
{
if(aa[c]>bb[c])
while(aa[c]>bb[c] && jj>0)
{
p[k]=aaa[c][--aa[c]];
r[k]=qj[--jj];
k++;
}
}
for(c=0;c<26;c++)
{
if(aa[c]<bb[c])
while(aa[c]<bb[c] && ii>0)
{
r[k]=bbb[c][--bb[c]];
p[k]=qi[--ii];
k++;
}
}
while(ii>0 && jj>0)
{
p[k]=qi[--ii];
r[k]=qj[--jj];
k++;
}
printf("%d\n",k);
for(i=0;i<k;i++)
{
printf("%d %d\n",p[i]+1,r[i]+1);
}
}
| |
There are $$$n$$$ left boots and $$$n$$$ right boots. Each boot has a color which is denoted as a lowercase Latin letter or a question mark ('?'). Thus, you are given two strings $$$l$$$ and $$$r$$$, both of length $$$n$$$. The character $$$l_i$$$ stands for the color of the $$$i$$$-th left boot and the character $$$r_i$$$ stands for the color of the $$$i$$$-th right boot.A lowercase Latin letter denotes a specific color, but the question mark ('?') denotes an indefinite color. Two specific colors are compatible if they are exactly the same. An indefinite color is compatible with any (specific or indefinite) color.For example, the following pairs of colors are compatible: ('f', 'f'), ('?', 'z'), ('a', '?') and ('?', '?'). The following pairs of colors are not compatible: ('f', 'g') and ('a', 'z').Compute the maximum number of pairs of boots such that there is one left and one right boot in a pair and their colors are compatible.Print the maximum number of such pairs and the pairs themselves. A boot can be part of at most one pair. | Print $$$k$$$ — the maximum number of compatible left-right pairs of boots, i.e. pairs consisting of one left and one right boot which have compatible colors. The following $$$k$$$ lines should contain pairs $$$a_j, b_j$$$ ($$$1 \le a_j, b_j \le n$$$). The $$$j$$$-th of these lines should contain the index $$$a_j$$$ of the left boot in the $$$j$$$-th pair and index $$$b_j$$$ of the right boot in the $$$j$$$-th pair. All the numbers $$$a_j$$$ should be distinct (unique), all the numbers $$$b_j$$$ should be distinct (unique). If there are many optimal answers, print any of them. | C | 6bf3e5a542ebce81c1e6ce7260644a3c | 74b011eddbbf8d6cd35c1ba58e6f471e | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"greedy"
] | 1553006100 | ["10\ncodeforces\ndodivthree", "7\nabaca?b\nzabbbcc", "9\nbambarbia\nhellocode", "10\ncode??????\n??????test"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 150000$$$), denoting the number of boots for each leg (i.e. the number of left boots and the number of right boots). The second line contains the string $$$l$$$ of length $$$n$$$. It contains only lowercase Latin letters or question marks. The $$$i$$$-th character stands for the color of the $$$i$$$-th left boot. The third line contains the string $$$r$$$ of length $$$n$$$. It contains only lowercase Latin letters or question marks. The $$$i$$$-th character stands for the color of the $$$i$$$-th right boot. | ["5\n7 8\n4 9\n2 2\n9 10\n3 1", "5\n6 5\n2 3\n4 6\n7 4\n1 2", "0", "10\n6 2\n1 6\n7 3\n3 5\n4 8\n9 7\n5 1\n2 4\n10 9\n8 10"] | #include<stdio.h>
main()
{
int c[27][150000],d[27][150000],e[150000],f[150000],i,n,j,k[27]={0},l[27]={0},num=0,g=0,h=0,m;
char a[150000],b[150000];
scanf("%d",&n);
scanf("%s %s",&a,&b);
for(i=0;i<n;i++)
{
if((a[i]>='a')&&(a[i]<='z'))
{
j=a[i]-97;
}
else if(a[i]=='?')
{
j=26;
}
c[j][k[j]]=i;
k[j]++;
if((b[i]>='a')&&(b[i]<='z'))
{
j=b[i]-97;
}
else if(b[i]=='?')
{
j=26;
}
d[j][l[j]]=i;
l[j]++;
}
for(j=0;j<26;j++)
{
while((k[j]>0)&&(l[j]>0))
{
m=c[j][k[j]-1]+1;
e[num]=m;
k[j]--;
m=d[j][l[j]-1]+1;
f[num]=m;
l[j]--;
num++;
}
}
for(j=0;j<26;j++)
{
while((k[j]>0)&&(l[26]>0))
{
m=c[j][k[j]-1]+1;
e[num]=m;
k[j]--;
m=d[26][l[26]-1]+1;
f[num]=m;
l[26]--;
num++;
}
if(l[26]==0)
{
break;
}
}
for(j=0;j<26;j++)
{
while((l[j]>0)&&(k[26]>0))
{
m=c[26][k[26]-1]+1;
e[num]=m;
k[26]--;
m=d[j][l[j]-1]+1;
f[num]=m;
l[j]--;
num++;
}
if(k[26]==0)
{
break;
}
}
while((k[26]>0)&&(l[26]>0))
{
m=c[26][k[26]-1]+1;
e[num]=m;
k[26]--;
m=d[26][l[26]-1]+1;
f[num]=m;
l[26]--;
num++;
}
printf("%d\n",num);
for(i=0;i<num;i++)
{
printf("%d %d\n",e[i],f[i]);
}
}
| |
There are $$$n$$$ left boots and $$$n$$$ right boots. Each boot has a color which is denoted as a lowercase Latin letter or a question mark ('?'). Thus, you are given two strings $$$l$$$ and $$$r$$$, both of length $$$n$$$. The character $$$l_i$$$ stands for the color of the $$$i$$$-th left boot and the character $$$r_i$$$ stands for the color of the $$$i$$$-th right boot.A lowercase Latin letter denotes a specific color, but the question mark ('?') denotes an indefinite color. Two specific colors are compatible if they are exactly the same. An indefinite color is compatible with any (specific or indefinite) color.For example, the following pairs of colors are compatible: ('f', 'f'), ('?', 'z'), ('a', '?') and ('?', '?'). The following pairs of colors are not compatible: ('f', 'g') and ('a', 'z').Compute the maximum number of pairs of boots such that there is one left and one right boot in a pair and their colors are compatible.Print the maximum number of such pairs and the pairs themselves. A boot can be part of at most one pair. | Print $$$k$$$ — the maximum number of compatible left-right pairs of boots, i.e. pairs consisting of one left and one right boot which have compatible colors. The following $$$k$$$ lines should contain pairs $$$a_j, b_j$$$ ($$$1 \le a_j, b_j \le n$$$). The $$$j$$$-th of these lines should contain the index $$$a_j$$$ of the left boot in the $$$j$$$-th pair and index $$$b_j$$$ of the right boot in the $$$j$$$-th pair. All the numbers $$$a_j$$$ should be distinct (unique), all the numbers $$$b_j$$$ should be distinct (unique). If there are many optimal answers, print any of them. | C | 6bf3e5a542ebce81c1e6ce7260644a3c | 2eda4a182adb28d4dc1cb486305e98bb | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"greedy"
] | 1553006100 | ["10\ncodeforces\ndodivthree", "7\nabaca?b\nzabbbcc", "9\nbambarbia\nhellocode", "10\ncode??????\n??????test"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 150000$$$), denoting the number of boots for each leg (i.e. the number of left boots and the number of right boots). The second line contains the string $$$l$$$ of length $$$n$$$. It contains only lowercase Latin letters or question marks. The $$$i$$$-th character stands for the color of the $$$i$$$-th left boot. The third line contains the string $$$r$$$ of length $$$n$$$. It contains only lowercase Latin letters or question marks. The $$$i$$$-th character stands for the color of the $$$i$$$-th right boot. | ["5\n7 8\n4 9\n2 2\n9 10\n3 1", "5\n6 5\n2 3\n4 6\n7 4\n1 2", "0", "10\n6 2\n1 6\n7 3\n3 5\n4 8\n9 7\n5 1\n2 4\n10 9\n8 10"] | # include <stdio.h>
# include <string.h>
struct xiezi
{
int bian[150000];
int shu;
int xz;
} zuo[27],you[27];
int s1[150000];
int s2[150000];
int main ()
{
int i,j,k,s,n,a,b,c,d;
char f;
for(i=0;i<27;i++)
{
zuo[i].shu=0;
you[i].shu=0;
zuo[i].xz=0;
you[i].xz=0;
}
scanf("%d",&n);
getchar();
for(i=1;i<=n;i++)
{
f=getchar();
if(f=='?')
a=26;
else
a=f-'a';
zuo[a].bian[zuo[a].shu]=i;
zuo[a].shu++;
}
getchar();
for(i=1;i<=n;i++)
{
f=getchar();
if(f=='?')
a=26;
else
a=f-'a';
you[a].bian[you[a].shu]=i;
you[a].shu++;
}
s=0;
for(i=0;i<=26;i++)
{
if(zuo[i].shu!=0&&you[i].shu!=0)
{
a=zuo[i].shu;
if(you[i].shu<a)
a=you[i].shu;
c=0;
for(j=s;j<(s+a);j++)
{
s1[j]=zuo[i].bian[zuo[i].xz+c];
s2[j]=you[i].bian[you[i].xz+c];
c++;
}
s=s+a;
zuo[i].shu=zuo[i].shu-a;
you[i].shu=you[i].shu-a;
you[i].xz=you[i].xz+a;
zuo[i].xz=zuo[i].xz+a;
if(zuo[i].shu>you[i].shu)
{
if(you[26].shu!=0)
{
a=zuo[i].shu;
if(you[26].shu<a)
a=you[26].shu;
you[26].shu=you[26].shu-a;
zuo[i].shu=zuo[i].shu-a;
c=0;
for(j=s;j<(s+a);j++)
{
s1[j]=zuo[i].bian[zuo[i].xz+c];
s2[j]=you[26].bian[you[26].xz+c];
c++;
}
s=s+a;
you[26].xz=you[26].xz+a;
zuo[i].xz=zuo[i].xz+a;
}
continue;
}
else if(you[i].shu>zuo[i].shu)
{
if(zuo[26].shu!=0)
{
a=you[i].shu;
if(zuo[26].shu<a)
a=zuo[26].shu;
zuo[26].shu=zuo[26].shu-a;
you[i].shu=you[i].shu-a;
c=0;
for(j=s;j<(s+a);j++)
{
s2[j]=you[i].bian[you[i].xz+c];
s1[j]=zuo[26].bian[zuo[26].xz+c];
c++;
}
s=s+a;
zuo[26].xz=zuo[26].xz+a;
you[i].xz=you[i].xz+a;
}
continue;
}
continue;
}
else if(zuo[i].shu!=0&&you[i].shu==0&&you[26].shu!=0)
{
a=zuo[i].shu;
if(you[26].shu<a)
a=you[26].shu;
you[26].shu=you[26].shu-a;
zuo[i].shu=zuo[i].shu-a;
c=0;
for(j=s;j<(s+a);j++)
{
s1[j]=zuo[i].bian[zuo[i].xz+c];
s2[j]=you[26].bian[you[26].xz+c];
c++;
}
s=s+a;
you[26].xz=you[26].xz+a;
zuo[i].xz=zuo[i].xz+a;
continue;
}
else if(zuo[i].shu==0&&you[i].shu!=0&&zuo[26].shu!=0)
{
a=you[i].shu;
if(zuo[26].shu<a)
a=zuo[26].shu;
zuo[26].shu=zuo[26].shu-a;
you[i].shu=you[i].shu-a;
c=0;
for(j=s;j<(s+a);j++)
{
s2[j]=you[i].bian[you[i].xz+c];
s1[j]=zuo[26].bian[zuo[26].xz+c];
c++;
}
s=s+a;
zuo[26].xz=zuo[26].xz+a;
you[i].xz=you[i].xz+a;
continue;
}
}
printf("%d",s);
for(i=0;i<s;i++)
{
printf("\n");
printf("%d %d",s1[i],s2[i]);
}
return 0;
} | |
There are $$$n$$$ left boots and $$$n$$$ right boots. Each boot has a color which is denoted as a lowercase Latin letter or a question mark ('?'). Thus, you are given two strings $$$l$$$ and $$$r$$$, both of length $$$n$$$. The character $$$l_i$$$ stands for the color of the $$$i$$$-th left boot and the character $$$r_i$$$ stands for the color of the $$$i$$$-th right boot.A lowercase Latin letter denotes a specific color, but the question mark ('?') denotes an indefinite color. Two specific colors are compatible if they are exactly the same. An indefinite color is compatible with any (specific or indefinite) color.For example, the following pairs of colors are compatible: ('f', 'f'), ('?', 'z'), ('a', '?') and ('?', '?'). The following pairs of colors are not compatible: ('f', 'g') and ('a', 'z').Compute the maximum number of pairs of boots such that there is one left and one right boot in a pair and their colors are compatible.Print the maximum number of such pairs and the pairs themselves. A boot can be part of at most one pair. | Print $$$k$$$ — the maximum number of compatible left-right pairs of boots, i.e. pairs consisting of one left and one right boot which have compatible colors. The following $$$k$$$ lines should contain pairs $$$a_j, b_j$$$ ($$$1 \le a_j, b_j \le n$$$). The $$$j$$$-th of these lines should contain the index $$$a_j$$$ of the left boot in the $$$j$$$-th pair and index $$$b_j$$$ of the right boot in the $$$j$$$-th pair. All the numbers $$$a_j$$$ should be distinct (unique), all the numbers $$$b_j$$$ should be distinct (unique). If there are many optimal answers, print any of them. | C | 6bf3e5a542ebce81c1e6ce7260644a3c | 9b5667c3900fede27b1ee4046621c780 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"greedy"
] | 1553006100 | ["10\ncodeforces\ndodivthree", "7\nabaca?b\nzabbbcc", "9\nbambarbia\nhellocode", "10\ncode??????\n??????test"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 150000$$$), denoting the number of boots for each leg (i.e. the number of left boots and the number of right boots). The second line contains the string $$$l$$$ of length $$$n$$$. It contains only lowercase Latin letters or question marks. The $$$i$$$-th character stands for the color of the $$$i$$$-th left boot. The third line contains the string $$$r$$$ of length $$$n$$$. It contains only lowercase Latin letters or question marks. The $$$i$$$-th character stands for the color of the $$$i$$$-th right boot. | ["5\n7 8\n4 9\n2 2\n9 10\n3 1", "5\n6 5\n2 3\n4 6\n7 4\n1 2", "0", "10\n6 2\n1 6\n7 3\n3 5\n4 8\n9 7\n5 1\n2 4\n10 9\n8 10"] | # include <stdio.h>
# include <string.h>
struct xiezi
{
int bian[150000];
int shu;
int xz;
int ss
} zuo[27],you[27];
int s1[150000];
int s2[150000];
int main ()
{
int i,j,k,s,n,a,b,c,d;
char f;
for(i=0;i<27;i++)
{
zuo[i].shu=0;
you[i].shu=0;
zuo[i].xz=0;
you[i].xz=0;
}
scanf("%d",&n);
getchar();
for(i=1;i<=n;i++)
{
f=getchar();
if(f=='?')
a=26;
else
a=f-'a';
zuo[a].bian[zuo[a].shu]=i;
zuo[a].shu++;
}
getchar();
for(i=1;i<=n;i++)
{
f=getchar();
if(f=='?')
a=26;
else
a=f-'a';
you[a].bian[you[a].shu]=i;
you[a].shu++;
}
s=0;
for(i=0;i<=26;i++)
{
if(zuo[i].shu!=0&&you[i].shu!=0)
{
a=zuo[i].shu;
if(you[i].shu<a)
a=you[i].shu;
c=0;
for(j=s;j<(s+a);j++)
{
s1[j]=zuo[i].bian[zuo[i].xz+c];
s2[j]=you[i].bian[you[i].xz+c];
c++;
}
s=s+a;
zuo[i].shu=zuo[i].shu-a;
you[i].shu=you[i].shu-a;
you[i].xz=you[i].xz+a;
zuo[i].xz=zuo[i].xz+a;
if(zuo[i].shu>you[i].shu)
{
if(you[26].shu!=0)
{
a=zuo[i].shu;
if(you[26].shu<a)
a=you[26].shu;
you[26].shu=you[26].shu-a;
zuo[i].shu=zuo[i].shu-a;
c=0;
for(j=s;j<(s+a);j++)
{
s1[j]=zuo[i].bian[zuo[i].xz+c];
s2[j]=you[26].bian[you[26].xz+c];
c++;
}
s=s+a;
you[26].xz=you[26].xz+a;
zuo[i].xz=zuo[i].xz+a;
}
continue;
}
else if(you[i].shu>zuo[i].shu)
{
if(zuo[26].shu!=0)
{
a=you[i].shu;
if(zuo[26].shu<a)
a=zuo[26].shu;
zuo[26].shu=zuo[26].shu-a;
you[i].shu=you[i].shu-a;
c=0;
for(j=s;j<(s+a);j++)
{
s2[j]=you[i].bian[you[i].xz+c];
s1[j]=zuo[26].bian[zuo[26].xz+c];
c++;
}
s=s+a;
zuo[26].xz=zuo[26].xz+a;
you[i].xz=you[i].xz+a;
}
continue;
}
continue;
}
else if(zuo[i].shu!=0&&you[i].shu==0&&you[26].shu!=0)
{
a=zuo[i].shu;
if(you[26].shu<a)
a=you[26].shu;
you[26].shu=you[26].shu-a;
zuo[i].shu=zuo[i].shu-a;
c=0;
for(j=s;j<(s+a);j++)
{
s1[j]=zuo[i].bian[zuo[i].xz+c];
s2[j]=you[26].bian[you[26].xz+c];
c++;
}
s=s+a;
you[26].xz=you[26].xz+a;
zuo[i].xz=zuo[i].xz+a;
continue;
}
else if(zuo[i].shu==0&&you[i].shu!=0&&zuo[26].shu!=0)
{
a=you[i].shu;
if(zuo[26].shu<a)
a=zuo[26].shu;
zuo[26].shu=zuo[26].shu-a;
you[i].shu=you[i].shu-a;
c=0;
for(j=s;j<(s+a);j++)
{
s2[j]=you[i].bian[you[i].xz+c];
s1[j]=zuo[26].bian[zuo[26].xz+c];
c++;
}
s=s+a;
zuo[26].xz=zuo[26].xz+a;
you[i].xz=you[i].xz+a;
continue;
}
}
printf("%d",s);
for(i=0;i<s;i++)
{
printf("\n");
printf("%d %d",s1[i],s2[i]);
}
return 0;
} | |
There are $$$n$$$ left boots and $$$n$$$ right boots. Each boot has a color which is denoted as a lowercase Latin letter or a question mark ('?'). Thus, you are given two strings $$$l$$$ and $$$r$$$, both of length $$$n$$$. The character $$$l_i$$$ stands for the color of the $$$i$$$-th left boot and the character $$$r_i$$$ stands for the color of the $$$i$$$-th right boot.A lowercase Latin letter denotes a specific color, but the question mark ('?') denotes an indefinite color. Two specific colors are compatible if they are exactly the same. An indefinite color is compatible with any (specific or indefinite) color.For example, the following pairs of colors are compatible: ('f', 'f'), ('?', 'z'), ('a', '?') and ('?', '?'). The following pairs of colors are not compatible: ('f', 'g') and ('a', 'z').Compute the maximum number of pairs of boots such that there is one left and one right boot in a pair and their colors are compatible.Print the maximum number of such pairs and the pairs themselves. A boot can be part of at most one pair. | Print $$$k$$$ — the maximum number of compatible left-right pairs of boots, i.e. pairs consisting of one left and one right boot which have compatible colors. The following $$$k$$$ lines should contain pairs $$$a_j, b_j$$$ ($$$1 \le a_j, b_j \le n$$$). The $$$j$$$-th of these lines should contain the index $$$a_j$$$ of the left boot in the $$$j$$$-th pair and index $$$b_j$$$ of the right boot in the $$$j$$$-th pair. All the numbers $$$a_j$$$ should be distinct (unique), all the numbers $$$b_j$$$ should be distinct (unique). If there are many optimal answers, print any of them. | C | 6bf3e5a542ebce81c1e6ce7260644a3c | 1c16021c51f90e6c7bb6b4bc387319b6 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"greedy"
] | 1553006100 | ["10\ncodeforces\ndodivthree", "7\nabaca?b\nzabbbcc", "9\nbambarbia\nhellocode", "10\ncode??????\n??????test"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains $$$n$$$ ($$$1 \le n \le 150000$$$), denoting the number of boots for each leg (i.e. the number of left boots and the number of right boots). The second line contains the string $$$l$$$ of length $$$n$$$. It contains only lowercase Latin letters or question marks. The $$$i$$$-th character stands for the color of the $$$i$$$-th left boot. The third line contains the string $$$r$$$ of length $$$n$$$. It contains only lowercase Latin letters or question marks. The $$$i$$$-th character stands for the color of the $$$i$$$-th right boot. | ["5\n7 8\n4 9\n2 2\n9 10\n3 1", "5\n6 5\n2 3\n4 6\n7 4\n1 2", "0", "10\n6 2\n1 6\n7 3\n3 5\n4 8\n9 7\n5 1\n2 4\n10 9\n8 10"] | #include <stdio.h>
int vr[27][150000], vl[27][150000], pr[27]={0}, pl[27]={0};
int main()
{
int n, i, j, rc[26]={0}, lc[26]={0}, rw=0, lw=0, c=0, x;
scanf("%d", &n);
char r[150001], l[150001];
scanf("%s ", r);
scanf(" %s", l);
for(i=0; i<n; i++){
if(r[i]=='?'){
rw++;
x=26;
}
if(r[i]!='?'){
x=r[i]-'a';
rc[r[i]-'a']++;
}
vr[x][pr[x]]=i;
pr[x]++;
if(l[i]=='?'){
lw++;
x=26;
}
if(l[i]!='?'){
x=l[i]-'a';
lc[l[i]-'a']++;
}
vl[x][pl[x]]=i;
pl[x]++;
}
for(i=0; i<26; i++){
if(rc[i]>=lc[i]){
c=c+lc[i];
continue;
}
c=c+rc[i];
}
c=c+lw+rw;
if(c>=n){
c=n;
}
printf("%d\n", c);
//for print
for(i=0; i<26; i++){
while(pl[i]>0 && pr[i]>0){
printf("%d %d\n", vr[i][pr[i]-1]+1, vl[i][pl[i]-1]+1);
pr[i]--;
pl[i]--;
}
}
x=26;
for(i=0; i<26; i++){
while(pl[x]>0 && pr[i]>0){
printf("%d %d\n", vr[i][pr[i]-1]+1, vl[x][pl[x]-1]+1);
pr[i]--;
pl[x]--;
}
if(pl[x]==0){
break;
}
}
for(i=0; i<26; i++){
while(pl[i]>0 && pr[x]>0){
printf("%d %d\n", vr[x][pr[x]-1]+1, vl[i][pl[i]-1]+1);
pr[x]--;
pl[i]--;
}
if(pr[x]==0){
break;
}
}
while(pl[x]>0 && pr[x]>0){
printf("%d %d\n", vr[x][pr[x]-1]+1, vl[x][pl[x]-1]+1);
pr[x]--;
pl[i]--;
}
return 0;
}
| |
You desperately need to build some string t. For that you've got n more strings s1, s2, ..., sn. To build string t, you are allowed to perform exactly |t| (|t| is the length of string t) operations on these strings. Each operation looks like that: choose any non-empty string from strings s1, s2, ..., sn; choose an arbitrary character from the chosen string and write it on a piece of paper; remove the chosen character from the chosen string. Note that after you perform the described operation, the total number of characters in strings s1, s2, ..., sn decreases by 1. We are assumed to build string t, if the characters, written on the piece of paper, in the order of performed operations form string t.There are other limitations, though. For each string si you know number ai — the maximum number of characters you are allowed to delete from string si. You also know that each operation that results in deleting a character from string si, costs i rubles. That is, an operation on string s1 is the cheapest (it costs 1 ruble), and the operation on string sn is the most expensive one (it costs n rubles).Your task is to count the minimum amount of money (in rubles) you will need to build string t by the given rules. Consider the cost of building string t to be the sum of prices of the operations you use. | Print a single number — the minimum money (in rubles) you need in order to build string t. If there is no solution, print -1. | C | adc23c13988fc955f4589c88829ef0e7 | 9c3425c6b6ba1b70882885d73843d858 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"flows",
"graphs"
] | 1351179000 | ["bbaze\n3\nbzb 2\naeb 3\nba 10", "abacaba\n4\naba 2\nbcc 1\ncaa 2\nbbb 5", "xyz\n4\naxx 8\nza 1\nefg 4\nt 1"] | NoteNotes to the samples:In the first sample from the first string you should take characters "b" and "z" with price 1 ruble, from the second string characters "a", "e" и "b" with price 2 rubles. The price of the string t in this case is 2·1 + 3·2 = 8.In the second sample from the first string you should take two characters "a" with price 1 ruble, from the second string character "c" with price 2 rubles, from the third string two characters "a" with price 3 rubles, from the fourth string two characters "b" with price 4 rubles. The price of the string t in this case is 2·1 + 1·2 + 2·3 + 2·4 = 18.In the third sample the solution doesn't exist because there is no character "y" in given strings. | PASSED | 2,000 | standard input | 2 seconds | The first line of the input contains string t — the string that you need to build. The second line contains a single integer n (1 ≤ n ≤ 100) — the number of strings to which you are allowed to apply the described operation. Each of the next n lines contains a string and an integer. The i-th line contains space-separated string si and integer ai (0 ≤ ai ≤ 100). Number ai represents the maximum number of characters that can be deleted from string si. All strings in the input only consist of lowercase English letters. All strings are non-empty. The lengths of all strings do not exceed 100 characters. | ["8", "18", "-1"] | #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAXN 210
#define MAXL 110
#define SNK 209
#define SRC 0
typedef struct edge{
int cap;
int cost;
int from;
int to;
struct edge *back_edge;
struct edge *next;
}edge;
edge *g[MAXN];
char niz[MAXN][MAXL];
int letters[255];
edge* from[MAXN];
int d[MAXN];
int q[MAXN*MAXN];
edge* add_edge(int x, int y, int cap, int cost);
void dijkstra(int start, int dest);
int main()
{
int n;
char t[MAXL];
int i, j;
edge *a, *b;
scanf("%s", t);
for (i=0;i<strlen(t);i++)
letters[(int)t[i]]++;
scanf("%d", &n);
for (i=1;i<=n;i++)
{
int x;
scanf("%s %d", niz[i], &x);
a = add_edge(SRC, i, x, i);
b = add_edge(i, SRC, 0, -i);
a->back_edge = b;
b->back_edge = a;
}
for(i=1;i<=n;i++)
{
int tl[255];
memset(tl,0,sizeof(tl));
for (j=0;j<strlen(niz[i]);j++)
tl[(int)niz[i][j]]++;
for (j='a';j<='z';j++)
if (tl[j] && letters[j])
{
a = add_edge(i, n+j-'a'+1, tl[j], 0);
b = add_edge(n+j-'a'+1, i, 0, 0);
a->back_edge = b;
b->back_edge = a;
}
}
for(i='a';i<='z';i++)
{
if (!letters[i]) continue;
a = add_edge(n+i-'a'+1, SNK, letters[i], 0);
b = add_edge(SNK, n+i-'a'+1, 0, 0);
a->back_edge = b;
b->back_edge = a;
}
int result = 0;
int flow = 0;
while(1)
{
dijkstra(SRC, SNK);
if (from[SNK] == NULL) break;
int x = SNK;
int cap = 100000;
while (from[x] != NULL)
{
cap = (cap>from[x]->cap)?from[x]->cap:cap;
x = from[x]->from;
}
flow += cap;
result += d[SNK] * cap;
x = SNK;
while (from[x] != NULL)
{
from[x]->cap -= cap;
from[x]->back_edge->cap += cap;
x = from[x]->from;
}
}
if (flow == strlen(t))
{
printf("%d\n", result);
}
else printf("-1\n");
edge *c, *d;
for (i=0;i<MAXN;i++)
{
if (g[i]==NULL) continue;
c = g[i];
d = c->next;
free(c);
}
return 0;
}
edge* add_edge(int x, int y, int cap, int cost)
{
if (g[x]==NULL)
{
g[x] = (edge*)calloc(1, sizeof(edge));
g[x]->from = x;
g[x]->to = y;
g[x]->cap = cap;
g[x]->cost = cost;
g[x]->next = NULL;
}
else
{
edge *t = (edge*)calloc(1, sizeof(edge));
t->from = x;
t->to = y;
t->cap = cap;
t->cost = cost;
t->next = g[x];
g[x] = t;
}
return g[x];
}
void dijkstra(int start, int dest)
{
int i, x, p, k;
edge *e;
for (i=0;i<MAXN;i++) d[i] = 100000;
d[start] = 0;
from[start] = NULL;
from[dest] = NULL;
p = k = 1;
q[k++] = start;
for (;p!=k;p++)
{
x = q[p];
e = g[x];
while (e!=NULL)
{
if (d[e->to] > d[x] + e->cost && e->cap > 0 && e->to != SRC)
{
d[e->to] = d[x] + e->cost;
from[e->to] = e;
q[k++] = e->to;
}
e = e->next;
}
}
} | |
You desperately need to build some string t. For that you've got n more strings s1, s2, ..., sn. To build string t, you are allowed to perform exactly |t| (|t| is the length of string t) operations on these strings. Each operation looks like that: choose any non-empty string from strings s1, s2, ..., sn; choose an arbitrary character from the chosen string and write it on a piece of paper; remove the chosen character from the chosen string. Note that after you perform the described operation, the total number of characters in strings s1, s2, ..., sn decreases by 1. We are assumed to build string t, if the characters, written on the piece of paper, in the order of performed operations form string t.There are other limitations, though. For each string si you know number ai — the maximum number of characters you are allowed to delete from string si. You also know that each operation that results in deleting a character from string si, costs i rubles. That is, an operation on string s1 is the cheapest (it costs 1 ruble), and the operation on string sn is the most expensive one (it costs n rubles).Your task is to count the minimum amount of money (in rubles) you will need to build string t by the given rules. Consider the cost of building string t to be the sum of prices of the operations you use. | Print a single number — the minimum money (in rubles) you need in order to build string t. If there is no solution, print -1. | C | adc23c13988fc955f4589c88829ef0e7 | 58da4dcebca3eeffeeaa02fbd6c6e369 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"flows",
"graphs"
] | 1351179000 | ["bbaze\n3\nbzb 2\naeb 3\nba 10", "abacaba\n4\naba 2\nbcc 1\ncaa 2\nbbb 5", "xyz\n4\naxx 8\nza 1\nefg 4\nt 1"] | NoteNotes to the samples:In the first sample from the first string you should take characters "b" and "z" with price 1 ruble, from the second string characters "a", "e" и "b" with price 2 rubles. The price of the string t in this case is 2·1 + 3·2 = 8.In the second sample from the first string you should take two characters "a" with price 1 ruble, from the second string character "c" with price 2 rubles, from the third string two characters "a" with price 3 rubles, from the fourth string two characters "b" with price 4 rubles. The price of the string t in this case is 2·1 + 1·2 + 2·3 + 2·4 = 18.In the third sample the solution doesn't exist because there is no character "y" in given strings. | PASSED | 2,000 | standard input | 2 seconds | The first line of the input contains string t — the string that you need to build. The second line contains a single integer n (1 ≤ n ≤ 100) — the number of strings to which you are allowed to apply the described operation. Each of the next n lines contains a string and an integer. The i-th line contains space-separated string si and integer ai (0 ≤ ai ≤ 100). Number ai represents the maximum number of characters that can be deleted from string si. All strings in the input only consist of lowercase English letters. All strings are non-empty. The lengths of all strings do not exceed 100 characters. | ["8", "18", "-1"] | #include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
typedef struct struct_listgraphintcostintflow{
int node, nodeMemory;
int *edgeSize, *edgeMemory;
int **edge, **cost, **flow, **reverse;
} ListGraphIntCostIntFlow;
ListGraphIntCostIntFlow NewListGraphIntCostIntFlow(int maxNode,int maxDegree){
int i; ListGraphIntCostIntFlow res;
res.node=0; res.nodeMemory=maxNode;
res.edgeSize = (int*)malloc(maxNode*sizeof(int));
res.edgeMemory = (int*)malloc(maxNode*sizeof(int));
res.edge = (int**)malloc(maxNode*sizeof(int*));
res.cost = (int**)malloc(maxNode*sizeof(int*));
res.flow = (int**)malloc(maxNode*sizeof(int*));
res.reverse = (int**)malloc(maxNode*sizeof(int*));
if(maxDegree){
rep(i,maxNode) res.edge[i]=(int*)malloc(maxDegree*sizeof(int));
rep(i,maxNode) res.cost[i]=(int*)malloc(maxDegree*sizeof(int));
rep(i,maxNode) res.flow[i]=(int*)malloc(maxDegree*sizeof(int));
rep(i,maxNode) res.reverse[i]=(int*)malloc(maxDegree*sizeof(int));
}
rep(i,maxNode) res.edgeMemory[i]=maxDegree;
return res;
}
void DeleteListGraphIntCostIntFlow(ListGraphIntCostIntFlow g){
int i;
rep(i,g.nodeMemory) if(g.edgeMemory[i]){free(g.edge[i]); free(g.cost[i]); free(g.flow[i]); free(g.reverse[i]);}
free(g.edgeSize); free(g.edgeMemory); free(g.edge); free(g.cost);
}
void ListGraphIntCostIntFlowSetEmpty(ListGraphIntCostIntFlow *g,int node){
int i;
g->node = node;
rep(i,node) g->edgeSize[i]=0;
}
/* edgeMemory[k]=sizeに変更する.中身のデータは破壊される. */
/* fg=1 ならば,すでにedgeMemory[k]>=sizeの場合は何もしない */
void ListGraphIntCostIntFlowOneEdgeReallocEasy(ListGraphIntCostIntFlow *g,int k,int size,int fg){
if(fg==1 && g->edgeMemory[k]>=size) return;
if(g->edgeMemory[k]==size) return;
if(g->edgeMemory[k]){free(g->edge[k]); free(g->cost[k]); free(g->flow[k]); free(g->reverse[k]);}
g->edgeMemory[k]=size;
g->edge[k] = (int*)malloc(size*sizeof(int));
g->cost[k] = (int*)malloc(size*sizeof(int));
g->flow[k] = (int*)malloc(size*sizeof(int));
g->reverse[k] = (int*)malloc(size*sizeof(int));
}
void ListGraphIntCostIntFlowAddEdge(ListGraphIntCostIntFlow *g,int node1,int node2,int cost,int flow){
int s1,s2;
s1=g->edgeSize[node1]++, s2=g->edgeSize[node2]++;
g->edge[node1][s1]=node2; g->cost[node1][s1]= cost; g->flow[node1][s1]=flow; g->reverse[node1][s1]=s2;
g->edge[node2][s2]=node1; g->cost[node2][s2]=-cost; g->flow[node2][s2]=0; g->reverse[node2][s2]=s1;
}
void intHeapGoUp(int n,int hp[],int hpi[],int d[]){
int k,m;
if(!n) return;
m=(n-1)/2;
if(d[hp[m]]<=d[hp[n]]) return;
k=hp[m]; hp[m]=hp[n]; hp[n]=k;
hpi[hp[m]]=m; hpi[hp[n]]=n;
intHeapGoUp(m,hp,hpi,d);
}
void intHeapGoDown(int n,int hp[],int hpi[],int hp_size,int d[]){
int k,m;
m=2*n+1; if(m>=hp_size) return;
if(hp_size>m+1 && d[hp[m]]>d[hp[m+1]]) m++;
if(d[hp[m]]>=d[hp[n]]) return;
k=hp[m]; hp[m]=hp[n]; hp[n]=k;
hpi[hp[m]]=m; hpi[hp[n]]=n;
intHeapGoDown(m,hp,hpi,hp_size,d);
}
void intHeapInsert(int n,int hp[],int hpi[],int *hp_size,int d[]){
hp[*hp_size]=n; hpi[n]=(*hp_size)++;
intHeapGoUp((*hp_size)-1,hp,hpi,d);
}
int intHeapDelete(int hp[],int hpi[],int *hp_size,int d[]){
int r=hp[0]; hpi[r]=-1;
if( *hp_size==1 ){(*hp_size)--; return r;}
hp[0]=hp[--(*hp_size)]; hpi[hp[0]]=0;
intHeapGoDown(0,hp,hpi,*hp_size,d);
return r;
}
/* INF=1000000000=unreachable */
/* 負の閉路がなければ負枝があってもよい.が,その場合ed=-1と指定すること. */
/* flowが流れることができる枝のみを考えてダイクストラするんだ. */
void ListGraphIntCostIntFlowDijkstra(ListGraphIntCostIntFlow g,int st,int ed,int res_dist[],int res_back_node[],int res_back_edge[],void *WorkMemory){
int i,j,k,n=g.node,hp_size=0; int c;
int *hp, *hpi;
hp = (int*) WorkMemory; WorkMemory = (void*)( hp + n );
hpi = (int*) WorkMemory; WorkMemory = (void*)( hpi + n );
rep(i,n) hpi[i]=-1, res_dist[i]=1000000000, res_back_node[i]=-1; res_dist[st]=0;
intHeapInsert(st,hp,hpi,&hp_size,res_dist);
while(hp_size){
i = intHeapDelete(hp,hpi,&hp_size,res_dist);
if(i==ed) break;
rep(j,g.edgeSize[i]) if(g.flow[i][j]>0) {
k=g.edge[i][j]; c=res_dist[i]+g.cost[i][j];
if(res_dist[k] <= c) continue; res_dist[k]=c; res_back_node[k]=i; res_back_edge[k]=j;
if(hpi[k]<0) intHeapInsert(k,hp,hpi,&hp_size,res_dist);
else intHeapGoUp(hpi[k],hp,hpi,res_dist);
}
}
}
/* gは破壊される */
void ListGraphIntCostIntFlowMinCostFlow(ListGraphIntCostIntFlow g,int st,int ed,int flowLimit,int *res_flow,int *res_cost,void *WorkMemory){
int i,j,k,l,flow_max;
int *dist, *back_node, *back_edge;
dist = (int*) WorkMemory; WorkMemory = (void*) (dist + g.node);
back_node = (int*) WorkMemory; WorkMemory = (void*) (back_node + g.node);
back_edge = (int*) WorkMemory; WorkMemory = (void*) (back_edge + g.node);
*res_flow = *res_cost = 0;
for(;;){
if(flowLimit==0) break;
ListGraphIntCostIntFlowDijkstra(g,st,-1,dist,back_node,back_edge,WorkMemory);
if(back_node[ed]==-1) break;
flow_max = flowLimit;
k=ed;
while(back_node[k]!=-1){
i=back_node[k]; j=back_edge[k];
if(flow_max > g.flow[i][j]) flow_max = g.flow[i][j];
k=i;
}
k=ed;
while(back_node[k]!=-1){
i=back_node[k]; j=back_edge[k]; l=g.reverse[i][j];
g.flow[i][j] -= flow_max; g.flow[k][l] += flow_max;
k=i;
}
*res_flow += flow_max; *res_cost += flow_max * dist[ed];
flowLimit -= flow_max;
}
}
int main(){
int i,j,k,l,m,n;
int dic_size;
char in[120]; int len;
char dic[120][120]; int dic_len[120], dic_del[120];
int in_c[120];
int dic_c[120][120];
int node, st, ed;
ListGraphIntCostIntFlow g = NewListGraphIntCostIntFlow(3000, 110);
int flow, cost;
void *mem = malloc(30000000);
scanf("%s",in);
len = strlen(in);
scanf("%d",&dic_size);
rep(i,dic_size) scanf("%s%d",dic[i], dic_del+i), dic_len[i] = strlen(dic[i]);
node = 26 + dic_size * 26 + dic_size;
st = node++; ed = node++;
ListGraphIntCostIntFlowSetEmpty(&g, node);
rep(k,26) in_c[k] = 0;
rep(i,dic_size) rep(k,26) dic_c[i][k] = 0;
rep(i,len) in_c[in[i]-'a']++;
rep(i,dic_size) rep(j,dic_len[i]) dic_c[i][dic[i][j]-'a']++;
rep(i,26) if(in_c[i]) ListGraphIntCostIntFlowAddEdge(&g, st, i, 0, in_c[i]);
rep(i,26) rep(j,dic_size){
m = in_c[i];
if(m > dic_c[j][i]) m = dic_c[j][i];
if(m) ListGraphIntCostIntFlowAddEdge(&g, i, 26+26*j+i, 0, m);
}
rep(i,dic_size) rep(j,26) if(dic_c[i][j]) ListGraphIntCostIntFlowAddEdge(&g, 26+i*26+j, 26+26*dic_size+i, 0, dic_c[i][j]);
rep(i,dic_size) ListGraphIntCostIntFlowAddEdge(&g, 26+26*dic_size+i, ed, i+1, dic_del[i]);
ListGraphIntCostIntFlowMinCostFlow(g, st, ed, len, &flow, &cost, mem);
if(flow != len) puts("-1");
else printf("%d\n", cost);
return 0;
}
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | da76142981f28f40a2d6bb9e24bb476d | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include<stdio.h>
int main()
{
int n,count=0,i;
int sml[27]={0};
char tmp,k,D;
scanf("%d",&n);
scanf("%c",&tmp);
for(i=0;i<n-1;i++)
{
scanf("%c%c",&k,&D);
sml[k-'a'+1]++;
if(sml[D-'A'+1])
sml[D-'A'+1]--;
else
count++;
}
printf("%d\n",count);
return 0;
}
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | d44353345d8cf08f0f6fa04a78b5fbcb | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
char str[200000];
scanf("%s",&str);
int arr[100]={0};
int i,cnt=0;
for(i=0;i<2*n-2;i++)
{
if((int)str[i]>96)
arr[str[i]-'a']++;
else
{
if(arr[str[i]-'A']!=0)
arr[str[i]-'A']--;
else
cnt++;
}
}
printf("%d",cnt);
return 0;
} | |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | 249bd112e94acec42fd2e8401d8ef427 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include<stdio.h>
int main()
{
int n,z=0,i;
scanf("%d",&n);
n*=2;
n-=2;
int b[26]={0};
char a;
for(i=0;i<n;i++){
scanf("%c",&a);
if(a>96)
b[a-97]++;
else
if(b[a-65]>0)
b[a-65]--;
}
scanf("%c",&a);
if(a>96)
b[a-97]++;
else
if(b[a-65]>0)
b[a-65]--;
for(i=0;i<26;i++)
z+=b[i];
printf("%d\n",z);
return 0;}
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | ffb3952f65274458f88e529a66ff2530 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include<stdio.h>
#include<string.h>
int main()
{
long int i,j,T,N,k=0,mark[256]={0};
char ch[200000];
scanf("%ld",&N);
getchar();
gets(ch);
T=strlen(ch);
for(i=0;i<T;i++)
{
if(ch[i]>='a'&&ch[i]<='z')
mark[ch[i]]++;
else
{
if(mark[ch[i]-'A'+'a']>0)
mark[ch[i]-'A'+'a']--;
else ++k;
}
}
printf("%ld\n",k);
return 0;
}
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | f5f8690cac9160d9181a316626678b4d | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include <stdio.h>
#include <ctype.h>
#define SIZE 100000
int main()
{
int i, keys[26] = { 0 }, cnt = 0;
char s[SIZE * 2];
scanf ("%*d %s", s);
for (i = 0; s[i]; i++) {
if (islower(s[i]))
keys[s[i] - 'a']++;
else {
if (keys[tolower(s[i]) - 'a'] == 0)
cnt++;
else
keys[tolower(s[i]) - 'a']--;
}
}
printf ("%d", cnt);
return 0;
}
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | 5804ce1fd01b3026cd0cfb6ae54ecefc | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include<stdio.h>
#include<string.h>
#include<math.h>
long long int l[256];
int main() {
long long int a,b,i,j,count=0,n,l1;
char str[1000001];
// while(1) {
scanf("%lld",&n);
scanf("%s",str);
l1=strlen(str);
count=0;
for(i=0;i<l1-1;i+=2)
{
l[(int)str[i]]++;
// printf("%c %c ",str[i],str[i]-32);
if(l[(int)str[i+1]+32]>0)
{
// printf("%c in >0 ",str[i]+32);
l[(int)str[i+1]+32]--;
}
else
count++;
}
printf("%lld\n",count);
//scanf("%d",&a);
//}
return 0;
}//end of main()
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | ec76b551301052d83a48e763ee3e9450 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include<stdio.h>
#include<string.h>
#include<math.h>
long long int l[256];
int main() {
long long int a,b,i,j,count=0,n,l1;
char str[1000001];
// while(1) {
scanf("%lld",&n);
scanf("%s\n",str);
l1=strlen(str);
count=0;
for(i=0;i<l1-1;i+=2)
{
l[(int)str[i]]++;
// printf("%c %c ",str[i],str[i]-32);
if(l[(int)str[i+1]+32]>0)
{
// printf("%c in >0 ",str[i]+32);
l[(int)str[i+1]+32]--;
}
else
count++;
}
printf("%lld\n",count);
//scanf("%d",&a);
//}
return 0;
}//end of main()
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | 3c202b7ff899ec6d0ffe5466cd6ab384 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include<stdio.h>
#include<string.h>
int arr[123]={0};
int arr1[123]={0};
int main()
{
long long int a,b,c,d,i,j=0,count=0;
char ch;
scanf("%lld",&a);
getchar();
while(j<(2*(a-1)))
{
if(j%2==0)
{
ch=getchar();
arr[ch]++;
}
else
{
ch=getchar();
if(arr[ch+32]>0)
{
arr[ch+32]--;
}
else
{
count++;
}
}
j++;
}
/*for(i=0;i<(2*(a-1));i++)
{
if(i%2==0)
{
arr[str[i]]++;
}
else
{
arr1[str[i]]++;
}
}
if(str[0]!=(str[1]+32))
{
count++;
arr1[str[1]]--;
}
else
{
arr[str[0]]--;
arr1[str[1]]--;
}
for(i=97;i<123;i++)
{
if(arr[i]<=arr1[i-32])
{
arr1[i-32]=arr1[i-32]-arr[i];
arr[i]=0;
}
}
for(i=65;i<91;i++)
{
if(arr1[i]>0)
{
count=count+arr1[i];
arr1[i]=0;
}
}*/
printf("%lld",count);
return 0;
}
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | 896b352c8da08d887927efdc8a942d1c | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include <stdio.h>
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE
int n,i,ans,len;
char str[200000];
while(scanf("%d",&n)==1)
{
int mappa[26]={0};
scanf("%s",&str);
ans=0;
len=2*n-2;
for(i=0;i<len;i++)
{
if(i&1)
{
if(mappa[str[i]-'a'+32]>0)
{
mappa[str[i]-'a'+32]--;
}else ans++;
}else
{
mappa[str[i]-'a']++;
}
}
printf("%d\n",ans);
}
return 0;
} | |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | ce4a84c54f324bd585756a75a7070814 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include <stdio.h>
#include <string.h>
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE
int n,i,ans,len;
char str[200000];
while(scanf("%d",&n)==1)
{
int mappa[26]={0};
scanf("%s",&str);
ans=0;
len=strlen(str);
for(i=0;i<len;i++)
{
if(i&1)
{
if(mappa[str[i]-'a'+32]>0)
{
mappa[str[i]-'a'+32]--;
}else ans++;
}else
{
mappa[str[i]-'a']++;
}
}
printf("%d\n",ans);
}
return 0;
}
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | 33f28da025159fe3da5ec740a13d1fbd | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include <stdio.h>
char small[26];
int main()
{
int n,state,count=0,k;
long long int i,j;
scanf("%d",&n);
char ch;
ch=getchar();
for(i=0;i<26;i++)
small[i]=0;
for(i=0;i<2*n-2;i++)
{
ch=getchar();
if('a'<=ch && 'z'>=ch)
{
k=ch-'a';
small[k]++;
}
else
{
k=ch-'A';
if(small[k]==0)
count++;
else
small[k]--;
}
}
printf("%d",count);
return 0;
}
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | 856cf7fc3f524735704b4c46d9da82f8 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int n,c,i,b[26];
char a[200000];
while(scanf("%d",&n)!=EOF)
{
getchar();
scanf("%s",a);
c=0;
for(i=0;i<26;i++)
{
b[i]=0;
}
for(i=0;i<n-1;i++)
{
b[a[2*i]-97]++;
if(b[a[2*i+1]-65]==0)c++;
else b[a[2*i+1]-65]--;
}
printf("%d\n",c);
}
return 0;
}
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | 3d426e0e82f0b1e5ab6ffb3deb907bff | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
int len=2*n-2;
char ch[200000];
int i;
scanf("%s",ch);
int arr[26];
for(i=0;i<26;i++)
arr[i]=0;
int sum=0;
for(i=0;i<len;i++)
{
if(ch[i]>=97)
{
int m=(int)ch[i] - 97;
arr[m]++;
}
else
{
int m=(int)ch[i] - 65;
if(arr[m]==0)
{
sum++;
}
else
{
arr[m]--;
}
}
}
printf("%d\n",sum);
return 0;
}
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | c781647e93552e18df1be3b599ffdc52 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include<stdio.h>
#include<string.h>
int main()
{
int n;
scanf("%d",&n);
int arr[26];
int i;
for(i=0;i<26;i++)
{
arr[i]=0;
}
char ch[1000000];
scanf("%s",ch);
int len=strlen(ch);
int count=0;
for(i=0;i<len;i++)
{
int m=(int)(ch[i]-97);
arr[m]++;
i++;
int x=(int)(ch[i]-65);
if(arr[x]!=0)
{
arr[x]--;
}
else
{
count++;
}
}
printf("%d\n",count);
return 0;
}
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | eb5d513f76f1bc95af430d03998cd0df | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int x,n,key[26]={0},openRoom,pointer=0,buy=0;
char *string;
scanf(" %d",&n);
string =(char *)malloc((2*n-2)*sizeof(char));
scanf(" %s",string);
while(pointer<=(2*n-4))
{
x=string[pointer]-97;
key[x]++;
openRoom = string[pointer+1] -65;
if(key[openRoom]>0)
key[openRoom]--;
else
buy++;
pointer+=2;
}
printf("%d",buy);
return 0;
}
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | e10f7034353fadb484e7d4807bb5e14e | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include<stdio.h>
char arr[1000004];
int b[26]={0};
int main()
{
int n,i,j;
scanf("%d",&n);
int d=0,count=0;
scanf(" %[^\n]",arr);
for(i=0;i<2*(n-1);i++)
{
if(i%2==0)
{
int s=(int)arr[i]-97;
b[s]++;
}
else
{
int h=(int)arr[i]-65;
if(b[h]>0)
{
b[h]--;
count++;
}
}
}
printf("%d\n",(n-count-1));
return 0;
}
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | c40d3c5d7c8d512a9ed0cf42dfff5860 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include<stdio.h>
int main(int argc,char *argv[]){
int n;
int string[26];
int j;
int k;
for(k=0;k<26;k++){string[k]=0;}
int c,count;
count=0;
scanf("%d",&n);
int limit;
getchar();
limit=2*n-2;
int i=1;
while((c=getchar())!='\n'&& c!=EOF){
if(i%2){
string[c-97]++;
i++;}
else{
if(string[c-65]>0){
string[c-65]--;
i++;}
else{count++;
i++;}
}
if(i>limit)break;
}
printf("%d",count);
//for(i=0;i<26;printf("%d")
//for(j=0;j<26;j++){printf("%d\n ",string[j]);}
return 0;
} | |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | ce6ee286901977369be9d276a28e6aba | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include<stdio.h>
int main()
{int n,sum=0,i;
scanf("%d",&n);
char ch[2*n-2];
scanf("%s",&ch);
int a[26]={0};
for(i=0; i<2*n-2; i++)
{if(i%2==0)
a[ch[i]-'a']++;
else
{if(a[ch[i]-'A']>0)
{a[ch[i]-'A']--;}
else
sum++;
}
}
printf("%d\n",sum);
return 0;
}
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | e03006ffbf06fad877e049fa6073daf4 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] |
#include<stdio.h>
#define LL long long int
int main()
{
int n,i;
scanf("%d",&n);
char st[1000000];
scanf("%s",st);
static int a[26],b[26];
int count=0;
for(i=0;i<2*n-2;i+=2)
{
int c=st[i]-'a';
a[c]++;
int C=st[i+1]-'A';
if (a[C]==0)
count++;
else
a[C]--;
}
printf("%d\n",count);
return 0;
}
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | 9cbc0396d1ede34af2a8a0c81f63cf36 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
typedef long long int ll;
main()
{
char a[200005];
int n,i;
scanf("%d%s",&n,a);
int cnt[26] = {0};
int ans = 0;
for(i=0;i<(n-1);i++)
{
cnt[a[2*i]-'a']++;
if(cnt[a[2*i+1]-'A']>0)
{
cnt[a[2*i+1]-'A']--;
}
else
ans++;
}
printf("%d\n",ans);
return 0;
}
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | 579c02587872474697a1a2810fb103d8 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include<stdio.h>
int main()
{
char a[500000];
int map1[26]={0};
int n,i,j,k,count=0;
scanf("%d\n",&n);
gets(a);
for(i=0;i<(2*n)-2; i++)
{
if(i%2==0)
map1[a[i]-'a']++;
else
if(map1[a[i]-'A'])
map1[a[i]-'A']--;
else
count++;
}
printf("%d\n",count);
return 0;
}
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | 62d79404891cb3f344b2bb926cd17e41 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char s[200000];
int n,i,l,count=0;
scanf("%d",&n);
scanf("%s",s);
l = strlen(s);
int a[26];
for(i=0;i<26;i++)
a[i] = 0;
for(i=0;i<l;i++)
{
if(i%2==0)
a[s[i]-'a']++;
else
{
if(a[s[i]-'A']==0)
count++;
else
a[s[i]-'A']--;
}
}
printf("%d\n",count);
return 0;
}
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | d6b8d5877c5bcacffd631e080546865e | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include <stdio.h>
#include <string.h>
int main()
{
int n,p,i,j;
int a[150];
char x;
scanf("%d",&n);
p=0;
for(i='a';i<='z';i++)
{
a[i]=0;
}
for(i=0;i<=2*n-2;i++)
{
scanf("%c",&x);
if(i%2==1)
{
a[x]++;
}
else
{
if(a[x+32]>0)
{
a[x+32]--;
}
else
{
p++;
}
}
}
printf("%d",p);
return 0;
}
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | a1af9cd66723e3625293f1ac4c4d35cc | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include <stdio.h>
int main(void) {
int n,i;
scanf("%d",&n);
char s[(2*n-2)];
scanf("%s",s);
int k[26];
for(i=0;i<26;i++){
k[i]=0;
}
int x,ans=0,l=strlen(s);
for(i=0;i<l;i++){
k[(int)s[i]-97]++;
i++;
x=((int)s[i])-65;
if(k[x]>0)
k[x]--;
else
ans++;
}
printf("%d",ans);
return 0;
}
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | 9e7d2adf216223107b8bef0a958d5109 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include <stdio.h>
int main()
{
char code[300000];
unsigned long long record[1000];
unsigned long long len, i, n, keycount = 0;
scanf("%d", &n);
scanf("%s", code);
for(i = 0; i<= 2*(n-2); i+=2)
{
record[code[i]- 'a']++;
if(record[code[i+1]- 'A'] == 0)
{
keycount++;
}
else
{
record[code[i+1]-'A']--;
}
}
printf("%d", keycount);
return 0;
}
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | 0476924ba4b65035565c635edf1d6bb5 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include<stdio.h>
#include<string.h>
int main()
{
int n,ans=0,i;
scanf("%d",&n);
int a[26];
for(i=0;i<26;i++)
{
a[i]=0;
}
char str[2*n];
scanf("%s",str);
int l=strlen(str);
for(i=0;i<l;i++)
{
if(i&1)
{
if(a[str[i]-'A'])
{
a[str[i]-'A']--;
}
else
{
ans++;
}
}
else
a[str[i]-'a']++;
}
printf("%d\n",ans);
return 0;
} | |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | 7396d350d13ea0c7ed5cc28de07e2a9c | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include <stdio.h>
#define maxn 200005
int main()
{
int n = 0,m,ctr;
char s[maxn] = {'\0'};
char keys[27] = {'\0'};
scanf("%d",&n);
m = 2*n-2;
scanf("%s",s);
int i;
for (i = 0; i < m; i++)
{
if ( i%2 == 0)
{
keys[s[i]-'a']++;
}
else
{
if (keys[s[i]-'A']==0)
ctr++;
if (keys[s[i]-'A']!=0)
keys[s[i]-'A']--;
}
}
printf("%d\n",ctr);
return 0;
} | |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | 5ecb64ac4979a5dfdbc6c246dc449ccc | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include<stdio.h>
int main()
{
int n,i,c=0;
char a[10000000]="";
int b[125]={0};
scanf("%d\n",&n);
for(i=0; ;i++)
{
scanf("%c",&a[i]);
if(a[i]=='\0')
break;
}
for(i=0;a[i]!='\0';i++)
{ if(((int)a[i])>=97 && ((int)a[i])<=122)
{
b[((int)a[i])]++;
}
else
if(((int)a[i])>=65 && ((int)a[i])<=90)
{
if(b[((int)a[i]+32)]<=0)
c++;
else
if(b[((int)a[i])+32]>=1)
{
b[((int)a[i])+32]--;
}
}
}
printf("%d\n",c);
return 0;
} | |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | 2df94953d5de779ac96ab2267c539e55 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include<stdio.h>
int main()
{
int n,i,c=0;
char a[10000000]="";
int b[125]={0};
scanf("%d\n",&n);
for(i=0; ;i++)
{
scanf("%c",&a[i]);
if(a[i]=='\0')
break;
}
for(i=0;a[i]!='\0';i++)
{ if(((int)a[i])>=97 && ((int)a[i])<=122)
{
b[((int)a[i])]++;
}
else
if(((int)a[i])>=65 && ((int)a[i])<=90)
{
if(b[((int)a[i]+32)]<=0)
c++;
else
if(b[((int)a[i])+32]>=1)
{
b[((int)a[i])+32]--;
}
}
}
printf("%d\n",c);
return 0;
} | |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | b9f16a094acd48f3c75d63bb58715778 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
int a[26]={0};
char c;
char ser[1000000];
int count=0;
scanf("%s",ser);
int i=0;
while(ser[i]!='\0')
{
c=ser[i];
if(c>='a'&&c<='z')
{
a[c-'a']++;
// char t=(char)c;
}
else
{
if(a[c-'A']==0)
{
count++;
}
else
{
a[c-'A']--;
}
}
i++;
}
printf("%d\n",count);
return 0;
}
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | f5c1c984e76b9e522fe7164c964b6ccc | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include<stdio.h>
int main()
{
char str[200000];
int k[130], i, n, x, count=0;
for(i=0; i<130; i++)
k[i]=0;
scanf("%d %s", &n, str);
for(i=0; i<(2*n-2); i++)
{
if(i%2==0)
{
x = (int)(str[i]);
k[x]++;
}
else
{
if(k[(int)(str[i]+32)])
k[(int)(str[i]+32)]--;
else
{
count++;
}
}
}
printf("%d\n", count);
return 0;
} | |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | 6dd265685b390201f8e23bd8398386a3 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | /* Problem: 525A - Vitaliy and Pie */
/* Solver: Gusztav Szmolik */
#include <stdio.h>
#include <string.h>
#include <ctype.h>
unsigned char s[200000];
int main ()
{
unsigned int n;
unsigned int l;
unsigned short i;
unsigned int kc[26];
unsigned int kb;
unsigned int j;
unsigned char k;
unsigned char d;
if (scanf("%u",&n) != 1)
return -1;
if (n < 2 || n > 100000)
return -1;
if (scanf("%199999s",s) != 1)
return -1;
l = strlen (s);
if (l != 2*n-2)
return -1;
for (i = 0; i < 26; i++)
kc[i] = 0;
kb = 0;
for (j = 0; j < l; j += 2)
{
k = s[j];
d = s[j+1];
if (!islower(k) || !isupper(d))
return -1;
k -= 'a';
d -= 'A';
if (k != d)
{
kc[k]++;
if (!kc[d])
kb++;
else
kc[d]--;
}
}
printf ("%u\n",kb);
return 0;
}
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | 2861b65207d7b4896d727838c16fd8c1 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include<stdio.h>
int main()
{
char c;
int i,n;
int a[26]={0};
scanf("%d",&n);
int ans=0;
for(i=0;i<=(2*n-2);i++)
{
scanf("%c",&c);
if(c>='a' && c<='z')
{
a[c-'a']++;
}
else
{
if(a[c-'A']!=0)
a[c-'A']--;
else
ans+=1;
}
}
printf("%d",ans);
return 0;
}
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | b142b4b3288383fb16e437e021ded20a | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include<stdio.h>
int main()
{
int n,c=0,i,d[26]={0};
scanf("%d\n",&n);
char ch1,ch2;
for(i=1;i<=n-1;i++)
{
ch1=getchar();
ch2=getchar();
d[ch1-'a']++;
if(d[ch2-'A']!=0)
d[ch2-'A']--;
else
c++;
}
printf("%d",c);
}
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | a92e8992b713ec8029d80359840a05e4 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include<stdio.h>
int main()
{
int n,k[26]={0},d[26]={0},ans=0,i;
char s[300010];
scanf("%d\n",&n);
scanf("%s",s);
i=0;
while(s[i])
{
if(s[i]-32==s[i+1])
i=i+2;
else if(k[s[i+1]-'A']>0)
{
k[s[i+1]-'A']--;
k[s[i]-'a']++;
i=i+2;
}
else
{
ans++;
k[s[i]-'a']++;
i=i+2;
}
}
printf("%d\n",ans);
return 0;
}
| |
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. | C | 80fdb95372c1e8d558b8c8f31c9d0479 | 5bee177bbdc90877bfe3b66a69c7a52c | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"hashing",
"greedy",
"strings"
] | 1427387400 | ["3\naAbB", "4\naBaCaB", "5\nxYyXzZaZ"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. | ["0", "3", "2"] | #include <stdio.h>
#include <string.h>
int main()
{
long long int n,sum=0;
int alpha[100]={0},i=0;
scanf("%I64d",&n);
char a[2*n-1];
scanf("%s",a);
for(i=0;i<2*n-2;i++){
if(a[i]>='a'&&a[i]<='z') alpha[a[i]-'a']++;
else{
if(!alpha[a[i]-'A']) sum++;
else alpha[a[i]-'A']--;
}
}
printf("%d",sum);
return 0;
}
| |
You are given a sequence of integers of length $$$n$$$ and integer number $$$k$$$. You should print any integer number $$$x$$$ in the range of $$$[1; 10^9]$$$ (i.e. $$$1 \le x \le 10^9$$$) such that exactly $$$k$$$ elements of given sequence are less than or equal to $$$x$$$.Note that the sequence can contain equal elements.If there is no such $$$x$$$, print "-1" (without quotes). | Print any integer number $$$x$$$ from range $$$[1; 10^9]$$$ such that exactly $$$k$$$ elements of given sequence is less or equal to $$$x$$$. If there is no such $$$x$$$, print "-1" (without quotes). | C | 55297e2a65144323af4d6abd6a6ef050 | 5f7093fd5dcb61a4ee0bf2e43a3e2fb5 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"sortings"
] | 1567258500 | ["7 4\n3 7 5 1 10 3 20", "7 2\n3 7 5 1 10 3 20"] | NoteIn the first example $$$5$$$ is also a valid answer because the elements with indices $$$[1, 3, 4, 6]$$$ is less than or equal to $$$5$$$ and obviously less than or equal to $$$6$$$.In the second example you cannot choose any number that only $$$2$$$ elements of the given sequence will be less than or equal to this number because $$$3$$$ elements of the given sequence will be also less than or equal to this number. | PASSED | 1,200 | standard input | 2 seconds | The first line of the input contains integer numbers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le n$$$). The second line of the input contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the sequence itself. | ["6", "-1"] | #include<stdio.h>
#include<stdlib.h>
int arr[200002];
int comparator(const void*a,const void*b)
{ return (*(int*)a-*(int*)b); }
int main()
{
int n,k;
scanf("%d %d",&n,&k);
for(int i=0;i<n;i++)
scanf("%d",&arr[i]);
qsort(arr,n,sizeof(int),comparator);
if(k==0)
{
if(arr[0]>=2)
printf("%d",arr[0]-1);
else
printf("-1\n");
return 0;
}
if(arr[k]==arr[k-1])
{
printf("-1\n");
return 0;
}
printf("%d\n",arr[k-1]);
return 0;
}
| |
You are given a sequence of integers of length $$$n$$$ and integer number $$$k$$$. You should print any integer number $$$x$$$ in the range of $$$[1; 10^9]$$$ (i.e. $$$1 \le x \le 10^9$$$) such that exactly $$$k$$$ elements of given sequence are less than or equal to $$$x$$$.Note that the sequence can contain equal elements.If there is no such $$$x$$$, print "-1" (without quotes). | Print any integer number $$$x$$$ from range $$$[1; 10^9]$$$ such that exactly $$$k$$$ elements of given sequence is less or equal to $$$x$$$. If there is no such $$$x$$$, print "-1" (without quotes). | C | 55297e2a65144323af4d6abd6a6ef050 | a0ffc0c34f6e880795b93a7b04957d69 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"sortings"
] | 1567258500 | ["7 4\n3 7 5 1 10 3 20", "7 2\n3 7 5 1 10 3 20"] | NoteIn the first example $$$5$$$ is also a valid answer because the elements with indices $$$[1, 3, 4, 6]$$$ is less than or equal to $$$5$$$ and obviously less than or equal to $$$6$$$.In the second example you cannot choose any number that only $$$2$$$ elements of the given sequence will be less than or equal to this number because $$$3$$$ elements of the given sequence will be also less than or equal to this number. | PASSED | 1,200 | standard input | 2 seconds | The first line of the input contains integer numbers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le n$$$). The second line of the input contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the sequence itself. | ["6", "-1"] | #include<stdio.h>
#include<stdlib.h>
int compare(const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
int main(void){
long long int n,k;
scanf("%lld %lld",&n,&k);
long long int arr[200001];
for(int i=0;i<n;i++)
scanf("%lld",&arr[i]);
qsort(arr, n, sizeof(arr[0]), compare);
if(k>0){
if(arr[k]==arr[k-1])
printf("-1\n");
else
printf("%lld\n",(arr[k-1]));}
if(k==0 && arr[0]==1)
printf("-1\n");
if(k==0 && arr[0]>1)
printf("%lld",arr[0]-1);
return 0;
}
| |
You are given a sequence of integers of length $$$n$$$ and integer number $$$k$$$. You should print any integer number $$$x$$$ in the range of $$$[1; 10^9]$$$ (i.e. $$$1 \le x \le 10^9$$$) such that exactly $$$k$$$ elements of given sequence are less than or equal to $$$x$$$.Note that the sequence can contain equal elements.If there is no such $$$x$$$, print "-1" (without quotes). | Print any integer number $$$x$$$ from range $$$[1; 10^9]$$$ such that exactly $$$k$$$ elements of given sequence is less or equal to $$$x$$$. If there is no such $$$x$$$, print "-1" (without quotes). | C | 55297e2a65144323af4d6abd6a6ef050 | f02725861d2931b12f4774f83644c346 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"sortings"
] | 1567258500 | ["7 4\n3 7 5 1 10 3 20", "7 2\n3 7 5 1 10 3 20"] | NoteIn the first example $$$5$$$ is also a valid answer because the elements with indices $$$[1, 3, 4, 6]$$$ is less than or equal to $$$5$$$ and obviously less than or equal to $$$6$$$.In the second example you cannot choose any number that only $$$2$$$ elements of the given sequence will be less than or equal to this number because $$$3$$$ elements of the given sequence will be also less than or equal to this number. | PASSED | 1,200 | standard input | 2 seconds | The first line of the input contains integer numbers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le n$$$). The second line of the input contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the sequence itself. | ["6", "-1"] | #include <stdio.h>
#include <stdlib.h>
int cmp(const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
int main()
{
int n, k, a[2*100000];
scanf("%d %d", &n, &k);
int i;
for(i=0;i<n;i++) scanf("%d", &a[i]);
qsort(a, n, sizeof(int), cmp);
int x=a[k-1];
int j=k, l=0;
if(k==0)
{
if(a[0]!=1 )printf("%d\n", a[0]-1);
else printf("-1\n");
return 0;
}
while((a[j]<=a[k-1])&&(j<n))
{
j++;
l++;
}
if(l==0) printf("%d\n", x);
else printf("-1\n");
return 0;
}
| |
You are given a sequence of integers of length $$$n$$$ and integer number $$$k$$$. You should print any integer number $$$x$$$ in the range of $$$[1; 10^9]$$$ (i.e. $$$1 \le x \le 10^9$$$) such that exactly $$$k$$$ elements of given sequence are less than or equal to $$$x$$$.Note that the sequence can contain equal elements.If there is no such $$$x$$$, print "-1" (without quotes). | Print any integer number $$$x$$$ from range $$$[1; 10^9]$$$ such that exactly $$$k$$$ elements of given sequence is less or equal to $$$x$$$. If there is no such $$$x$$$, print "-1" (without quotes). | C | 55297e2a65144323af4d6abd6a6ef050 | 92962ad2c69bdbb1036c0a53caa2c9ea | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"sortings"
] | 1567258500 | ["7 4\n3 7 5 1 10 3 20", "7 2\n3 7 5 1 10 3 20"] | NoteIn the first example $$$5$$$ is also a valid answer because the elements with indices $$$[1, 3, 4, 6]$$$ is less than or equal to $$$5$$$ and obviously less than or equal to $$$6$$$.In the second example you cannot choose any number that only $$$2$$$ elements of the given sequence will be less than or equal to this number because $$$3$$$ elements of the given sequence will be also less than or equal to this number. | PASSED | 1,200 | standard input | 2 seconds | The first line of the input contains integer numbers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le n$$$). The second line of the input contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the sequence itself. | ["6", "-1"] | #include <stdio.h>
#include <stdlib.h>
int cmp(const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
int main()
{
int n, k, a[2*100000];
scanf("%d %d", &n, &k);
int i;
for(i=0;i<n;i++) scanf("%d", &a[i]);
qsort(a, n, sizeof(int), cmp);
int x=a[k-1], j=k, l=0;
if(k==0)
{
if(a[0]!=1 )printf("%d\n", a[0]-1);
else printf("-1\n");
return 0;
}
while((a[j]<=a[k-1])&&(j<n))
{
j++;
l++;
break;
}
if(l==0) printf("%d\n", x);
else printf("-1\n");
return 0;
}
| |
You are given a sequence of integers of length $$$n$$$ and integer number $$$k$$$. You should print any integer number $$$x$$$ in the range of $$$[1; 10^9]$$$ (i.e. $$$1 \le x \le 10^9$$$) such that exactly $$$k$$$ elements of given sequence are less than or equal to $$$x$$$.Note that the sequence can contain equal elements.If there is no such $$$x$$$, print "-1" (without quotes). | Print any integer number $$$x$$$ from range $$$[1; 10^9]$$$ such that exactly $$$k$$$ elements of given sequence is less or equal to $$$x$$$. If there is no such $$$x$$$, print "-1" (without quotes). | C | 55297e2a65144323af4d6abd6a6ef050 | befa2b976db960d7954d62305052a5e9 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"sortings"
] | 1567258500 | ["7 4\n3 7 5 1 10 3 20", "7 2\n3 7 5 1 10 3 20"] | NoteIn the first example $$$5$$$ is also a valid answer because the elements with indices $$$[1, 3, 4, 6]$$$ is less than or equal to $$$5$$$ and obviously less than or equal to $$$6$$$.In the second example you cannot choose any number that only $$$2$$$ elements of the given sequence will be less than or equal to this number because $$$3$$$ elements of the given sequence will be also less than or equal to this number. | PASSED | 1,200 | standard input | 2 seconds | The first line of the input contains integer numbers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le n$$$). The second line of the input contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the sequence itself. | ["6", "-1"] | #include<stdio.h>
int comparefunc(const void *a,const void *b)
{
return (*(int*)a-*(int*)b);
}
int main()
{
int n,k,str[200001],i;
scanf("%d %d",&n,&k);
for(i=0;i<n;i++){
scanf("%d",&str[i]);
}
qsort(str,n,sizeof(int),comparefunc);
if(str[0]>=2 && k==0)
printf("%d",str[0]-1);
else if(n==1 && str[0]>=1 && k==1)
printf("%d",str[0]);
else if(str[k-1]<str[k] && str[k-1]>=1)
printf("%d",str[k-1]);
else if(n==k)
printf("%d",str[k-1]);
else printf("-1");
return 0;
} | |
You are given a sequence of integers of length $$$n$$$ and integer number $$$k$$$. You should print any integer number $$$x$$$ in the range of $$$[1; 10^9]$$$ (i.e. $$$1 \le x \le 10^9$$$) such that exactly $$$k$$$ elements of given sequence are less than or equal to $$$x$$$.Note that the sequence can contain equal elements.If there is no such $$$x$$$, print "-1" (without quotes). | Print any integer number $$$x$$$ from range $$$[1; 10^9]$$$ such that exactly $$$k$$$ elements of given sequence is less or equal to $$$x$$$. If there is no such $$$x$$$, print "-1" (without quotes). | C | 55297e2a65144323af4d6abd6a6ef050 | b4648e462cb2d610356feefd07bee9a2 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"sortings"
] | 1567258500 | ["7 4\n3 7 5 1 10 3 20", "7 2\n3 7 5 1 10 3 20"] | NoteIn the first example $$$5$$$ is also a valid answer because the elements with indices $$$[1, 3, 4, 6]$$$ is less than or equal to $$$5$$$ and obviously less than or equal to $$$6$$$.In the second example you cannot choose any number that only $$$2$$$ elements of the given sequence will be less than or equal to this number because $$$3$$$ elements of the given sequence will be also less than or equal to this number. | PASSED | 1,200 | standard input | 2 seconds | The first line of the input contains integer numbers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le n$$$). The second line of the input contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the sequence itself. | ["6", "-1"] | #include<stdio.h>
void divide(int a[],int n);
void merge(int l[],int r[],int a[],int nl,int nr);
int main(void)
{
int n,i,k;
scanf("%i %i",&n,&k);
int ar[n+1];
ar[0]=0;
for(i=1;i<=n;i++)scanf("%i",&ar[i]);
divide(ar,n+1);
if(k==n)printf("%i",ar[k]);
else if(ar[k+1]>ar[k])
{
if(ar[k+1]-1>0)printf("%i",ar[k+1]-1);
else printf("-1");
}
else printf("-1");
return 0;
}
void divide(int a[],int n)
{
int mid;
if(n<2) return;
else
mid=n/2;
int left[mid],right[n-mid];
int i;
for(i=0;i<mid;i++) left[i]=a[i];
for(i=mid;i<n;i++) right[i-mid]=a[i];
divide(left,mid); divide(right,n-mid);
merge(left,right,a,mid,n-mid);
}
void merge(int l[],int r[],int a[],int nl,int nr)
{
int i=0,j=0,k=0;
while(i<nl&&j<nr)
{
if(l[i]<r[j])
{
a[k]=l[i];
k++;
i++;
}
else
{
a[k]=r[j];
k++;
j++;
}
}
while(i<nl) {a[k]=l[i]; k++; i++;}
while(j<nr) {a[k]=r[j]; k++; j++;}
}
| |
You are given a sequence of integers of length $$$n$$$ and integer number $$$k$$$. You should print any integer number $$$x$$$ in the range of $$$[1; 10^9]$$$ (i.e. $$$1 \le x \le 10^9$$$) such that exactly $$$k$$$ elements of given sequence are less than or equal to $$$x$$$.Note that the sequence can contain equal elements.If there is no such $$$x$$$, print "-1" (without quotes). | Print any integer number $$$x$$$ from range $$$[1; 10^9]$$$ such that exactly $$$k$$$ elements of given sequence is less or equal to $$$x$$$. If there is no such $$$x$$$, print "-1" (without quotes). | C | 55297e2a65144323af4d6abd6a6ef050 | cbc4b38be4e89a7b1b9d15facac53f34 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"sortings"
] | 1567258500 | ["7 4\n3 7 5 1 10 3 20", "7 2\n3 7 5 1 10 3 20"] | NoteIn the first example $$$5$$$ is also a valid answer because the elements with indices $$$[1, 3, 4, 6]$$$ is less than or equal to $$$5$$$ and obviously less than or equal to $$$6$$$.In the second example you cannot choose any number that only $$$2$$$ elements of the given sequence will be less than or equal to this number because $$$3$$$ elements of the given sequence will be also less than or equal to this number. | PASSED | 1,200 | standard input | 2 seconds | The first line of the input contains integer numbers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le n$$$). The second line of the input contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the sequence itself. | ["6", "-1"] | #include<stdio.h>
#include<stdlib.h>
int compare(const void *a,const void *b)
{
return(*(int*)a-*(int*)b);
}
int main()
{
long long int n,k,ans;
scanf("%lld %lld",&n,&k);
long long int arr[n];
for(long long int i=0;i<n;i++)
scanf("%lld",&arr[i]);
qsort(arr,n,sizeof(arr[0]),compare);
ans=-1;
if(k>0)
{
if(arr[k]!=arr[k-1])
ans=arr[k-1];
}
if(k==0 && arr[0]>1)
ans=(arr[0]-1);
printf("%lld\n",ans);
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.