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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | 95e909fe3fb62cecbd7b020d8eec832e | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] | #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int cmp(const void *a,const void *b)
{
return *(int *)a- *(int *)b;
}
int max(int a,int b)
{
if(a>b)
return a;
return b;
}
int min(int a,int b)
{
if(a<b)
return a;
return b;
}
int mod(int a)
{
if(a<0)
return -a;
return a;
}
int main()
{
int n,m,i,j=0,a[10002],b[10003];
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<m;i++)
scanf("%d",&b[i]);
int count=0;
for(i=0;i<n;i++)
{
if(j<m && a[i]<=b[j])
{
count++;
j++;
}
}
printf("%d\n",count );
return 0;
}
| |
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | 3d98b64abeb9a0ddcf92eaf52d4f0e34 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] |
#include <stdio.h>
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int c[n];
for(int i=0;i<n;i++)
{
scanf("%d",&c[i]);
}
int a[m];
for(int i=0;i<m;i++)
{
scanf("%d",&a[i]);
}
int *bill=&a[0];
int count=0;
for(int i=0;i<n;i++)
{
while(bill<=&a[m-1])
{
if(*bill>=c[i])
{
count+=1;
bill++;
break;
}
else
{
break;
}
}
}
printf("%d",count);
return 0;
}
| |
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | f448b2a76780c64677b7d62d69f43744 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] | #include<stdio.h>
int main()
{
int n,m,i,c,p=0;
long long int sum=0;
scanf("%d %d",&n,&m);
int a[n];
int b[m];
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<m;i++)
scanf("%d",&b[i]);
c=b[p];
for(i=0;i<n;i++)
{
if(a[i]<=c && p<m)
{
sum++;
c=b[++p];
}
}
printf("%d",sum);
} | |
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | 3f2ff5a3e38925d42751d4b83767e9e5 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] | #include<stdio.h>
int main()
{
int m,n,j,i,count=0,a[1001],b[1001];
scanf("%d%d",&m,&n);
for(i=0;i<m;i++)
{
scanf("%d",&a[i]);
}
for(j=0;j<n;j++)
{
scanf("%d",&b[j]);
}
j=0;
for(i=0;i<m;i++)
{
if(a[i]<=b[j])
{ count++;
j++;}
}
printf("%d",count);
return 0;
}
| |
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | 4e5fab317a662092c05725a34a0aacf1 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] | #include<stdio.h>
int main()
{
int n,m,bill[1001],game[1001],j,i,bought=0;
scanf("%d %d",&n,&m);
for(i=0;i<n;i++)
{
scanf("%d",&game[i]);
}
for(i=0;i<m;i++)
{
scanf("%d",&bill[i]);
}
for(i=0;i<n;i++)
{ if(j<=m){
if(bill[j]>=game[i])
{
bought++;
j++;
}
}
else break;
}
printf("%d",bought);
} | |
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | 92bca65d171e56f3aadefdabb999ad5c | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] | #include <stdio.h>
int main()
{
int m, n, c, i, j;
scanf("%d %d", &n, &m);
int a[n], b[m];
for(i = 0; i < n; i++) scanf("%d", a+i);
for(i = 0; i < m; i++) scanf("%d", b+i);
for(i = 0, c = 0, j = 0; i < n && j < m; i++){
if(b[j] >= a[i]){
c++;
j++;
}
}
printf("%d\n", c);
return 0;
}
| |
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | 04b6f6552b3048d20c4d5d0b253a5810 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] | #include<stdio.h>
//#include<stdlib.h>
int main()
{
int n=0,m=0,i=0,j=0,count=0,a[1000],c[1000];
scanf("%d %d",&n,&m);
//a=(int *)malloc(sizeof(int)*n);
//c=(int *)malloc(sizeof(int)*m);
for(i=0;i<n;i++)
{
scanf("%d",&c[i]);
}
for(i=0;i<m;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
if(c[i]<=a[j])
{
count++;
j++;
}
}
printf("%d",count);
//free(a);
//free(c);
return 0;
}
| |
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | 858b79d99b3ab72ae08d554aaf0e4687 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] | #include<stdio.h>
#include<stdlib.h>
int main()
{
int n=0,m=0,i=0,j=0,count=0,*a,*c;
scanf("%d %d",&n,&m);
a=(int *)malloc(sizeof(int)*m);
c=(int *)malloc(sizeof(int)*n);
for(i=0;i<n;i++)
{
scanf("%d",&c[i]);
}
for(i=0;i<m;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
if(c[i]<=a[j])
{
count++;
j++;
}
if(j>=m)
{
break;
}
}
printf("%d",count);
free(a);
free(c);
return 0;
}
| |
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | 1a5018d3b1ca7aca7c256056d5722184 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] | #include<stdio.h>
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int aran[n];
int aram[m];
int flag=0,x=0;
for(int i=0;i<n;i++){
scanf("%d",&aran[i]);
}
for(int i=0;i<m;i++){
scanf("%d",&aram[i]);
}
for(int i=0;i<m;i++){
for(int j=x;j<n;){
if(aram[i]>=aran[j]){
flag++;
j++;
x=j;
break;
}
else{
j++;
x=j;
}
}
}
printf("%d",flag);
}
| |
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | 3a7f6ce8f37915c7ea57c8babd4f8dfa | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] | #include <stdio.h>
int main()
{
int n,m,a[1001],b[1001],i,j,cnt=0;
scanf("%d %d",&n,&m);
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
for(i=0;i<m;i++){
scanf("%d",&b[i]);
}
i=0;j=0;
while(i!=n&&j!=m){
if(a[i]<=b[j]){
i++;
j++;
cnt++;
}
else{
i++;
}
}
printf("%d",cnt);
return 0;
}
| |
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | 14972ab0fd2418a6eb43204b5125c553 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] | #include <stdio.h>
#include <stdlib.h>
int main(void)
{
int n, m;
int *c, *a;
int i, j, count = 0;
scanf("%d %d", &n, &m);
c = malloc(sizeof(int) * n);
a = malloc(sizeof(int) * m);
for(i = 0; i < n; i++)
{
scanf("%d", &c[i]);
}
for(i = 0; i < m; i++)
{
scanf("%d", &a[i]);
}
for(i = 0, j = 0; i < m && j < n; )
{
if (a[i] >= c[j])
{
i++;
j++;
count++;
}
else if (a[i] < c[j])
{
j++;
}
}
printf("%d\n", count);
free(c);
free(a);
return 0;
}
| |
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | b76d6b971371b109056dc86c38acd5a4 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] | #include<stdio.h>
int main()
{
int a,b,count=0;
scanf("%d %d",&a,&b);
int aa[a],ab[b],i,j=0;
for(i=0;i<a;i++)
scanf("%d",&aa[i]);
for(i=0;i<b;i++)
scanf("%d",&ab[i]);
for(i=0;i<a;i++){
for(;j<b;){
if(aa[i]<=ab[j]){
count++;
j++;
break;
}
else
break;
}
}
printf("%d\n",count);
return 0;
}
| |
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | 38e380c90fa359402b2d40652eb60f8a | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] | #include<stdio.h>
int main()
{
int i,j,k[10000],a,b,count=0,l[10000],c=0;
scanf("%d %d",&a,&b);
for(i=0;i<a;i++)
{
scanf("%d",&k[i]);
}
for(j=0;j<b;j++)
{
scanf("%d",&l[j]);
for(c=c;c<a;c++)
{
if(l[j]>=k[c])
{
count++;
c=c+1;
break;
}
}
}
printf("%d\n",count);
return 0;
}
| |
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | 49041abfe8f3caa893588a1eee3c12ca | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] | #include <stdio.h>
#include <math.h>
int main ()
{int n,m,i,j,a[1000],c[1000];
scanf ("%d",&n);
scanf ("%d",&m);
for (i=0;i<n;i++)
scanf ("%d",&c[i]);
for (j=0;j<m;j++)
scanf ("%d",&a[j]);
int com=0;
i=0;
j=0;
while(i<n && j<m)
{if (a[j]>=c[i])
{i++;
j++;
com++;}
else
i++;}
printf ("%d",com);
} | |
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | a93373b54399dc3c32fb94521b9e5dcc | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] | /******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby,
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <stdio.h>
int main()
{
int i,j=0,m,n,count=0;
scanf("%d %d",&n,&m);
int c[n];
int b[m];
for(i=0;i<n;i++)
{
scanf("%d",&c[i]);
}
for(i=0;i<m;i++)
{
scanf("%d",&b[i]);
}
for(i=0;i<n;i++)
{
if(c[i]<=b[j])
{
count++;
j++;
}
if(j==m)
break;
}
printf("%d",count);
return 0;
} | |
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | 71c3083dacd0d78ea5ec077cb4fce5e0 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] | #include <stdio.h>
int main(){
int n = 0, m = 0, j[1001]={}, d[1001]={}, i =0, z = 0;
scanf("%d %d", &n, &m);
for(i=0;i<n;i++){
scanf("%d", &j[i]);
}
for(i=0;i<m;i++){
scanf("%d", &d[i]);
}
for(i=0, z = 0;i<m && z<n;z++){
if(d[i]>=j[z]){
i++;
}
}
printf("%d\n", i);
return 0;
}
| |
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | 04bb37502a0b5a54387374bb3c8b8377 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] | #include<stdio.h>
int main()
{
int n,m,i,j;
int count=0;
scanf("%d %d",&n,&m);
int c[1010];
int a[1010];
for(i=0;i<n;i++)
{
scanf("%d",&c[i]);
}
i=0;
for(j=0;j<m;j++)
{
scanf("%d",&a[j]);
}
j=0;
for(i=0;i<n;i++)
{
if(a[j]>=c[i])
{
count+=1;
j+=1;
}
if(j>=m)
break;
}
printf("%d\n",count);
return 0;
}
| |
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | a37d47ff31a9e2777302f429a3287b0c | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] | #include<stdio.h>
int main()
{
int n,m;
int i,j,k=0,games=0,count=0;
int w[1001], c[1001];
scanf("%d %d", &n, &m);
for(i=0; i<n; i++)
{
scanf("%d", &c[i]);
}
for(i=0; i<m; i++)
{
scanf("%d", &w[i]);
}
// First condition
for(i=0; i<n; i++)
{
if(w[0] < c[i])
{
count++;
}
}
if(count==n)
{
printf("0\n");
return 0;
}
// 2nd condition
for(i=0; i<m; )
{
for(j=0; j<n; j++)
{
if(w[i]>=c[j])
{
games++;
i++;
}
}
if(j==n)
{
break;
}
}
printf("%d\n", games);
return 0;
} | |
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | cd0aa997dbfe77c770d7cd14acc99eb7 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] | #include<stdio.h>
int main()
{
int i,j,m,n,count=0;
scanf("%d %d",&n,&m);
int c[n],a[m];
for(i=0;i<n;i++){
scanf("%d",&c[i]);
}
for(i=0;i<m;i++){
scanf("%d",&a[i]);
}
for(i=0,j=0;i<n;i++){
if(j==m) break;
if(a[j]>=c[i]){
count++;
j++;
}
}
printf("%d",count);
return 0;
}
| |
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | bd2f445d95cf4892284733a320a921e2 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] | #include <stdio.h>
#define max 1007
int main()
{
int n, i, count = 0, m, c[max], a[max], front = 0;
scanf("%d %d", &n, &m);
for(i = 0; i < n; i++)
scanf("%d", &c[i]);
for(i = 0;i < m; i++)
scanf("%d", &a[i]);
for(i = 0; i < n && front < m; i++){
if(a[front] >= c[i]){
count++;
front++;
}
else if(!a[front])
front++;
}
printf("%d\n", count);
return 0;
}
| |
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | 2894bc3d9844ad7c17db1b6c35a97228 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] | #include <stdio.h>
#define ll long long
int main()
{
int i, j, n, k, r=0, cnt =0,a[10005], b[10005];
scanf("%d%d",&n,&k);
for (i=0;i<n;i++){
scanf("%d",&a[i]);
}
for (i=0;i<k;i++){
scanf("%d",&b[i]);
}
i=0,j=0;
while (j<n){
if(b[i]>=a[j]){
cnt++;
i++;
j++;
}
else j++;
}
printf("%d\n",cnt);
return 0;
} | |
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | 39a029b48e5fd0864f3f47d45542f6d1 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*int main()
{
char a[100];
int i,j;
scanf("%d",&i);
for(j=0;j<i;j++)
{
scanf("%s",a);
if(strlen(a)>10)
{
printf("%c%d%c\n",a[0],strlen(a)-2,a[strlen(a)-1]);
}
else
printf("%s\n",a);
memset( a, 0, sizeof(a) );
}
}
*/
/*
int main()
{
int i,s,rest=0;
int a[50];
int n,k;
scanf("%d%d",&n,&k);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(i==k-1)
s=a[i];
}
for(i=0;i<n;i++)
{
if(a[i]>=s&&a[i]>0)
rest++;
}
printf("%d",rest);
}*/
/*
int main()
{
char a[100];
scanf("%s",a);
int i;
for(i=0;i<strlen(a);i++)
{
if(a[i]=='A'||a[i]=='O'||a[i]=='Y'||a[i]=='E'||a[i]=='U'||a[i]=='I'
||a[i]=='a'||a[i]=='o'||a[i]=='y'||a[i]=='e'||a[i]=='u'||a[i]=='i')
{
;
}
else
{
if(a[i]>='A'&&a[i]<='Z')
a[i]=a[i]+32;
printf(".%c",a[i]);
}
}
}*/
/*
int main()
{
int n,m;
int sum;
scanf("%d%d",&n,&m);
sum=n*m/2;
printf("%d",sum);
}
*/
/*
int main()
{
int n,i,j,sum=0,r=0;
int a[3];
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[j]);
if(a[j]==1)
r++;
}
if(r>=2)
sum++;
memset(a,0,sizeof(a));
r=0;
}
printf("%d",sum);
}
*/
/*
int main()
{
int n,i,j=0;
int sum=0,r=0;
int a[1000];
int b[1000];
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
r++;
if(a[i]==1)
{
sum++;
b[j]=r;
j++;
r=0;
}
if(i==n-1)
{
b[j]=r+1;
}
}
printf("%d\n",sum);
for(j=1;j<sum+1;j++)
printf("%d ",b[j]);
}
*/
/*
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
string s1,s2;
int n1,n2,i,j,num=0;
cin>>s1>>s2;
n1=s1.length()-1;
n2=s2.length()-1;
for(i=n1,j=n2;i>=0,j>=0;i--,j--)
{
if(s1[i]==s2[j])
num+=2;
else
break;
}
cout<<n1+n2+2-num<<endl;
return 0;
}
*/
int main()
{
int a[1000];
int b[1000];
int n,m,i,j=0,count=0;
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<m;i++)
{
scanf("%d",&b[i]);
}
for(i=0;i<n;i++)
{
if(a[i]<=b[j])
{
j++;
count++;
}
}
printf("%d",count);
}
| |
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | 5415d621c645048ed1509dc131e4f5de | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] | #include<stdio.h>
int main()
{
int i=0,j=0,n,a[10000],m,b[10000],c=0,k=0,d[10000],min,e[10000],l=0;
scanf("%d %d",&n,&m);
min=d[0];
e[0]=0;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<m;i++)
{
scanf("%d",&b[i]);
}
for(i=0;i<n;)
{
for(j=0;j<m;)
{
if(b[j]>=a[i])
{
j++;
i++;
e[l]++;
if(i==n || j==m)
{
d[k++]=e[l++];
}
}
else
{
i++;
if(i==n || j==m)
{
d[k++]=e[l++];
}
}
}
}
printf("%d",d[0]);
return 0;
} | |
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | 5dcc034faaef5e6a8d6a153e9cf1ad7b | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int x=0,n,m,a[1000],c[1000],i,j=0;
do
scanf("%d%d",&n,&m);
while(n>1000 || m>1000 || n<1 || m<1);
for(i=0;i<n;i++)
scanf("%d",&c[i]);
for(i=0;i<m;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
if(c[i]<=a[j])
{
j++;
x++;
}
printf("%d",x);
return 0;
}
| |
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | 98cb1d18b00c96fdf3980d3703a94149 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] | #include<stdio.h>
int main()
{
int n,m;
int i,j,k=0,games=0,count=0;
int w[1001], c[1001];
scanf("%d %d", &n, &m);
for(i=0; i<n; i++)
{
scanf("%d", &c[i]);
}
for(i=0; i<m; i++)
{
scanf("%d", &w[i]);
}
// First condition
for(i=0; i<n; i++)
{
if(w[0] < c[i])
{
count++;
}
}
if(count==n)
{
printf("0\n");
return 0;
}
// 2nd condition
for(i=0; i<m; )
{
for(j=0; j<n; j++)
{
if(w[i]>=c[j])
{
games++;
i++;
}
}
if(j==n)
{
break;
}
}
printf("%d\n", games);
return 0;
} | |
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | 997e267eec555130fd398b14e4e8d2c5 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] | #include<stdio.h>
main()
{
int n,m,i,c,k,j;
scanf("%d %d",&n,&m);
c=0;
k=0;
int a[n];
int b[m];
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<m;i++)
scanf("%d",&b[i]);
for(i=0;i<m;i++)
{
for(j=k;j<n;j++)
{
if(b[i]>=a[j])
{
c++;
k=j+1;
break;
}
}
if(j>=n)
break;
}
printf("%d",c);
}
| |
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | 5719fa6c6766349bd37b2df92a8bcb5a | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] | #include<stdio.h>
int main()
{
int c[1000], a[1000], n, m, i, j, count = 0;
scanf("%d %d", &n, &m);
if (n >= 1 && m <= 1000)
{
for (i = 0; i < n; i++)
{
scanf("%d", &c[i]);
}
for (j = 0; j < m; j++)
{
scanf("%d", &a[j]);
}
j=0;
for (i = 0; i < n; i++)
{
if (a[j] >= c[i])
{
count++;
j++;
}
else
continue;
}
}
printf("%d\n", count);
return 0;
} | |
Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy. | Print a single integer — the number of games Maxim will buy. | C | c3f080681e3da5e1290ef935ff91f364 | 5088d7b72804f3c620d0f6c026b951a0 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1531578900 | ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000"] | NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet. | PASSED | 800 | standard input | 1 second | The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet. | ["3", "0", "4"] | #include<stdio.h>
int main()
{
int n, m, cost[1010], bill[1010], i, count=0, j;
scanf("%d%d", &n, &m);
for(i=0; i<n; i++)
{
scanf("%d",&cost[i]);
}
for(i=0; i<m; i++)
{
scanf("%d", &bill[i]);
}
for(i=0,j=0; i<n; i++)
{
if(cost[i]<=bill[j])
{
count++;
j++;
}
}
printf("%d\n", count);
return 0;
}
| |
Vova plans to go to the conference by train. Initially, the train is at the point $$$1$$$ and the destination point of the path is the point $$$L$$$. The speed of the train is $$$1$$$ length unit per minute (i.e. at the first minute the train is at the point $$$1$$$, at the second minute — at the point $$$2$$$ and so on).There are lanterns on the path. They are placed at the points with coordinates divisible by $$$v$$$ (i.e. the first lantern is at the point $$$v$$$, the second is at the point $$$2v$$$ and so on).There is also exactly one standing train which occupies all the points from $$$l$$$ to $$$r$$$ inclusive.Vova can see the lantern at the point $$$p$$$ if $$$p$$$ is divisible by $$$v$$$ and there is no standing train at this position ($$$p \not\in [l; r]$$$). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to $$$t$$$ different conferences, so you should answer $$$t$$$ independent queries. | Print $$$t$$$ lines. The $$$i$$$-th line should contain one integer — the answer for the $$$i$$$-th query. | C | 5194846a503c2087fcd299eaf3c20b2b | cab1038b9038f1c5e1f396ce4fe05cbc | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1539354900 | ["4\n10 2 3 7\n100 51 51 51\n1234 1 100 199\n1000000000 1 1 1000000000"] | NoteFor the first example query, the answer is $$$3$$$. There are lanterns at positions $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$ and $$$10$$$, but Vova didn't see the lanterns at positions $$$4$$$ and $$$6$$$ because of the standing train.For the second example query, the answer is $$$0$$$ because the only lantern is at the point $$$51$$$ and there is also a standing train at this point.For the third example query, the answer is $$$1134$$$ because there are $$$1234$$$ lanterns, but Vova didn't see the lanterns from the position $$$100$$$ to the position $$$199$$$ inclusive.For the fourth example query, the answer is $$$0$$$ because the standing train covers the whole path. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of queries. Then $$$t$$$ lines follow. The $$$i$$$-th line contains four integers $$$L_i, v_i, l_i, r_i$$$ ($$$1 \le L, v \le 10^9$$$, $$$1 \le l \le r \le L$$$) — destination point of the $$$i$$$-th path, the period of the lantern appearance and the segment occupied by the standing train. | ["3\n0\n1134\n0"] | #include <stdio.h>
void Find(int L,int v,int l,int r)
{
int AL,HL,SL;
AL=L/v;
HL=r/v - l/v;
if(l%v==0)
{
HL++;
}
SL=AL-HL;
printf("%d\n",SL);
}
int main()
{
int i,L,v,l,r,n;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&L);
scanf("%d",&v);
scanf("%d",&l);
scanf("%d",&r);
Find(L,v,l,r);
}
return 0;
}
| |
Vova plans to go to the conference by train. Initially, the train is at the point $$$1$$$ and the destination point of the path is the point $$$L$$$. The speed of the train is $$$1$$$ length unit per minute (i.e. at the first minute the train is at the point $$$1$$$, at the second minute — at the point $$$2$$$ and so on).There are lanterns on the path. They are placed at the points with coordinates divisible by $$$v$$$ (i.e. the first lantern is at the point $$$v$$$, the second is at the point $$$2v$$$ and so on).There is also exactly one standing train which occupies all the points from $$$l$$$ to $$$r$$$ inclusive.Vova can see the lantern at the point $$$p$$$ if $$$p$$$ is divisible by $$$v$$$ and there is no standing train at this position ($$$p \not\in [l; r]$$$). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to $$$t$$$ different conferences, so you should answer $$$t$$$ independent queries. | Print $$$t$$$ lines. The $$$i$$$-th line should contain one integer — the answer for the $$$i$$$-th query. | C | 5194846a503c2087fcd299eaf3c20b2b | 65e5b2b37663b47b4edb4efcd7d6cdb0 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1539354900 | ["4\n10 2 3 7\n100 51 51 51\n1234 1 100 199\n1000000000 1 1 1000000000"] | NoteFor the first example query, the answer is $$$3$$$. There are lanterns at positions $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$ and $$$10$$$, but Vova didn't see the lanterns at positions $$$4$$$ and $$$6$$$ because of the standing train.For the second example query, the answer is $$$0$$$ because the only lantern is at the point $$$51$$$ and there is also a standing train at this point.For the third example query, the answer is $$$1134$$$ because there are $$$1234$$$ lanterns, but Vova didn't see the lanterns from the position $$$100$$$ to the position $$$199$$$ inclusive.For the fourth example query, the answer is $$$0$$$ because the standing train covers the whole path. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of queries. Then $$$t$$$ lines follow. The $$$i$$$-th line contains four integers $$$L_i, v_i, l_i, r_i$$$ ($$$1 \le L, v \le 10^9$$$, $$$1 \le l \le r \le L$$$) — destination point of the $$$i$$$-th path, the period of the lantern appearance and the segment occupied by the standing train. | ["3\n0\n1134\n0"] | #include<stdio.h>
int main ()
{
long long int l,t,v,r,s,x,y,z;
scanf("%lld",&t);
for ( int i=0;i<t;++i)
{
scanf("%lld %lld %lld %lld",&l,&v,&r,&s);
x=l/v;
y=r/v;
z=s/v;
if ((r%v)==0 && (s%v)==0)
{
printf("%lld\n",(x+y-z-1));
}
else if((r%v)==0 && (s%v)!=0)
{
printf("%lld\n",(x+y-z-1));
}
else
{
printf ("%lld\n",(x+y-z));
}
}
return 0;
}
| |
Vova plans to go to the conference by train. Initially, the train is at the point $$$1$$$ and the destination point of the path is the point $$$L$$$. The speed of the train is $$$1$$$ length unit per minute (i.e. at the first minute the train is at the point $$$1$$$, at the second minute — at the point $$$2$$$ and so on).There are lanterns on the path. They are placed at the points with coordinates divisible by $$$v$$$ (i.e. the first lantern is at the point $$$v$$$, the second is at the point $$$2v$$$ and so on).There is also exactly one standing train which occupies all the points from $$$l$$$ to $$$r$$$ inclusive.Vova can see the lantern at the point $$$p$$$ if $$$p$$$ is divisible by $$$v$$$ and there is no standing train at this position ($$$p \not\in [l; r]$$$). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to $$$t$$$ different conferences, so you should answer $$$t$$$ independent queries. | Print $$$t$$$ lines. The $$$i$$$-th line should contain one integer — the answer for the $$$i$$$-th query. | C | 5194846a503c2087fcd299eaf3c20b2b | 55a9ef96ce3cd199eff995b8bea2a9c7 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1539354900 | ["4\n10 2 3 7\n100 51 51 51\n1234 1 100 199\n1000000000 1 1 1000000000"] | NoteFor the first example query, the answer is $$$3$$$. There are lanterns at positions $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$ and $$$10$$$, but Vova didn't see the lanterns at positions $$$4$$$ and $$$6$$$ because of the standing train.For the second example query, the answer is $$$0$$$ because the only lantern is at the point $$$51$$$ and there is also a standing train at this point.For the third example query, the answer is $$$1134$$$ because there are $$$1234$$$ lanterns, but Vova didn't see the lanterns from the position $$$100$$$ to the position $$$199$$$ inclusive.For the fourth example query, the answer is $$$0$$$ because the standing train covers the whole path. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of queries. Then $$$t$$$ lines follow. The $$$i$$$-th line contains four integers $$$L_i, v_i, l_i, r_i$$$ ($$$1 \le L, v \le 10^9$$$, $$$1 \le l \le r \le L$$$) — destination point of the $$$i$$$-th path, the period of the lantern appearance and the segment occupied by the standing train. | ["3\n0\n1134\n0"] | #include<stdio.h>
int main (){
int t,l,v,a,b,i=0,m;
scanf("%d",&t);
while(i<t){
scanf("%d %d %d %d",&l,&v,&a,&b);
m=(l/v)-((b/v)-(a/v));
if(a%v==0){
m=m-1;}
i++;
printf("%d\n",m);
}
return 0;
} | |
Vova plans to go to the conference by train. Initially, the train is at the point $$$1$$$ and the destination point of the path is the point $$$L$$$. The speed of the train is $$$1$$$ length unit per minute (i.e. at the first minute the train is at the point $$$1$$$, at the second minute — at the point $$$2$$$ and so on).There are lanterns on the path. They are placed at the points with coordinates divisible by $$$v$$$ (i.e. the first lantern is at the point $$$v$$$, the second is at the point $$$2v$$$ and so on).There is also exactly one standing train which occupies all the points from $$$l$$$ to $$$r$$$ inclusive.Vova can see the lantern at the point $$$p$$$ if $$$p$$$ is divisible by $$$v$$$ and there is no standing train at this position ($$$p \not\in [l; r]$$$). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to $$$t$$$ different conferences, so you should answer $$$t$$$ independent queries. | Print $$$t$$$ lines. The $$$i$$$-th line should contain one integer — the answer for the $$$i$$$-th query. | C | 5194846a503c2087fcd299eaf3c20b2b | 892757558fd4459659b80195fe8dbaed | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1539354900 | ["4\n10 2 3 7\n100 51 51 51\n1234 1 100 199\n1000000000 1 1 1000000000"] | NoteFor the first example query, the answer is $$$3$$$. There are lanterns at positions $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$ and $$$10$$$, but Vova didn't see the lanterns at positions $$$4$$$ and $$$6$$$ because of the standing train.For the second example query, the answer is $$$0$$$ because the only lantern is at the point $$$51$$$ and there is also a standing train at this point.For the third example query, the answer is $$$1134$$$ because there are $$$1234$$$ lanterns, but Vova didn't see the lanterns from the position $$$100$$$ to the position $$$199$$$ inclusive.For the fourth example query, the answer is $$$0$$$ because the standing train covers the whole path. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of queries. Then $$$t$$$ lines follow. The $$$i$$$-th line contains four integers $$$L_i, v_i, l_i, r_i$$$ ($$$1 \le L, v \le 10^9$$$, $$$1 \le l \le r \le L$$$) — destination point of the $$$i$$$-th path, the period of the lantern appearance and the segment occupied by the standing train. | ["3\n0\n1134\n0"] | #include<stdio.h>
int main()
{
long long t,l,v,a,b,x,k;
scanf("%lld",&t);
for(int i=0;i<t;i++)
{
scanf("%lld %lld %lld %lld",&l,&v,&a,&b);
k=l/v;
x=b/v-a/v;
if(a%v==0)
printf("%lld \n",k-x-1);
else
printf("%lld \n",k-x);
}
return 0;
} | |
Vova plans to go to the conference by train. Initially, the train is at the point $$$1$$$ and the destination point of the path is the point $$$L$$$. The speed of the train is $$$1$$$ length unit per minute (i.e. at the first minute the train is at the point $$$1$$$, at the second minute — at the point $$$2$$$ and so on).There are lanterns on the path. They are placed at the points with coordinates divisible by $$$v$$$ (i.e. the first lantern is at the point $$$v$$$, the second is at the point $$$2v$$$ and so on).There is also exactly one standing train which occupies all the points from $$$l$$$ to $$$r$$$ inclusive.Vova can see the lantern at the point $$$p$$$ if $$$p$$$ is divisible by $$$v$$$ and there is no standing train at this position ($$$p \not\in [l; r]$$$). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to $$$t$$$ different conferences, so you should answer $$$t$$$ independent queries. | Print $$$t$$$ lines. The $$$i$$$-th line should contain one integer — the answer for the $$$i$$$-th query. | C | 5194846a503c2087fcd299eaf3c20b2b | b8ebf5e0f07ff7642d972e35e77e08e9 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1539354900 | ["4\n10 2 3 7\n100 51 51 51\n1234 1 100 199\n1000000000 1 1 1000000000"] | NoteFor the first example query, the answer is $$$3$$$. There are lanterns at positions $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$ and $$$10$$$, but Vova didn't see the lanterns at positions $$$4$$$ and $$$6$$$ because of the standing train.For the second example query, the answer is $$$0$$$ because the only lantern is at the point $$$51$$$ and there is also a standing train at this point.For the third example query, the answer is $$$1134$$$ because there are $$$1234$$$ lanterns, but Vova didn't see the lanterns from the position $$$100$$$ to the position $$$199$$$ inclusive.For the fourth example query, the answer is $$$0$$$ because the standing train covers the whole path. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of queries. Then $$$t$$$ lines follow. The $$$i$$$-th line contains four integers $$$L_i, v_i, l_i, r_i$$$ ($$$1 \le L, v \le 10^9$$$, $$$1 \le l \le r \le L$$$) — destination point of the $$$i$$$-th path, the period of the lantern appearance and the segment occupied by the standing train. | ["3\n0\n1134\n0"] | #include<stdio.h>
int main()
{
int t,L,v,r,l,i;
scanf("%d",&t);
for(i=0;i<t;i++){
scanf("%d %d %d %d",&L,&v,&l,&r);
printf("%d\n",(L/v)-(r/v)+((l-1)/v));
}
return 0;
}
| |
Vova plans to go to the conference by train. Initially, the train is at the point $$$1$$$ and the destination point of the path is the point $$$L$$$. The speed of the train is $$$1$$$ length unit per minute (i.e. at the first minute the train is at the point $$$1$$$, at the second minute — at the point $$$2$$$ and so on).There are lanterns on the path. They are placed at the points with coordinates divisible by $$$v$$$ (i.e. the first lantern is at the point $$$v$$$, the second is at the point $$$2v$$$ and so on).There is also exactly one standing train which occupies all the points from $$$l$$$ to $$$r$$$ inclusive.Vova can see the lantern at the point $$$p$$$ if $$$p$$$ is divisible by $$$v$$$ and there is no standing train at this position ($$$p \not\in [l; r]$$$). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to $$$t$$$ different conferences, so you should answer $$$t$$$ independent queries. | Print $$$t$$$ lines. The $$$i$$$-th line should contain one integer — the answer for the $$$i$$$-th query. | C | 5194846a503c2087fcd299eaf3c20b2b | 1ef882f4c2c788cb8d7ba51d45a294e4 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1539354900 | ["4\n10 2 3 7\n100 51 51 51\n1234 1 100 199\n1000000000 1 1 1000000000"] | NoteFor the first example query, the answer is $$$3$$$. There are lanterns at positions $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$ and $$$10$$$, but Vova didn't see the lanterns at positions $$$4$$$ and $$$6$$$ because of the standing train.For the second example query, the answer is $$$0$$$ because the only lantern is at the point $$$51$$$ and there is also a standing train at this point.For the third example query, the answer is $$$1134$$$ because there are $$$1234$$$ lanterns, but Vova didn't see the lanterns from the position $$$100$$$ to the position $$$199$$$ inclusive.For the fourth example query, the answer is $$$0$$$ because the standing train covers the whole path. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of queries. Then $$$t$$$ lines follow. The $$$i$$$-th line contains four integers $$$L_i, v_i, l_i, r_i$$$ ($$$1 \le L, v \le 10^9$$$, $$$1 \le l \le r \le L$$$) — destination point of the $$$i$$$-th path, the period of the lantern appearance and the segment occupied by the standing train. | ["3\n0\n1134\n0"] | #include<stdio.h>
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
int x,n,v,l,r,x1,x2,x3;
scanf("%d%d%d%d", &n,&v,&l,&r);
x=(n-r+l);
x1=n/v;
x2=l/v;
x3=r/v;
if(n-r+l<0)
printf("0\n");
else
{ if(l%v==0)
printf("%d\n", x1+x2-x3-1);
else if(l==r && l%v==0)
{
x1=n/v;
x2=l/v;
x3=r/v;
printf("%d\n", x1+x2-x3-1);
}
else
{
x1=n/v;
x2=l/v;
x3=r/v;
printf("%d\n", x1+x2-x3);
}
}
}
}
| |
Vova plans to go to the conference by train. Initially, the train is at the point $$$1$$$ and the destination point of the path is the point $$$L$$$. The speed of the train is $$$1$$$ length unit per minute (i.e. at the first minute the train is at the point $$$1$$$, at the second minute — at the point $$$2$$$ and so on).There are lanterns on the path. They are placed at the points with coordinates divisible by $$$v$$$ (i.e. the first lantern is at the point $$$v$$$, the second is at the point $$$2v$$$ and so on).There is also exactly one standing train which occupies all the points from $$$l$$$ to $$$r$$$ inclusive.Vova can see the lantern at the point $$$p$$$ if $$$p$$$ is divisible by $$$v$$$ and there is no standing train at this position ($$$p \not\in [l; r]$$$). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to $$$t$$$ different conferences, so you should answer $$$t$$$ independent queries. | Print $$$t$$$ lines. The $$$i$$$-th line should contain one integer — the answer for the $$$i$$$-th query. | C | 5194846a503c2087fcd299eaf3c20b2b | a87aa80089f32956a8b42b8a0538bc25 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1539354900 | ["4\n10 2 3 7\n100 51 51 51\n1234 1 100 199\n1000000000 1 1 1000000000"] | NoteFor the first example query, the answer is $$$3$$$. There are lanterns at positions $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$ and $$$10$$$, but Vova didn't see the lanterns at positions $$$4$$$ and $$$6$$$ because of the standing train.For the second example query, the answer is $$$0$$$ because the only lantern is at the point $$$51$$$ and there is also a standing train at this point.For the third example query, the answer is $$$1134$$$ because there are $$$1234$$$ lanterns, but Vova didn't see the lanterns from the position $$$100$$$ to the position $$$199$$$ inclusive.For the fourth example query, the answer is $$$0$$$ because the standing train covers the whole path. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of queries. Then $$$t$$$ lines follow. The $$$i$$$-th line contains four integers $$$L_i, v_i, l_i, r_i$$$ ($$$1 \le L, v \le 10^9$$$, $$$1 \le l \le r \le L$$$) — destination point of the $$$i$$$-th path, the period of the lantern appearance and the segment occupied by the standing train. | ["3\n0\n1134\n0"] | #include<stdio.h>
int main()
{
int t,L,v,l,r,i,j,p;
scanf("%d",&t);
for(i=0;i<t;i++)
{
scanf("%d%d%d%d",&L,&v,&l,&r);
printf("%d\n",(L/v)-(r/v)+(l-1)/v);
}
return 0;
}
| |
Vova plans to go to the conference by train. Initially, the train is at the point $$$1$$$ and the destination point of the path is the point $$$L$$$. The speed of the train is $$$1$$$ length unit per minute (i.e. at the first minute the train is at the point $$$1$$$, at the second minute — at the point $$$2$$$ and so on).There are lanterns on the path. They are placed at the points with coordinates divisible by $$$v$$$ (i.e. the first lantern is at the point $$$v$$$, the second is at the point $$$2v$$$ and so on).There is also exactly one standing train which occupies all the points from $$$l$$$ to $$$r$$$ inclusive.Vova can see the lantern at the point $$$p$$$ if $$$p$$$ is divisible by $$$v$$$ and there is no standing train at this position ($$$p \not\in [l; r]$$$). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to $$$t$$$ different conferences, so you should answer $$$t$$$ independent queries. | Print $$$t$$$ lines. The $$$i$$$-th line should contain one integer — the answer for the $$$i$$$-th query. | C | 5194846a503c2087fcd299eaf3c20b2b | 1f91ac82488aef19e023e0852fa6b244 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1539354900 | ["4\n10 2 3 7\n100 51 51 51\n1234 1 100 199\n1000000000 1 1 1000000000"] | NoteFor the first example query, the answer is $$$3$$$. There are lanterns at positions $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$ and $$$10$$$, but Vova didn't see the lanterns at positions $$$4$$$ and $$$6$$$ because of the standing train.For the second example query, the answer is $$$0$$$ because the only lantern is at the point $$$51$$$ and there is also a standing train at this point.For the third example query, the answer is $$$1134$$$ because there are $$$1234$$$ lanterns, but Vova didn't see the lanterns from the position $$$100$$$ to the position $$$199$$$ inclusive.For the fourth example query, the answer is $$$0$$$ because the standing train covers the whole path. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of queries. Then $$$t$$$ lines follow. The $$$i$$$-th line contains four integers $$$L_i, v_i, l_i, r_i$$$ ($$$1 \le L, v \le 10^9$$$, $$$1 \le l \le r \le L$$$) — destination point of the $$$i$$$-th path, the period of the lantern appearance and the segment occupied by the standing train. | ["3\n0\n1134\n0"] | #include <stdio.h>
int main() {
int n;
scanf("%d",&n);
for (int i=0;i<n;++i)
{
int k,v,l,r;
scanf("%d %d %d %d",&k,&v,&l,&r);
printf("%d\n",k/v-r/v+(l-1)/v);
}
return 0;
}
| |
Vova plans to go to the conference by train. Initially, the train is at the point $$$1$$$ and the destination point of the path is the point $$$L$$$. The speed of the train is $$$1$$$ length unit per minute (i.e. at the first minute the train is at the point $$$1$$$, at the second minute — at the point $$$2$$$ and so on).There are lanterns on the path. They are placed at the points with coordinates divisible by $$$v$$$ (i.e. the first lantern is at the point $$$v$$$, the second is at the point $$$2v$$$ and so on).There is also exactly one standing train which occupies all the points from $$$l$$$ to $$$r$$$ inclusive.Vova can see the lantern at the point $$$p$$$ if $$$p$$$ is divisible by $$$v$$$ and there is no standing train at this position ($$$p \not\in [l; r]$$$). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to $$$t$$$ different conferences, so you should answer $$$t$$$ independent queries. | Print $$$t$$$ lines. The $$$i$$$-th line should contain one integer — the answer for the $$$i$$$-th query. | C | 5194846a503c2087fcd299eaf3c20b2b | 6635bde654f6103d25ccc187ee90428f | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1539354900 | ["4\n10 2 3 7\n100 51 51 51\n1234 1 100 199\n1000000000 1 1 1000000000"] | NoteFor the first example query, the answer is $$$3$$$. There are lanterns at positions $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$ and $$$10$$$, but Vova didn't see the lanterns at positions $$$4$$$ and $$$6$$$ because of the standing train.For the second example query, the answer is $$$0$$$ because the only lantern is at the point $$$51$$$ and there is also a standing train at this point.For the third example query, the answer is $$$1134$$$ because there are $$$1234$$$ lanterns, but Vova didn't see the lanterns from the position $$$100$$$ to the position $$$199$$$ inclusive.For the fourth example query, the answer is $$$0$$$ because the standing train covers the whole path. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of queries. Then $$$t$$$ lines follow. The $$$i$$$-th line contains four integers $$$L_i, v_i, l_i, r_i$$$ ($$$1 \le L, v \le 10^9$$$, $$$1 \le l \le r \le L$$$) — destination point of the $$$i$$$-th path, the period of the lantern appearance and the segment occupied by the standing train. | ["3\n0\n1134\n0"] |
#include <stdio.h>
int main() {
int t;
scanf("%d",&t);
for (int i=0;i<t;++i)
{
int L,v,l,r;
scanf("%d %d %d %d",&L,&v,&l,&r);
printf("%d\n",L/v-r/v+(l-1)/v);
}
return 0;
} | |
Vova plans to go to the conference by train. Initially, the train is at the point $$$1$$$ and the destination point of the path is the point $$$L$$$. The speed of the train is $$$1$$$ length unit per minute (i.e. at the first minute the train is at the point $$$1$$$, at the second minute — at the point $$$2$$$ and so on).There are lanterns on the path. They are placed at the points with coordinates divisible by $$$v$$$ (i.e. the first lantern is at the point $$$v$$$, the second is at the point $$$2v$$$ and so on).There is also exactly one standing train which occupies all the points from $$$l$$$ to $$$r$$$ inclusive.Vova can see the lantern at the point $$$p$$$ if $$$p$$$ is divisible by $$$v$$$ and there is no standing train at this position ($$$p \not\in [l; r]$$$). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to $$$t$$$ different conferences, so you should answer $$$t$$$ independent queries. | Print $$$t$$$ lines. The $$$i$$$-th line should contain one integer — the answer for the $$$i$$$-th query. | C | 5194846a503c2087fcd299eaf3c20b2b | b055ce28c215f153009412e1e7449eb7 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1539354900 | ["4\n10 2 3 7\n100 51 51 51\n1234 1 100 199\n1000000000 1 1 1000000000"] | NoteFor the first example query, the answer is $$$3$$$. There are lanterns at positions $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$ and $$$10$$$, but Vova didn't see the lanterns at positions $$$4$$$ and $$$6$$$ because of the standing train.For the second example query, the answer is $$$0$$$ because the only lantern is at the point $$$51$$$ and there is also a standing train at this point.For the third example query, the answer is $$$1134$$$ because there are $$$1234$$$ lanterns, but Vova didn't see the lanterns from the position $$$100$$$ to the position $$$199$$$ inclusive.For the fourth example query, the answer is $$$0$$$ because the standing train covers the whole path. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of queries. Then $$$t$$$ lines follow. The $$$i$$$-th line contains four integers $$$L_i, v_i, l_i, r_i$$$ ($$$1 \le L, v \le 10^9$$$, $$$1 \le l \le r \le L$$$) — destination point of the $$$i$$$-th path, the period of the lantern appearance and the segment occupied by the standing train. | ["3\n0\n1134\n0"] | #include<stdio.h>
int main()
{
long long int t,L,v,l,r,s,u;
int i,j,k;
scanf("%lld", &t);
for(i=0; i<t; i++)
{
scanf("%lld %lld %lld %lld", &L, &v, &l,&r);
s=(L/v);
if(l%v==0)
{
u=(r/v)-(l/v)+1;
}
else
u=(r/v)-(l/v);
printf("%d\n", s-u);
}
return 0;
}
| |
Vova plans to go to the conference by train. Initially, the train is at the point $$$1$$$ and the destination point of the path is the point $$$L$$$. The speed of the train is $$$1$$$ length unit per minute (i.e. at the first minute the train is at the point $$$1$$$, at the second minute — at the point $$$2$$$ and so on).There are lanterns on the path. They are placed at the points with coordinates divisible by $$$v$$$ (i.e. the first lantern is at the point $$$v$$$, the second is at the point $$$2v$$$ and so on).There is also exactly one standing train which occupies all the points from $$$l$$$ to $$$r$$$ inclusive.Vova can see the lantern at the point $$$p$$$ if $$$p$$$ is divisible by $$$v$$$ and there is no standing train at this position ($$$p \not\in [l; r]$$$). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to $$$t$$$ different conferences, so you should answer $$$t$$$ independent queries. | Print $$$t$$$ lines. The $$$i$$$-th line should contain one integer — the answer for the $$$i$$$-th query. | C | 5194846a503c2087fcd299eaf3c20b2b | f4f4c5d6df7fc525f51a459bb28db598 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1539354900 | ["4\n10 2 3 7\n100 51 51 51\n1234 1 100 199\n1000000000 1 1 1000000000"] | NoteFor the first example query, the answer is $$$3$$$. There are lanterns at positions $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$ and $$$10$$$, but Vova didn't see the lanterns at positions $$$4$$$ and $$$6$$$ because of the standing train.For the second example query, the answer is $$$0$$$ because the only lantern is at the point $$$51$$$ and there is also a standing train at this point.For the third example query, the answer is $$$1134$$$ because there are $$$1234$$$ lanterns, but Vova didn't see the lanterns from the position $$$100$$$ to the position $$$199$$$ inclusive.For the fourth example query, the answer is $$$0$$$ because the standing train covers the whole path. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of queries. Then $$$t$$$ lines follow. The $$$i$$$-th line contains four integers $$$L_i, v_i, l_i, r_i$$$ ($$$1 \le L, v \le 10^9$$$, $$$1 \le l \le r \le L$$$) — destination point of the $$$i$$$-th path, the period of the lantern appearance and the segment occupied by the standing train. | ["3\n0\n1134\n0"] | #include <stdio.h>
#include <stdlib.h>
#define MAX 1000001
int compare(const void* a, const void *b){
return (*(int*)a-*(int*)b);
}
void countingSort(int n, int (*v)[MAX]){
int A[MAX], i;
for(i=0;i<MAX;i++){
A[i] = 0;
}
int C[n];
for(i=0;i<n;i++){
A[(*v)[i]]++;
}
for(i=1;i<MAX;i++){
A[i] += A[i-1];
}
for(i=0;i<n;i++){
C[A[(*v)[i]]-1] = (*v)[i];
A[(*v)[i]]--;
}
for(i=0;i<n;i++){
(*v)[i] = C[i];
}
}
int main(void){
long long L, v, l, r;
int t, i;
scanf("%d", &t);
for(i=0;i<t;i++){
scanf("%I64d%I64d%I64d%I64d", &L, &v, &l, &r);
if(v == 1){
printf("%I64d\n", L-((r-l)+1));
}else{
long long lanterns=0, rem;
if(L%v!=0){
rem = L%v;
L-=rem;
}
if(l%v!=0){
rem = l%v;
l-=rem;
}else{
l-=v;
}
rem = r%v;
r-=rem;
r+=v;
lanterns+=(L/v);
lanterns-=(((r/v)-1) - (l/v));
printf("%I64d\n", lanterns);
}
}
}
| |
Vova plans to go to the conference by train. Initially, the train is at the point $$$1$$$ and the destination point of the path is the point $$$L$$$. The speed of the train is $$$1$$$ length unit per minute (i.e. at the first minute the train is at the point $$$1$$$, at the second minute — at the point $$$2$$$ and so on).There are lanterns on the path. They are placed at the points with coordinates divisible by $$$v$$$ (i.e. the first lantern is at the point $$$v$$$, the second is at the point $$$2v$$$ and so on).There is also exactly one standing train which occupies all the points from $$$l$$$ to $$$r$$$ inclusive.Vova can see the lantern at the point $$$p$$$ if $$$p$$$ is divisible by $$$v$$$ and there is no standing train at this position ($$$p \not\in [l; r]$$$). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to $$$t$$$ different conferences, so you should answer $$$t$$$ independent queries. | Print $$$t$$$ lines. The $$$i$$$-th line should contain one integer — the answer for the $$$i$$$-th query. | C | 5194846a503c2087fcd299eaf3c20b2b | c4339b77486add9ec92f90809d19eb90 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1539354900 | ["4\n10 2 3 7\n100 51 51 51\n1234 1 100 199\n1000000000 1 1 1000000000"] | NoteFor the first example query, the answer is $$$3$$$. There are lanterns at positions $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$ and $$$10$$$, but Vova didn't see the lanterns at positions $$$4$$$ and $$$6$$$ because of the standing train.For the second example query, the answer is $$$0$$$ because the only lantern is at the point $$$51$$$ and there is also a standing train at this point.For the third example query, the answer is $$$1134$$$ because there are $$$1234$$$ lanterns, but Vova didn't see the lanterns from the position $$$100$$$ to the position $$$199$$$ inclusive.For the fourth example query, the answer is $$$0$$$ because the standing train covers the whole path. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of queries. Then $$$t$$$ lines follow. The $$$i$$$-th line contains four integers $$$L_i, v_i, l_i, r_i$$$ ($$$1 \le L, v \le 10^9$$$, $$$1 \le l \le r \le L$$$) — destination point of the $$$i$$$-th path, the period of the lantern appearance and the segment occupied by the standing train. | ["3\n0\n1134\n0"] | #include<stdio.h>
int main()
{
int t;
long L,v,l,r,a,b,c,n;
scanf("%d",&t);
for(int i=0;i<t;i++)
{
scanf("%ld %ld %ld %ld",&L,&v,&l,&r);
a=L/v;
b=r/v;
c=(l-1)/v;
n=a-(b-c);
printf("%ld\n",n);
}
return 0;
}
| |
Vova plans to go to the conference by train. Initially, the train is at the point $$$1$$$ and the destination point of the path is the point $$$L$$$. The speed of the train is $$$1$$$ length unit per minute (i.e. at the first minute the train is at the point $$$1$$$, at the second minute — at the point $$$2$$$ and so on).There are lanterns on the path. They are placed at the points with coordinates divisible by $$$v$$$ (i.e. the first lantern is at the point $$$v$$$, the second is at the point $$$2v$$$ and so on).There is also exactly one standing train which occupies all the points from $$$l$$$ to $$$r$$$ inclusive.Vova can see the lantern at the point $$$p$$$ if $$$p$$$ is divisible by $$$v$$$ and there is no standing train at this position ($$$p \not\in [l; r]$$$). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to $$$t$$$ different conferences, so you should answer $$$t$$$ independent queries. | Print $$$t$$$ lines. The $$$i$$$-th line should contain one integer — the answer for the $$$i$$$-th query. | C | 5194846a503c2087fcd299eaf3c20b2b | 5fefeb846a4aa4ef7ee53fe81181885c | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1539354900 | ["4\n10 2 3 7\n100 51 51 51\n1234 1 100 199\n1000000000 1 1 1000000000"] | NoteFor the first example query, the answer is $$$3$$$. There are lanterns at positions $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$ and $$$10$$$, but Vova didn't see the lanterns at positions $$$4$$$ and $$$6$$$ because of the standing train.For the second example query, the answer is $$$0$$$ because the only lantern is at the point $$$51$$$ and there is also a standing train at this point.For the third example query, the answer is $$$1134$$$ because there are $$$1234$$$ lanterns, but Vova didn't see the lanterns from the position $$$100$$$ to the position $$$199$$$ inclusive.For the fourth example query, the answer is $$$0$$$ because the standing train covers the whole path. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of queries. Then $$$t$$$ lines follow. The $$$i$$$-th line contains four integers $$$L_i, v_i, l_i, r_i$$$ ($$$1 \le L, v \le 10^9$$$, $$$1 \le l \le r \le L$$$) — destination point of the $$$i$$$-th path, the period of the lantern appearance and the segment occupied by the standing train. | ["3\n0\n1134\n0"] | #include <stdio.h>
int main()
{
int tc;
scanf("%d",&tc);
while(tc--){
long long L,V,l,r,lan,ans,ll,rr;
scanf("%lld%lld%lld%lld",&L,&V,&l,&r);
lan=L/V;
if(V<l){
ll=l%V;if(!ll)lan--;
lan-=((r-l+ll)/V);
}
else if(V>=l&&V<=r){
lan--;
lan-=(r-V)/V;
}
printf("%lld\n",lan);
}
} | |
Vova plans to go to the conference by train. Initially, the train is at the point $$$1$$$ and the destination point of the path is the point $$$L$$$. The speed of the train is $$$1$$$ length unit per minute (i.e. at the first minute the train is at the point $$$1$$$, at the second minute — at the point $$$2$$$ and so on).There are lanterns on the path. They are placed at the points with coordinates divisible by $$$v$$$ (i.e. the first lantern is at the point $$$v$$$, the second is at the point $$$2v$$$ and so on).There is also exactly one standing train which occupies all the points from $$$l$$$ to $$$r$$$ inclusive.Vova can see the lantern at the point $$$p$$$ if $$$p$$$ is divisible by $$$v$$$ and there is no standing train at this position ($$$p \not\in [l; r]$$$). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to $$$t$$$ different conferences, so you should answer $$$t$$$ independent queries. | Print $$$t$$$ lines. The $$$i$$$-th line should contain one integer — the answer for the $$$i$$$-th query. | C | 5194846a503c2087fcd299eaf3c20b2b | 973787a8525dadbf0defa66345cf8fae | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1539354900 | ["4\n10 2 3 7\n100 51 51 51\n1234 1 100 199\n1000000000 1 1 1000000000"] | NoteFor the first example query, the answer is $$$3$$$. There are lanterns at positions $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$ and $$$10$$$, but Vova didn't see the lanterns at positions $$$4$$$ and $$$6$$$ because of the standing train.For the second example query, the answer is $$$0$$$ because the only lantern is at the point $$$51$$$ and there is also a standing train at this point.For the third example query, the answer is $$$1134$$$ because there are $$$1234$$$ lanterns, but Vova didn't see the lanterns from the position $$$100$$$ to the position $$$199$$$ inclusive.For the fourth example query, the answer is $$$0$$$ because the standing train covers the whole path. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of queries. Then $$$t$$$ lines follow. The $$$i$$$-th line contains four integers $$$L_i, v_i, l_i, r_i$$$ ($$$1 \le L, v \le 10^9$$$, $$$1 \le l \le r \le L$$$) — destination point of the $$$i$$$-th path, the period of the lantern appearance and the segment occupied by the standing train. | ["3\n0\n1134\n0"] | #include<stdio.h>
#include<math.h>
int main()
{
int i,t;
scanf("%d",&t);
for(i=1;i<=t;i++)
{
long long int h,v,l,r;
scanf("%I64d %I64d %I64d %I64d",&h,&v,&l,&r);
printf("%I64d\n",(h/v)-(r/v)+(l-1)/v);
}
return 0;
}
| |
Vova plans to go to the conference by train. Initially, the train is at the point $$$1$$$ and the destination point of the path is the point $$$L$$$. The speed of the train is $$$1$$$ length unit per minute (i.e. at the first minute the train is at the point $$$1$$$, at the second minute — at the point $$$2$$$ and so on).There are lanterns on the path. They are placed at the points with coordinates divisible by $$$v$$$ (i.e. the first lantern is at the point $$$v$$$, the second is at the point $$$2v$$$ and so on).There is also exactly one standing train which occupies all the points from $$$l$$$ to $$$r$$$ inclusive.Vova can see the lantern at the point $$$p$$$ if $$$p$$$ is divisible by $$$v$$$ and there is no standing train at this position ($$$p \not\in [l; r]$$$). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to $$$t$$$ different conferences, so you should answer $$$t$$$ independent queries. | Print $$$t$$$ lines. The $$$i$$$-th line should contain one integer — the answer for the $$$i$$$-th query. | C | 5194846a503c2087fcd299eaf3c20b2b | 3a162e320de8739b62346d171d084a16 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1539354900 | ["4\n10 2 3 7\n100 51 51 51\n1234 1 100 199\n1000000000 1 1 1000000000"] | NoteFor the first example query, the answer is $$$3$$$. There are lanterns at positions $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$ and $$$10$$$, but Vova didn't see the lanterns at positions $$$4$$$ and $$$6$$$ because of the standing train.For the second example query, the answer is $$$0$$$ because the only lantern is at the point $$$51$$$ and there is also a standing train at this point.For the third example query, the answer is $$$1134$$$ because there are $$$1234$$$ lanterns, but Vova didn't see the lanterns from the position $$$100$$$ to the position $$$199$$$ inclusive.For the fourth example query, the answer is $$$0$$$ because the standing train covers the whole path. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of queries. Then $$$t$$$ lines follow. The $$$i$$$-th line contains four integers $$$L_i, v_i, l_i, r_i$$$ ($$$1 \le L, v \le 10^9$$$, $$$1 \le l \le r \le L$$$) — destination point of the $$$i$$$-th path, the period of the lantern appearance and the segment occupied by the standing train. | ["3\n0\n1134\n0"] | #include<stdio.h>
int main()
{
int t, L, v, l, r, i,p,q,o;
scanf("%d", &t);
for (i=0; i<t; i++)
{scanf("%d%d%d%d", &L, &v, &l, &r);
p=L/v;
q=r/v;
o=(l-1)/v;
p=p-q+o;
printf("%d\n",p);
}
return 0;
} | |
Vova plans to go to the conference by train. Initially, the train is at the point $$$1$$$ and the destination point of the path is the point $$$L$$$. The speed of the train is $$$1$$$ length unit per minute (i.e. at the first minute the train is at the point $$$1$$$, at the second minute — at the point $$$2$$$ and so on).There are lanterns on the path. They are placed at the points with coordinates divisible by $$$v$$$ (i.e. the first lantern is at the point $$$v$$$, the second is at the point $$$2v$$$ and so on).There is also exactly one standing train which occupies all the points from $$$l$$$ to $$$r$$$ inclusive.Vova can see the lantern at the point $$$p$$$ if $$$p$$$ is divisible by $$$v$$$ and there is no standing train at this position ($$$p \not\in [l; r]$$$). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to $$$t$$$ different conferences, so you should answer $$$t$$$ independent queries. | Print $$$t$$$ lines. The $$$i$$$-th line should contain one integer — the answer for the $$$i$$$-th query. | C | 5194846a503c2087fcd299eaf3c20b2b | e293497e93a747f7e2aa1f978b2e570f | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1539354900 | ["4\n10 2 3 7\n100 51 51 51\n1234 1 100 199\n1000000000 1 1 1000000000"] | NoteFor the first example query, the answer is $$$3$$$. There are lanterns at positions $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$ and $$$10$$$, but Vova didn't see the lanterns at positions $$$4$$$ and $$$6$$$ because of the standing train.For the second example query, the answer is $$$0$$$ because the only lantern is at the point $$$51$$$ and there is also a standing train at this point.For the third example query, the answer is $$$1134$$$ because there are $$$1234$$$ lanterns, but Vova didn't see the lanterns from the position $$$100$$$ to the position $$$199$$$ inclusive.For the fourth example query, the answer is $$$0$$$ because the standing train covers the whole path. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of queries. Then $$$t$$$ lines follow. The $$$i$$$-th line contains four integers $$$L_i, v_i, l_i, r_i$$$ ($$$1 \le L, v \le 10^9$$$, $$$1 \le l \le r \le L$$$) — destination point of the $$$i$$$-th path, the period of the lantern appearance and the segment occupied by the standing train. | ["3\n0\n1134\n0"] | #include <stdio.h>
int main(){
int t;
scanf("%i", &t);
while(t--){
int l, v, s, e, c = 0, le;
scanf("%i %i %i %i", &l, &v, &s, &e);
c = ((s-1)/v);
if((e+1)%v == 0){
le = (e+1);
}
else{
le = ((e/v)+1)*v;
}
if(le>l){
le = 0;
}
if(le) c = c + (((l-le)/v)+1);
printf("%i\n", c);
}
return 0;
} | |
Vova plans to go to the conference by train. Initially, the train is at the point $$$1$$$ and the destination point of the path is the point $$$L$$$. The speed of the train is $$$1$$$ length unit per minute (i.e. at the first minute the train is at the point $$$1$$$, at the second minute — at the point $$$2$$$ and so on).There are lanterns on the path. They are placed at the points with coordinates divisible by $$$v$$$ (i.e. the first lantern is at the point $$$v$$$, the second is at the point $$$2v$$$ and so on).There is also exactly one standing train which occupies all the points from $$$l$$$ to $$$r$$$ inclusive.Vova can see the lantern at the point $$$p$$$ if $$$p$$$ is divisible by $$$v$$$ and there is no standing train at this position ($$$p \not\in [l; r]$$$). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to $$$t$$$ different conferences, so you should answer $$$t$$$ independent queries. | Print $$$t$$$ lines. The $$$i$$$-th line should contain one integer — the answer for the $$$i$$$-th query. | C | 5194846a503c2087fcd299eaf3c20b2b | 82b69b81d61f75af9fadb9a8a1a483de | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1539354900 | ["4\n10 2 3 7\n100 51 51 51\n1234 1 100 199\n1000000000 1 1 1000000000"] | NoteFor the first example query, the answer is $$$3$$$. There are lanterns at positions $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$ and $$$10$$$, but Vova didn't see the lanterns at positions $$$4$$$ and $$$6$$$ because of the standing train.For the second example query, the answer is $$$0$$$ because the only lantern is at the point $$$51$$$ and there is also a standing train at this point.For the third example query, the answer is $$$1134$$$ because there are $$$1234$$$ lanterns, but Vova didn't see the lanterns from the position $$$100$$$ to the position $$$199$$$ inclusive.For the fourth example query, the answer is $$$0$$$ because the standing train covers the whole path. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of queries. Then $$$t$$$ lines follow. The $$$i$$$-th line contains four integers $$$L_i, v_i, l_i, r_i$$$ ($$$1 \le L, v \le 10^9$$$, $$$1 \le l \le r \le L$$$) — destination point of the $$$i$$$-th path, the period of the lantern appearance and the segment occupied by the standing train. | ["3\n0\n1134\n0"] | #include <stdio.h>
#include <math.h>
int main()
{
int n;
int s, v, l, r;
scanf("%d", &n);
int counts;
while(n--){
scanf("%d%d%d%d", &s, &v, &l, &r);
counts = s / v;
int left = l / v;
if(l % v) left++;
int right = r / v;
counts -= (right - left + 1);
printf("%d\n", counts);
}
return 0;
} | |
Vova plans to go to the conference by train. Initially, the train is at the point $$$1$$$ and the destination point of the path is the point $$$L$$$. The speed of the train is $$$1$$$ length unit per minute (i.e. at the first minute the train is at the point $$$1$$$, at the second minute — at the point $$$2$$$ and so on).There are lanterns on the path. They are placed at the points with coordinates divisible by $$$v$$$ (i.e. the first lantern is at the point $$$v$$$, the second is at the point $$$2v$$$ and so on).There is also exactly one standing train which occupies all the points from $$$l$$$ to $$$r$$$ inclusive.Vova can see the lantern at the point $$$p$$$ if $$$p$$$ is divisible by $$$v$$$ and there is no standing train at this position ($$$p \not\in [l; r]$$$). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to $$$t$$$ different conferences, so you should answer $$$t$$$ independent queries. | Print $$$t$$$ lines. The $$$i$$$-th line should contain one integer — the answer for the $$$i$$$-th query. | C | 5194846a503c2087fcd299eaf3c20b2b | 2276f5df9cbe7a34acb497a25fa1bceb | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1539354900 | ["4\n10 2 3 7\n100 51 51 51\n1234 1 100 199\n1000000000 1 1 1000000000"] | NoteFor the first example query, the answer is $$$3$$$. There are lanterns at positions $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$ and $$$10$$$, but Vova didn't see the lanterns at positions $$$4$$$ and $$$6$$$ because of the standing train.For the second example query, the answer is $$$0$$$ because the only lantern is at the point $$$51$$$ and there is also a standing train at this point.For the third example query, the answer is $$$1134$$$ because there are $$$1234$$$ lanterns, but Vova didn't see the lanterns from the position $$$100$$$ to the position $$$199$$$ inclusive.For the fourth example query, the answer is $$$0$$$ because the standing train covers the whole path. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of queries. Then $$$t$$$ lines follow. The $$$i$$$-th line contains four integers $$$L_i, v_i, l_i, r_i$$$ ($$$1 \le L, v \le 10^9$$$, $$$1 \le l \le r \le L$$$) — destination point of the $$$i$$$-th path, the period of the lantern appearance and the segment occupied by the standing train. | ["3\n0\n1134\n0"] | #include <stdio.h>
#include <math.h>
int main()
{
int n;
int s, v, l, r;
scanf("%d", &n);
int counts;
while(n--){
scanf("%d%d%d%d", &s, &v, &l, &r);
counts = s / v;
int left = l / v;
if(l % v && l > 0) left++;
int right = r / v;
if(r % v && r < 0) right--;
counts -= (right - left + 1);
printf("%d\n", counts);
}
return 0;
} | |
Vova plans to go to the conference by train. Initially, the train is at the point $$$1$$$ and the destination point of the path is the point $$$L$$$. The speed of the train is $$$1$$$ length unit per minute (i.e. at the first minute the train is at the point $$$1$$$, at the second minute — at the point $$$2$$$ and so on).There are lanterns on the path. They are placed at the points with coordinates divisible by $$$v$$$ (i.e. the first lantern is at the point $$$v$$$, the second is at the point $$$2v$$$ and so on).There is also exactly one standing train which occupies all the points from $$$l$$$ to $$$r$$$ inclusive.Vova can see the lantern at the point $$$p$$$ if $$$p$$$ is divisible by $$$v$$$ and there is no standing train at this position ($$$p \not\in [l; r]$$$). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to $$$t$$$ different conferences, so you should answer $$$t$$$ independent queries. | Print $$$t$$$ lines. The $$$i$$$-th line should contain one integer — the answer for the $$$i$$$-th query. | C | 5194846a503c2087fcd299eaf3c20b2b | df18c27bb8b9bfde0d6c4ebe41ccfccc | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1539354900 | ["4\n10 2 3 7\n100 51 51 51\n1234 1 100 199\n1000000000 1 1 1000000000"] | NoteFor the first example query, the answer is $$$3$$$. There are lanterns at positions $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$ and $$$10$$$, but Vova didn't see the lanterns at positions $$$4$$$ and $$$6$$$ because of the standing train.For the second example query, the answer is $$$0$$$ because the only lantern is at the point $$$51$$$ and there is also a standing train at this point.For the third example query, the answer is $$$1134$$$ because there are $$$1234$$$ lanterns, but Vova didn't see the lanterns from the position $$$100$$$ to the position $$$199$$$ inclusive.For the fourth example query, the answer is $$$0$$$ because the standing train covers the whole path. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of queries. Then $$$t$$$ lines follow. The $$$i$$$-th line contains four integers $$$L_i, v_i, l_i, r_i$$$ ($$$1 \le L, v \le 10^9$$$, $$$1 \le l \le r \le L$$$) — destination point of the $$$i$$$-th path, the period of the lantern appearance and the segment occupied by the standing train. | ["3\n0\n1134\n0"] | #include<stdio.h>
int main(){
int t,L,v,l,r,i,a,b,d;
scanf("%d",&t);
for(i=0;i<t;i++){
scanf("%d",&L);
scanf("%d",&v);
scanf("%d",&l);
scanf("%d",&r);
a=L/v;
b=r/v;
d=(l-1)/v;
r=a-(b-d);
printf("%d\n",r);
}
return 0;
} | |
Vova plans to go to the conference by train. Initially, the train is at the point $$$1$$$ and the destination point of the path is the point $$$L$$$. The speed of the train is $$$1$$$ length unit per minute (i.e. at the first minute the train is at the point $$$1$$$, at the second minute — at the point $$$2$$$ and so on).There are lanterns on the path. They are placed at the points with coordinates divisible by $$$v$$$ (i.e. the first lantern is at the point $$$v$$$, the second is at the point $$$2v$$$ and so on).There is also exactly one standing train which occupies all the points from $$$l$$$ to $$$r$$$ inclusive.Vova can see the lantern at the point $$$p$$$ if $$$p$$$ is divisible by $$$v$$$ and there is no standing train at this position ($$$p \not\in [l; r]$$$). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to $$$t$$$ different conferences, so you should answer $$$t$$$ independent queries. | Print $$$t$$$ lines. The $$$i$$$-th line should contain one integer — the answer for the $$$i$$$-th query. | C | 5194846a503c2087fcd299eaf3c20b2b | 284cc7516709e1c2ee3f6d576c830f3d | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1539354900 | ["4\n10 2 3 7\n100 51 51 51\n1234 1 100 199\n1000000000 1 1 1000000000"] | NoteFor the first example query, the answer is $$$3$$$. There are lanterns at positions $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$ and $$$10$$$, but Vova didn't see the lanterns at positions $$$4$$$ and $$$6$$$ because of the standing train.For the second example query, the answer is $$$0$$$ because the only lantern is at the point $$$51$$$ and there is also a standing train at this point.For the third example query, the answer is $$$1134$$$ because there are $$$1234$$$ lanterns, but Vova didn't see the lanterns from the position $$$100$$$ to the position $$$199$$$ inclusive.For the fourth example query, the answer is $$$0$$$ because the standing train covers the whole path. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of queries. Then $$$t$$$ lines follow. The $$$i$$$-th line contains four integers $$$L_i, v_i, l_i, r_i$$$ ($$$1 \le L, v \le 10^9$$$, $$$1 \le l \le r \le L$$$) — destination point of the $$$i$$$-th path, the period of the lantern appearance and the segment occupied by the standing train. | ["3\n0\n1134\n0"] | #include <stdio.h>
int main(){
int n, L, v, l, r, k, x;
scanf("%d", &n);
for ( int i=1; i <= n; i++){
scanf("%d %d %d %d", &L, &v, &l, &r );
k=( L / v ) + ( l / v ) - ( r / v );
if ( l % v == 0 )
k--;
printf("%d \n", k);
}
}
| |
Vova plans to go to the conference by train. Initially, the train is at the point $$$1$$$ and the destination point of the path is the point $$$L$$$. The speed of the train is $$$1$$$ length unit per minute (i.e. at the first minute the train is at the point $$$1$$$, at the second minute — at the point $$$2$$$ and so on).There are lanterns on the path. They are placed at the points with coordinates divisible by $$$v$$$ (i.e. the first lantern is at the point $$$v$$$, the second is at the point $$$2v$$$ and so on).There is also exactly one standing train which occupies all the points from $$$l$$$ to $$$r$$$ inclusive.Vova can see the lantern at the point $$$p$$$ if $$$p$$$ is divisible by $$$v$$$ and there is no standing train at this position ($$$p \not\in [l; r]$$$). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to $$$t$$$ different conferences, so you should answer $$$t$$$ independent queries. | Print $$$t$$$ lines. The $$$i$$$-th line should contain one integer — the answer for the $$$i$$$-th query. | C | 5194846a503c2087fcd299eaf3c20b2b | bc3a20ae3be4cb5cf0be4c57f65fde85 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1539354900 | ["4\n10 2 3 7\n100 51 51 51\n1234 1 100 199\n1000000000 1 1 1000000000"] | NoteFor the first example query, the answer is $$$3$$$. There are lanterns at positions $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$ and $$$10$$$, but Vova didn't see the lanterns at positions $$$4$$$ and $$$6$$$ because of the standing train.For the second example query, the answer is $$$0$$$ because the only lantern is at the point $$$51$$$ and there is also a standing train at this point.For the third example query, the answer is $$$1134$$$ because there are $$$1234$$$ lanterns, but Vova didn't see the lanterns from the position $$$100$$$ to the position $$$199$$$ inclusive.For the fourth example query, the answer is $$$0$$$ because the standing train covers the whole path. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of queries. Then $$$t$$$ lines follow. The $$$i$$$-th line contains four integers $$$L_i, v_i, l_i, r_i$$$ ($$$1 \le L, v \le 10^9$$$, $$$1 \le l \le r \le L$$$) — destination point of the $$$i$$$-th path, the period of the lantern appearance and the segment occupied by the standing train. | ["3\n0\n1134\n0"] | #include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
int i;
for(i=0;i<t;i++)
{
int L,v,l,r;
scanf("%d %d %d %d",&L,&v,&l,&r);
int no= (L/v) - (r/v) + ((l-1)/v);
printf("%d",no);
if(i!= t-1)printf("\n");
}
return 0;
} | |
Vova plans to go to the conference by train. Initially, the train is at the point $$$1$$$ and the destination point of the path is the point $$$L$$$. The speed of the train is $$$1$$$ length unit per minute (i.e. at the first minute the train is at the point $$$1$$$, at the second minute — at the point $$$2$$$ and so on).There are lanterns on the path. They are placed at the points with coordinates divisible by $$$v$$$ (i.e. the first lantern is at the point $$$v$$$, the second is at the point $$$2v$$$ and so on).There is also exactly one standing train which occupies all the points from $$$l$$$ to $$$r$$$ inclusive.Vova can see the lantern at the point $$$p$$$ if $$$p$$$ is divisible by $$$v$$$ and there is no standing train at this position ($$$p \not\in [l; r]$$$). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to $$$t$$$ different conferences, so you should answer $$$t$$$ independent queries. | Print $$$t$$$ lines. The $$$i$$$-th line should contain one integer — the answer for the $$$i$$$-th query. | C | 5194846a503c2087fcd299eaf3c20b2b | 803b106ca83b852ca45c744d949122ca | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1539354900 | ["4\n10 2 3 7\n100 51 51 51\n1234 1 100 199\n1000000000 1 1 1000000000"] | NoteFor the first example query, the answer is $$$3$$$. There are lanterns at positions $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$ and $$$10$$$, but Vova didn't see the lanterns at positions $$$4$$$ and $$$6$$$ because of the standing train.For the second example query, the answer is $$$0$$$ because the only lantern is at the point $$$51$$$ and there is also a standing train at this point.For the third example query, the answer is $$$1134$$$ because there are $$$1234$$$ lanterns, but Vova didn't see the lanterns from the position $$$100$$$ to the position $$$199$$$ inclusive.For the fourth example query, the answer is $$$0$$$ because the standing train covers the whole path. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of queries. Then $$$t$$$ lines follow. The $$$i$$$-th line contains four integers $$$L_i, v_i, l_i, r_i$$$ ($$$1 \le L, v \le 10^9$$$, $$$1 \le l \le r \le L$$$) — destination point of the $$$i$$$-th path, the period of the lantern appearance and the segment occupied by the standing train. | ["3\n0\n1134\n0"] | #include<stdio.h>
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
long long int N,x,l,r,m=0,i,j;
scanf("%I64d%I64d%I64d%I64d",&N,&x,&l,&r);
i=(l-1)/x;
j=(N/x)-(r/x);
printf("%I64d\n",i+j);
}
return 0;
}
| |
Vova plans to go to the conference by train. Initially, the train is at the point $$$1$$$ and the destination point of the path is the point $$$L$$$. The speed of the train is $$$1$$$ length unit per minute (i.e. at the first minute the train is at the point $$$1$$$, at the second minute — at the point $$$2$$$ and so on).There are lanterns on the path. They are placed at the points with coordinates divisible by $$$v$$$ (i.e. the first lantern is at the point $$$v$$$, the second is at the point $$$2v$$$ and so on).There is also exactly one standing train which occupies all the points from $$$l$$$ to $$$r$$$ inclusive.Vova can see the lantern at the point $$$p$$$ if $$$p$$$ is divisible by $$$v$$$ and there is no standing train at this position ($$$p \not\in [l; r]$$$). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to $$$t$$$ different conferences, so you should answer $$$t$$$ independent queries. | Print $$$t$$$ lines. The $$$i$$$-th line should contain one integer — the answer for the $$$i$$$-th query. | C | 5194846a503c2087fcd299eaf3c20b2b | 6736608e80dd3a2ac58ecd544c0c9917 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1539354900 | ["4\n10 2 3 7\n100 51 51 51\n1234 1 100 199\n1000000000 1 1 1000000000"] | NoteFor the first example query, the answer is $$$3$$$. There are lanterns at positions $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$ and $$$10$$$, but Vova didn't see the lanterns at positions $$$4$$$ and $$$6$$$ because of the standing train.For the second example query, the answer is $$$0$$$ because the only lantern is at the point $$$51$$$ and there is also a standing train at this point.For the third example query, the answer is $$$1134$$$ because there are $$$1234$$$ lanterns, but Vova didn't see the lanterns from the position $$$100$$$ to the position $$$199$$$ inclusive.For the fourth example query, the answer is $$$0$$$ because the standing train covers the whole path. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of queries. Then $$$t$$$ lines follow. The $$$i$$$-th line contains four integers $$$L_i, v_i, l_i, r_i$$$ ($$$1 \le L, v \le 10^9$$$, $$$1 \le l \le r \le L$$$) — destination point of the $$$i$$$-th path, the period of the lantern appearance and the segment occupied by the standing train. | ["3\n0\n1134\n0"] | #include<stdio.h>
int main (){
int t,l,v,a,b,i=0,m;
scanf("%d",&t);
while(i<t){
scanf("%d %d %d %d",&l,&v,&a,&b);
m=(l/v)-((b/v)-(a/v));
if(a%v==0){
m=m-1;}
i++;
printf("%d\n",m);
}
return 0;
}
| |
Vova plans to go to the conference by train. Initially, the train is at the point $$$1$$$ and the destination point of the path is the point $$$L$$$. The speed of the train is $$$1$$$ length unit per minute (i.e. at the first minute the train is at the point $$$1$$$, at the second minute — at the point $$$2$$$ and so on).There are lanterns on the path. They are placed at the points with coordinates divisible by $$$v$$$ (i.e. the first lantern is at the point $$$v$$$, the second is at the point $$$2v$$$ and so on).There is also exactly one standing train which occupies all the points from $$$l$$$ to $$$r$$$ inclusive.Vova can see the lantern at the point $$$p$$$ if $$$p$$$ is divisible by $$$v$$$ and there is no standing train at this position ($$$p \not\in [l; r]$$$). Thus, if the point with the lantern is one of the points covered by the standing train, Vova can't see this lantern.Your problem is to say the number of lanterns Vova will see during the path. Vova plans to go to $$$t$$$ different conferences, so you should answer $$$t$$$ independent queries. | Print $$$t$$$ lines. The $$$i$$$-th line should contain one integer — the answer for the $$$i$$$-th query. | C | 5194846a503c2087fcd299eaf3c20b2b | 1bdd515253afe3ae321cd17640ddb007 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1539354900 | ["4\n10 2 3 7\n100 51 51 51\n1234 1 100 199\n1000000000 1 1 1000000000"] | NoteFor the first example query, the answer is $$$3$$$. There are lanterns at positions $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$ and $$$10$$$, but Vova didn't see the lanterns at positions $$$4$$$ and $$$6$$$ because of the standing train.For the second example query, the answer is $$$0$$$ because the only lantern is at the point $$$51$$$ and there is also a standing train at this point.For the third example query, the answer is $$$1134$$$ because there are $$$1234$$$ lanterns, but Vova didn't see the lanterns from the position $$$100$$$ to the position $$$199$$$ inclusive.For the fourth example query, the answer is $$$0$$$ because the standing train covers the whole path. | PASSED | 1,100 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of queries. Then $$$t$$$ lines follow. The $$$i$$$-th line contains four integers $$$L_i, v_i, l_i, r_i$$$ ($$$1 \le L, v \le 10^9$$$, $$$1 \le l \le r \le L$$$) — destination point of the $$$i$$$-th path, the period of the lantern appearance and the segment occupied by the standing train. | ["3\n0\n1134\n0"] | #include <stdio.h>
int main(int argc, char **argv)
{
long long t,l,v,a,b,x,k;
scanf("%lld",&t);
for(int i=0;i<t;i++)
{
scanf("%lld %lld %lld %lld",&l,&v,&a,&b);
k=l/v;
x=b/v-a/v;
if(a%v==0)
printf("%lld \n",k-x-1);
else
printf("%lld \n",k-x);
}
return 0;
} | |
Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees.A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (u, v) that belongs to the graph, u and v belong to different sets. You can find more formal definitions of a tree and a bipartite graph in the notes section below.Dr. Evil gave Mahmoud and Ehab a tree consisting of n nodes and asked them to add edges to it in such a way, that the graph is still bipartite. Besides, after adding these edges the graph should be simple (doesn't contain loops or multiple edges). What is the maximum number of edges they can add?A loop is an edge, which connects a node with itself. Graph doesn't contain multiple edges when for each pair of nodes there is no more than one edge between them. A cycle and a loop aren't the same . | Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions. | C | 44b9adcc9d672221bda3a1cada81b3d0 | c626e9dd4302ea70f7261a8cbda8cd56 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar",
"trees",
"graphs"
] | 1505833500 | ["3\n1 2\n1 3", "5\n1 2\n2 3\n3 4\n4 5"] | NoteTree definition: https://en.wikipedia.org/wiki/Tree_(graph_theory)Bipartite graph definition: https://en.wikipedia.org/wiki/Bipartite_graphIn the first test case the only edge that can be added in such a way, that graph won't contain loops or multiple edges is (2, 3), but adding this edge will make the graph non-bipartite so the answer is 0.In the second test case Mahmoud and Ehab can add edges (1, 4) and (2, 5). | PASSED | 1,300 | standard input | 2 seconds | The first line of input contains an integer n — the number of nodes in the tree (1 ≤ n ≤ 105). The next n - 1 lines contain integers u and v (1 ≤ u, v ≤ n, u ≠ v) — the description of the edges of the tree. It's guaranteed that the given graph is a tree. | ["0", "2"] | #include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <limits.h>
typedef struct adj {
int vertex;
struct adj *next;
} adjList;
typedef struct {
adjList **vertices;
long long int count[2];
} graph;
graph *newGraph(size_t tam) {
graph *graph = malloc(sizeof(graph));
int i;
graph->vertices = malloc(sizeof(adjList *) * (tam + 1));
memset(graph->count, 0, 2 * sizeof(long long int));
for (i = 0; i <= tam; i++) {
graph->vertices[i] = NULL;
}
return graph;
}
adjList *newAdjList(int item) {
adjList *adjj = malloc(sizeof(adjList));
adjj->vertex = item;
adjj->next = NULL;
return adjj;
}
void addEdge(graph *graph, int vertex1, int vertex2) {
adjList *vertex = newAdjList(vertex2);
vertex->next = graph->vertices[vertex1];
graph->vertices[vertex1] = vertex;
vertex = newAdjList(vertex1);
vertex->next = graph->vertices[vertex2];
graph->vertices[vertex2] = vertex;
}
void dfs(graph *graph, int src, int parent, int color) {
graph->count[color]++;
adjList *adj = graph->vertices[src];
while (adj) {
if (adj->vertex != parent)
dfs(graph, adj->vertex, src, !color);
adj = adj->next;
}
}
int main() {
int n;
scanf("%d", &n);
graph *g = newGraph(n);
for (int i = 1; i < n; i++) {
int a, b;
scanf("%d%d", &a, &b);
addEdge(g, a, b);
}
dfs(g, 1, 0, 0);
printf("%I64d\n", g->count[0] * g->count[1] - n + 1);
return 0;
} | |
Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees.A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (u, v) that belongs to the graph, u and v belong to different sets. You can find more formal definitions of a tree and a bipartite graph in the notes section below.Dr. Evil gave Mahmoud and Ehab a tree consisting of n nodes and asked them to add edges to it in such a way, that the graph is still bipartite. Besides, after adding these edges the graph should be simple (doesn't contain loops or multiple edges). What is the maximum number of edges they can add?A loop is an edge, which connects a node with itself. Graph doesn't contain multiple edges when for each pair of nodes there is no more than one edge between them. A cycle and a loop aren't the same . | Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions. | C | 44b9adcc9d672221bda3a1cada81b3d0 | 783645d76d7effbda190d8184a2b658e | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar",
"trees",
"graphs"
] | 1505833500 | ["3\n1 2\n1 3", "5\n1 2\n2 3\n3 4\n4 5"] | NoteTree definition: https://en.wikipedia.org/wiki/Tree_(graph_theory)Bipartite graph definition: https://en.wikipedia.org/wiki/Bipartite_graphIn the first test case the only edge that can be added in such a way, that graph won't contain loops or multiple edges is (2, 3), but adding this edge will make the graph non-bipartite so the answer is 0.In the second test case Mahmoud and Ehab can add edges (1, 4) and (2, 5). | PASSED | 1,300 | standard input | 2 seconds | The first line of input contains an integer n — the number of nodes in the tree (1 ≤ n ≤ 105). The next n - 1 lines contain integers u and v (1 ≤ u, v ≤ n, u ≠ v) — the description of the edges of the tree. It's guaranteed that the given graph is a tree. | ["0", "2"] | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define maxn 100000
struct node
{
long d;
struct node *next;
}*point[maxn+10];
bool vis[maxn+10];
long count[2]={0};
void dfs(long d,long value)
{
struct node *p=point[d];
count[value]++;
vis[d]=false;
while (p)
{
if (vis[p->d])
dfs(p->d,value ^1);
p=p->next;
}
}
int main()
{
long n,i,x,y;
struct node *p;
scanf("%ld",&n);
for (i=1;i<n;i++)
{
scanf("%ld%ld",&x,&y);
p=(struct node *) malloc (sizeof(struct node));
p->d=x;
p->next=point[y];
point[y]=p;
p=(struct node *) malloc (sizeof(struct node));
p->d=y;
p->next=point[x];
point[x]=p;
}
for (i=1;i<=n;i++)
vis[i]=true;
dfs(1,0);
printf("%I64d",(__int64)count[0]*count[1]-n+1);
return 0;
}
| |
Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees.A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (u, v) that belongs to the graph, u and v belong to different sets. You can find more formal definitions of a tree and a bipartite graph in the notes section below.Dr. Evil gave Mahmoud and Ehab a tree consisting of n nodes and asked them to add edges to it in such a way, that the graph is still bipartite. Besides, after adding these edges the graph should be simple (doesn't contain loops or multiple edges). What is the maximum number of edges they can add?A loop is an edge, which connects a node with itself. Graph doesn't contain multiple edges when for each pair of nodes there is no more than one edge between them. A cycle and a loop aren't the same . | Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions. | C | 44b9adcc9d672221bda3a1cada81b3d0 | db634a72ae3a0c72e1e187b365c3c4ea | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar",
"trees",
"graphs"
] | 1505833500 | ["3\n1 2\n1 3", "5\n1 2\n2 3\n3 4\n4 5"] | NoteTree definition: https://en.wikipedia.org/wiki/Tree_(graph_theory)Bipartite graph definition: https://en.wikipedia.org/wiki/Bipartite_graphIn the first test case the only edge that can be added in such a way, that graph won't contain loops or multiple edges is (2, 3), but adding this edge will make the graph non-bipartite so the answer is 0.In the second test case Mahmoud and Ehab can add edges (1, 4) and (2, 5). | PASSED | 1,300 | standard input | 2 seconds | The first line of input contains an integer n — the number of nodes in the tree (1 ≤ n ≤ 105). The next n - 1 lines contain integers u and v (1 ≤ u, v ≤ n, u ≠ v) — the description of the edges of the tree. It's guaranteed that the given graph is a tree. | ["0", "2"] | //Date:16-09-17
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<float.h>
#include<math.h>
#include<inttypes.h>
#include<assert.h>
#include<ctype.h>
#include<limits.h>
#include<time.h>
#define ll long long
#define For(i,n) for(i=0;i<n;i++)
#define rep(i ,a ,b) for(i=(a);i<=(b);i++)
#define mset(a ,value) memset(a ,value ,sizeof(a))
#define s(a) scanf("%d" ,&a);
#define ls(a) scanf("%ld" ,&a)
#define reg(i) register int i
#define infinite INT_MAX
#define MAX 100001
#define queue_max 200001
#define NIL -1
#define and &&
const int mod = 1e9+7;
int min(int a,int b){ return (a<b?a:b); }
int max(int a,int b){ return (a>b?a:b); }
int visited[MAX] = {0};
typedef struct Node{
int i ;
struct Node *next;
}*list ,node;
list start[MAX] ={0} ,tail[MAX] ={0};
void addEdge(int u,int v){
list tmp = (list)malloc(sizeof(node));
tmp->i = v;
tmp->next = NULL;
if(tail[u]==NULL){
start[u] = tmp;
tail[u] = tmp;
}else{
tail[u]->next = tmp;
tail[u] = tmp;
}
}
int level[MAX];
int queue[queue_max];
int front =-1,rear=-1 ,first = 0 ,second = 0;
int n;
void enqueue(int x){
queue[++rear] = x;
}
int dequeue(){
return queue[++front];
}
bool queue_empty(){
return front==rear;
}
void isBipartite(int s){
int i;
list p ;
enqueue(s);
visited[s] = 1 ,level[s] = 0;
while(!queue_empty()){
int u =dequeue();
p = start[u];
while(p) {
if(!visited[p->i]){
enqueue(p->i);
level[p->i] = (level[u] + 1)%2;
visited[p->i] = 1;
}
p = p->next;
}
}
}
int main() {
int i;
s(n);
For(i ,n - 1){
int u ,v;
s(u); s(v);
addEdge(--u ,--v);
addEdge(v ,u);
}
isBipartite(0);
For(i ,n){ if(level[i] == 0) first++; else second++; }
printf("%I64d" ,1LL*first*second - (n-1));
return 0;
} | |
Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees.A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (u, v) that belongs to the graph, u and v belong to different sets. You can find more formal definitions of a tree and a bipartite graph in the notes section below.Dr. Evil gave Mahmoud and Ehab a tree consisting of n nodes and asked them to add edges to it in such a way, that the graph is still bipartite. Besides, after adding these edges the graph should be simple (doesn't contain loops or multiple edges). What is the maximum number of edges they can add?A loop is an edge, which connects a node with itself. Graph doesn't contain multiple edges when for each pair of nodes there is no more than one edge between them. A cycle and a loop aren't the same . | Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions. | C | 44b9adcc9d672221bda3a1cada81b3d0 | f2a2f50c4de9372b241d509e3416ed1f | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar",
"trees",
"graphs"
] | 1505833500 | ["3\n1 2\n1 3", "5\n1 2\n2 3\n3 4\n4 5"] | NoteTree definition: https://en.wikipedia.org/wiki/Tree_(graph_theory)Bipartite graph definition: https://en.wikipedia.org/wiki/Bipartite_graphIn the first test case the only edge that can be added in such a way, that graph won't contain loops or multiple edges is (2, 3), but adding this edge will make the graph non-bipartite so the answer is 0.In the second test case Mahmoud and Ehab can add edges (1, 4) and (2, 5). | PASSED | 1,300 | standard input | 2 seconds | The first line of input contains an integer n — the number of nodes in the tree (1 ≤ n ≤ 105). The next n - 1 lines contain integers u and v (1 ≤ u, v ≤ n, u ≠ v) — the description of the edges of the tree. It's guaranteed that the given graph is a tree. | ["0", "2"] | #include <stdio.h>
#include <string.h>
#include <malloc.h>
int* _mstack_data;
int* _mstack_next;
int* _mstack_heads;
int _mstack_free;
char* vis;
int* e_count;
int* set1;
int* set2;
int set1count;
int set2count;
void dfs(int u, char set)
{
if (set)
{
set1[set1count] = u;
set1count++;
}
else
{
set2[set2count] = u;
set2count++;
}
vis[u] = 1;
int i = _mstack_heads[u];
while (i != -1)
{
int v = _mstack_data[i];
if (!vis[v])
{
dfs(v, !set);
}
i = _mstack_next[i];
}
}
int main()
{
int n;
scanf("%d", &n);
_mstack_data = malloc(sizeof(int[2*(n-1)]));
_mstack_next = malloc(sizeof(int[2*(n-1)]));
_mstack_heads = malloc(sizeof(int[n]));
memset(_mstack_heads, -1, sizeof(int[n]));
vis = malloc(n);
memset(vis, 0, n);
e_count = malloc(sizeof(int[n]));
memset(e_count, 0, sizeof(int[n]));
set1 = malloc(sizeof(int[n]));
set2 = malloc(sizeof(int[n]));
for (int i = 1; i < n; i++)
{
int u, v;
scanf("%d%d", &u, &v); u--; v--;
e_count[u]++; e_count[v]++;
_mstack_data[_mstack_free] = u;
_mstack_next[_mstack_free] = _mstack_heads[v];
_mstack_heads[v] = _mstack_free;
_mstack_free++;
_mstack_data[_mstack_free] = v;
_mstack_next[_mstack_free] = _mstack_heads[u];
_mstack_heads[u] = _mstack_free;
_mstack_free++;
}
dfs(0, 1);
long long ans = 0;
for (int i = 0; i < set1count; i++)
{
ans += set2count - e_count[set1[i]];
}
for (int i = 0; i < set2count; i++)
{
ans += set1count - e_count[set2[i]];
}
printf("%I64d", ans / 2);
return 0;
} | |
Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees.A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (u, v) that belongs to the graph, u and v belong to different sets. You can find more formal definitions of a tree and a bipartite graph in the notes section below.Dr. Evil gave Mahmoud and Ehab a tree consisting of n nodes and asked them to add edges to it in such a way, that the graph is still bipartite. Besides, after adding these edges the graph should be simple (doesn't contain loops or multiple edges). What is the maximum number of edges they can add?A loop is an edge, which connects a node with itself. Graph doesn't contain multiple edges when for each pair of nodes there is no more than one edge between them. A cycle and a loop aren't the same . | Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions. | C | 44b9adcc9d672221bda3a1cada81b3d0 | c0cad56587b6f1705eea4cf2ef8af374 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar",
"trees",
"graphs"
] | 1505833500 | ["3\n1 2\n1 3", "5\n1 2\n2 3\n3 4\n4 5"] | NoteTree definition: https://en.wikipedia.org/wiki/Tree_(graph_theory)Bipartite graph definition: https://en.wikipedia.org/wiki/Bipartite_graphIn the first test case the only edge that can be added in such a way, that graph won't contain loops or multiple edges is (2, 3), but adding this edge will make the graph non-bipartite so the answer is 0.In the second test case Mahmoud and Ehab can add edges (1, 4) and (2, 5). | PASSED | 1,300 | standard input | 2 seconds | The first line of input contains an integer n — the number of nodes in the tree (1 ≤ n ≤ 105). The next n - 1 lines contain integers u and v (1 ≤ u, v ≤ n, u ≠ v) — the description of the edges of the tree. It's guaranteed that the given graph is a tree. | ["0", "2"] |
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
int ret=0,c1=0;
int vis[100009]={0};
int col[100009]={0};
int a[100009],b[100009],count[100009]={0},deg[100009]={0};
int *g[100009];
void dfs(int i)
{
ret++;
int j,x;
vis[i]=1;
//printf("%d ",i);
for(j=0;j<deg[i];j++)
{
x=g[i][j];
if(vis[x]==0)
{
if(col[i]==1)
col[x]=2;
else if(col[i]==2)
{
col[x]=1;
c1++;
}
dfs(x);
}
}
return;
}
int main()
{
int n,m,u,v,i,j,k,cc=0;
scanf("%d",&n);
for(i=0;i<n-1;i++)
{
scanf("%d%d",&a[i],&b[i]);
deg[a[i]]++;
deg[b[i]]++;
}
for(i=0;i<=n;i++)
{
g[i]=(int*)malloc(4*deg[i]);
//for(j=0;j<deg[i];j++)
}
for(i=0;i<n-1;i++)
{
u=a[i];
v=b[i];
g[u][count[u]++]=v;
g[v][count[v]++]=u;
}
long long int ans=0;
//adjacency list created
for(i=1; i<=n; i++)
{
if(!vis[i])
{
col[i]=1;
c1++;
dfs(i);
}
}
ans=(long long int)c1*(long long int)(n-c1);
printf("%lld",ans-n+1);
return 0;
}
| |
Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees.A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (u, v) that belongs to the graph, u and v belong to different sets. You can find more formal definitions of a tree and a bipartite graph in the notes section below.Dr. Evil gave Mahmoud and Ehab a tree consisting of n nodes and asked them to add edges to it in such a way, that the graph is still bipartite. Besides, after adding these edges the graph should be simple (doesn't contain loops or multiple edges). What is the maximum number of edges they can add?A loop is an edge, which connects a node with itself. Graph doesn't contain multiple edges when for each pair of nodes there is no more than one edge between them. A cycle and a loop aren't the same . | Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions. | C | 44b9adcc9d672221bda3a1cada81b3d0 | c44ab4d0261a449427d8ceea27541cde | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar",
"trees",
"graphs"
] | 1505833500 | ["3\n1 2\n1 3", "5\n1 2\n2 3\n3 4\n4 5"] | NoteTree definition: https://en.wikipedia.org/wiki/Tree_(graph_theory)Bipartite graph definition: https://en.wikipedia.org/wiki/Bipartite_graphIn the first test case the only edge that can be added in such a way, that graph won't contain loops or multiple edges is (2, 3), but adding this edge will make the graph non-bipartite so the answer is 0.In the second test case Mahmoud and Ehab can add edges (1, 4) and (2, 5). | PASSED | 1,300 | standard input | 2 seconds | The first line of input contains an integer n — the number of nodes in the tree (1 ≤ n ≤ 105). The next n - 1 lines contain integers u and v (1 ≤ u, v ≤ n, u ≠ v) — the description of the edges of the tree. It's guaranteed that the given graph is a tree. | ["0", "2"] | #include <stdio.h>
#include <stdlib.h>
typedef struct Node {
struct Node* next;
long long int val;
}node;
node* v[500001];
long long int N, M, i, is[100001], q[100001],a11=0,b11=0, yes = 1;
int main() {
scanf("%lld", &N);
M=N-1;
for(i=1; i<=N; ++i) v[i] = NULL;
for(i=1; i<=M; ++i){
long long int x, y; scanf("%lld%lld", &x, &y);
node* xx = (node*) malloc(sizeof(node));
node* yy = (node*) malloc(sizeof(node));
xx->val = y; yy->val = x;
xx->next = v[x]; yy->next = v[y];
v[x] = xx; v[y] = yy;
}
for(i=1; i<=N; ++i) is[i] = -1;
for(i=1; i<=N; ++i){
if(yes == 0) break;
if(is[i] == -1){
long long int high = 1, low = 1;
is[i] = 0;
q[high++] = i;
while(low < high){
long long int cur = q[low];
node* it = v[cur];
while(it){
long long int next = it->val;
if(is[next] == -1){
is[next] = is[cur] ^ 1;
q[high++] = next;
}
else if(is[next] == is[cur]){
yes = 0;
break;
}
it = it->next;
}
++low;
}
}
}
for(i=1;i<=N;i++)
{
if(is[i]==1)
a11++;
else
b11++;
}
if(yes==1)
printf("%lld\n",((a11*b11)-(N-1)));
else
printf("0\n");
} | |
Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees.A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (u, v) that belongs to the graph, u and v belong to different sets. You can find more formal definitions of a tree and a bipartite graph in the notes section below.Dr. Evil gave Mahmoud and Ehab a tree consisting of n nodes and asked them to add edges to it in such a way, that the graph is still bipartite. Besides, after adding these edges the graph should be simple (doesn't contain loops or multiple edges). What is the maximum number of edges they can add?A loop is an edge, which connects a node with itself. Graph doesn't contain multiple edges when for each pair of nodes there is no more than one edge between them. A cycle and a loop aren't the same . | Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions. | C | 44b9adcc9d672221bda3a1cada81b3d0 | bab77e6b16f33803ca197ed392b52d0f | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar",
"trees",
"graphs"
] | 1505833500 | ["3\n1 2\n1 3", "5\n1 2\n2 3\n3 4\n4 5"] | NoteTree definition: https://en.wikipedia.org/wiki/Tree_(graph_theory)Bipartite graph definition: https://en.wikipedia.org/wiki/Bipartite_graphIn the first test case the only edge that can be added in such a way, that graph won't contain loops or multiple edges is (2, 3), but adding this edge will make the graph non-bipartite so the answer is 0.In the second test case Mahmoud and Ehab can add edges (1, 4) and (2, 5). | PASSED | 1,300 | standard input | 2 seconds | The first line of input contains an integer n — the number of nodes in the tree (1 ≤ n ≤ 105). The next n - 1 lines contain integers u and v (1 ≤ u, v ≤ n, u ≠ v) — the description of the edges of the tree. It's guaranteed that the given graph is a tree. | ["0", "2"] | #include <stdio.h>
#include <stdlib.h>
typedef struct node *node_t;
struct node{
long long int index;
node_t next;
};
struct vert{
long long int index;
long long int level;
node_t list;
};
node_t add(node_t list, long long int index){
node_t new = calloc(1, sizeof(struct node));
new->index = index;
new->next = list;
return new;
}
typedef struct q_node *qnode_t;
typedef struct queue *queue_t;
struct q_node{
long long int num;
qnode_t next;
};
struct queue{
qnode_t list;
qnode_t last;
};
queue_t create_queue(){
queue_t q = calloc(1, sizeof(struct queue));
q->list = NULL;
q->last = NULL;
return q;
}
queue_t dequeue(queue_t q){
qnode_t aux = q->list;
q->list = q->list->next;
free(aux);
return q;
}
queue_t enqueue(queue_t q, long long int elem){
qnode_t new = calloc(1, sizeof(struct q_node));
new->num = elem;
new->next = NULL;
if(q->last){
q->last->next = new;
}
else{
q->list = new;
}
q->last = new;
return q;
}
int main(){
long long int n, i, aux1, aux2, l1 = 1, pos;
node_t aux_node;
scanf("%lld", &n);
struct vert a[n];
for(i = 0; i < n; i++){
a[i].index = i;
a[i].list = NULL;
a[i].level = -1;
}
for(i = 0; i < n-1; i++){
scanf("%lld%lld", &aux1, &aux2); aux1--; aux2--;
a[aux1].list = add(a[aux1].list, aux2);
a[aux2].list = add(a[aux2].list, aux1);
}
queue_t q = create_queue();
a[0].level = 0;
q = enqueue(q, 0);
while(q->list){
pos = q->list->num;
aux_node = a[pos].list;
while(aux_node){
if(a[aux_node->index].level < 0){
a[aux_node->index].level = 1-a[pos].level;
q = enqueue(q, aux_node->index);
if(!a[aux_node->index].level){
l1++;
}
}
aux_node = aux_node->next;
}
q = dequeue(q);
}
printf("%lld\n", l1 * (n-l1)-n+1);
}
| |
Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities.To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only k storages, located in different cities numbered a1, a2, ..., ak.Unforunately the law of the country Masha lives in prohibits opening bakery in any of the cities which has storage located in it. She can open it only in one of another n - k cities, and, of course, flour delivery should be paid — for every kilometer of path between storage and bakery Masha should pay 1 ruble.Formally, Masha will pay x roubles, if she will open the bakery in some city b (ai ≠ b for every 1 ≤ i ≤ k) and choose a storage in some city s (s = aj for some 1 ≤ j ≤ k) and b and s are connected by some path of roads of summary length x (if there are more than one path, Masha is able to choose which of them should be used).Masha is very thrifty and rational. She is interested in a city, where she can open her bakery (and choose one of k storages and one of the paths between city with bakery and city with storage) and pay minimum possible amount of rubles for flour delivery. Please help Masha find this amount. | Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line. If the bakery can not be opened (while satisfying conditions) in any of the n cities, print - 1 in the only line. | C | b0e6a9b500b3b75219309b5e6295e105 | b7905c63f09bc6185220fea1f960ff58 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"graphs"
] | 1471698300 | ["5 4 2\n1 2 5\n1 2 3\n2 3 4\n1 4 10\n1 5", "3 1 1\n1 2 3\n3"] | NoteImage illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened. | PASSED | 1,300 | standard input | 2 seconds | The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 105, 0 ≤ k ≤ n) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively. Then m lines follow. Each of them contains three integers u, v and l (1 ≤ u, v ≤ n, 1 ≤ l ≤ 109, u ≠ v) meaning that there is a road between cities u and v of length of l kilometers . If k > 0, then the last line of the input contains k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n) — the number of cities having flour storage located in. If k = 0 then this line is not presented in the input. | ["3", "-1"] | #include<stdlib.h>
int a[100000][3],b[100000];
int main()
{
int n,m,k,i,t,min=1000000001;
scanf("%d %d %d",&n,&m,&k);
for(i=0;i<m;i++) scanf("%d %d %d",&a[i][0],&a[i][1],&a[i][2]);
for(i=0;i<k;i++)
{
scanf("%d",&t);
b[t]=1;
}
for(i=0;i<m;i++) if(b[a[i][0]]+b[a[i][1]]==1&&a[i][2]<min) min=a[i][2];
if(min==1000000001) min=-1;
printf("%d",min);
}
| |
Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities.To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only k storages, located in different cities numbered a1, a2, ..., ak.Unforunately the law of the country Masha lives in prohibits opening bakery in any of the cities which has storage located in it. She can open it only in one of another n - k cities, and, of course, flour delivery should be paid — for every kilometer of path between storage and bakery Masha should pay 1 ruble.Formally, Masha will pay x roubles, if she will open the bakery in some city b (ai ≠ b for every 1 ≤ i ≤ k) and choose a storage in some city s (s = aj for some 1 ≤ j ≤ k) and b and s are connected by some path of roads of summary length x (if there are more than one path, Masha is able to choose which of them should be used).Masha is very thrifty and rational. She is interested in a city, where she can open her bakery (and choose one of k storages and one of the paths between city with bakery and city with storage) and pay minimum possible amount of rubles for flour delivery. Please help Masha find this amount. | Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line. If the bakery can not be opened (while satisfying conditions) in any of the n cities, print - 1 in the only line. | C | b0e6a9b500b3b75219309b5e6295e105 | 5e4c6888c1f04225affdef8d7d77f617 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"graphs"
] | 1471698300 | ["5 4 2\n1 2 5\n1 2 3\n2 3 4\n1 4 10\n1 5", "3 1 1\n1 2 3\n3"] | NoteImage illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened. | PASSED | 1,300 | standard input | 2 seconds | The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 105, 0 ≤ k ≤ n) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively. Then m lines follow. Each of them contains three integers u, v and l (1 ≤ u, v ≤ n, 1 ≤ l ≤ 109, u ≠ v) meaning that there is a road between cities u and v of length of l kilometers . If k > 0, then the last line of the input contains k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n) — the number of cities having flour storage located in. If k = 0 then this line is not presented in the input. | ["3", "-1"] | int n,m,k,a=2e9,s[543210],i,j,J;main(){n||scanf("%d%d%d",&n,&m,&k);i-3*m-k?scanf("%d",s+i++):j-k?s[s[j+++3*m]+3*m+k]=1:(a<s[3*J+2]||s[s[3*J+1]+3*m+k]==s[s[3*J]+3*m+k]||(a=s[3*J+2]),J++);J-m&&main();exit(!printf("%d",a>1e9?-1:a));} | |
Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities.To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only k storages, located in different cities numbered a1, a2, ..., ak.Unforunately the law of the country Masha lives in prohibits opening bakery in any of the cities which has storage located in it. She can open it only in one of another n - k cities, and, of course, flour delivery should be paid — for every kilometer of path between storage and bakery Masha should pay 1 ruble.Formally, Masha will pay x roubles, if she will open the bakery in some city b (ai ≠ b for every 1 ≤ i ≤ k) and choose a storage in some city s (s = aj for some 1 ≤ j ≤ k) and b and s are connected by some path of roads of summary length x (if there are more than one path, Masha is able to choose which of them should be used).Masha is very thrifty and rational. She is interested in a city, where she can open her bakery (and choose one of k storages and one of the paths between city with bakery and city with storage) and pay minimum possible amount of rubles for flour delivery. Please help Masha find this amount. | Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line. If the bakery can not be opened (while satisfying conditions) in any of the n cities, print - 1 in the only line. | C | b0e6a9b500b3b75219309b5e6295e105 | f39664c5eb6c227dd02ccb6799bba074 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"graphs"
] | 1471698300 | ["5 4 2\n1 2 5\n1 2 3\n2 3 4\n1 4 10\n1 5", "3 1 1\n1 2 3\n3"] | NoteImage illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened. | PASSED | 1,300 | standard input | 2 seconds | The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 105, 0 ≤ k ≤ n) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively. Then m lines follow. Each of them contains three integers u, v and l (1 ≤ u, v ≤ n, 1 ≤ l ≤ 109, u ≠ v) meaning that there is a road between cities u and v of length of l kilometers . If k > 0, then the last line of the input contains k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n) — the number of cities having flour storage located in. If k = 0 then this line is not presented in the input. | ["3", "-1"] | int n,m,k,a=2e9,s[1<<20],i,j,J;main(){n||scanf("%d%d%d",&n,&m,&k);i-3*m-k?scanf("%d",s+i++):j-k?s[s[j+++3*m]+3*m+k]=1:(a<s[J+2]||s[s[J+1]+3*m+k]==s[s[J]+3*m+k]||(a=s[J+2]),J+=3);J-3*m?main():printf("%d",a>1e9?-1:a);} | |
Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities.To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only k storages, located in different cities numbered a1, a2, ..., ak.Unforunately the law of the country Masha lives in prohibits opening bakery in any of the cities which has storage located in it. She can open it only in one of another n - k cities, and, of course, flour delivery should be paid — for every kilometer of path between storage and bakery Masha should pay 1 ruble.Formally, Masha will pay x roubles, if she will open the bakery in some city b (ai ≠ b for every 1 ≤ i ≤ k) and choose a storage in some city s (s = aj for some 1 ≤ j ≤ k) and b and s are connected by some path of roads of summary length x (if there are more than one path, Masha is able to choose which of them should be used).Masha is very thrifty and rational. She is interested in a city, where she can open her bakery (and choose one of k storages and one of the paths between city with bakery and city with storage) and pay minimum possible amount of rubles for flour delivery. Please help Masha find this amount. | Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line. If the bakery can not be opened (while satisfying conditions) in any of the n cities, print - 1 in the only line. | C | b0e6a9b500b3b75219309b5e6295e105 | 10c39a4e7e89a4323201b154782412de | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"graphs"
] | 1471698300 | ["5 4 2\n1 2 5\n1 2 3\n2 3 4\n1 4 10\n1 5", "3 1 1\n1 2 3\n3"] | NoteImage illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened. | PASSED | 1,300 | standard input | 2 seconds | The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 105, 0 ≤ k ≤ n) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively. Then m lines follow. Each of them contains three integers u, v and l (1 ≤ u, v ≤ n, 1 ≤ l ≤ 109, u ≠ v) meaning that there is a road between cities u and v of length of l kilometers . If k > 0, then the last line of the input contains k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n) — the number of cities having flour storage located in. If k = 0 then this line is not presented in the input. | ["3", "-1"] | int n,m,k,a=2e9,s[1<<20],i,j,J;main(){n||scanf("%d%d%d",&n,&m,&k);i-3*m-k?scanf("%d",s+i++):j-k?s[s[j+++3*m]+3*m+k]=1:(a<s[J+2]||s[s[J+1]+3*m+k]==s[s[J]+3*m+k]||(a=s[J+2]),J+=3);J-3*m&&main();exit(!printf("%d",a>1e9?-1:a));} | |
Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities.To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only k storages, located in different cities numbered a1, a2, ..., ak.Unforunately the law of the country Masha lives in prohibits opening bakery in any of the cities which has storage located in it. She can open it only in one of another n - k cities, and, of course, flour delivery should be paid — for every kilometer of path between storage and bakery Masha should pay 1 ruble.Formally, Masha will pay x roubles, if she will open the bakery in some city b (ai ≠ b for every 1 ≤ i ≤ k) and choose a storage in some city s (s = aj for some 1 ≤ j ≤ k) and b and s are connected by some path of roads of summary length x (if there are more than one path, Masha is able to choose which of them should be used).Masha is very thrifty and rational. She is interested in a city, where she can open her bakery (and choose one of k storages and one of the paths between city with bakery and city with storage) and pay minimum possible amount of rubles for flour delivery. Please help Masha find this amount. | Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line. If the bakery can not be opened (while satisfying conditions) in any of the n cities, print - 1 in the only line. | C | b0e6a9b500b3b75219309b5e6295e105 | bb29f0f9e91302d43249d06736057e9c | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"graphs"
] | 1471698300 | ["5 4 2\n1 2 5\n1 2 3\n2 3 4\n1 4 10\n1 5", "3 1 1\n1 2 3\n3"] | NoteImage illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened. | PASSED | 1,300 | standard input | 2 seconds | The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 105, 0 ≤ k ≤ n) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively. Then m lines follow. Each of them contains three integers u, v and l (1 ≤ u, v ≤ n, 1 ≤ l ≤ 109, u ≠ v) meaning that there is a road between cities u and v of length of l kilometers . If k > 0, then the last line of the input contains k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n) — the number of cities having flour storage located in. If k = 0 then this line is not presented in the input. | ["3", "-1"] | #include <stdio.h>
char isStorageCity[100001];
int road[100000][2];
long roadLength[100000];
int main(void) {
int n,m,k;
scanf("%d %d %d",&n,&m,&k);
for (int i=0; i<m; i++) {
int u,v;
long l;
scanf("%d %d %ld",&u,&v,&l);
road[i][0]=u;
road[i][1]=v;
roadLength[i]=l;
}
if (k>0) {
for (int i=1; i<=n; i++)
isStorageCity[i]=0;
for (int i=0; i<k; i++) {
int ak;
scanf("%d",&ak);
isStorageCity[ak]=1;
}
}
long minPay=-1;
for (int i=0; i<m; i++) {
long aCityOfThisRoad=road[i][0],anotherCityOfThisRoad=road[i][1];
if ((isStorageCity[aCityOfThisRoad] && !isStorageCity[anotherCityOfThisRoad]) || (!isStorageCity[aCityOfThisRoad] && isStorageCity[anotherCityOfThisRoad])) {
long lengthOfThisRoad=roadLength[i];
if (minPay==-1) {
minPay=lengthOfThisRoad;
} else if (lengthOfThisRoad < minPay) {
minPay=lengthOfThisRoad;
}
}
}
printf("%ld",minPay);
return 0;
}
| |
Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities.To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only k storages, located in different cities numbered a1, a2, ..., ak.Unforunately the law of the country Masha lives in prohibits opening bakery in any of the cities which has storage located in it. She can open it only in one of another n - k cities, and, of course, flour delivery should be paid — for every kilometer of path between storage and bakery Masha should pay 1 ruble.Formally, Masha will pay x roubles, if she will open the bakery in some city b (ai ≠ b for every 1 ≤ i ≤ k) and choose a storage in some city s (s = aj for some 1 ≤ j ≤ k) and b and s are connected by some path of roads of summary length x (if there are more than one path, Masha is able to choose which of them should be used).Masha is very thrifty and rational. She is interested in a city, where she can open her bakery (and choose one of k storages and one of the paths between city with bakery and city with storage) and pay minimum possible amount of rubles for flour delivery. Please help Masha find this amount. | Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line. If the bakery can not be opened (while satisfying conditions) in any of the n cities, print - 1 in the only line. | C | b0e6a9b500b3b75219309b5e6295e105 | 7fb416fca41a66160ca8577971f8364c | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"graphs"
] | 1471698300 | ["5 4 2\n1 2 5\n1 2 3\n2 3 4\n1 4 10\n1 5", "3 1 1\n1 2 3\n3"] | NoteImage illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened. | PASSED | 1,300 | standard input | 2 seconds | The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 105, 0 ≤ k ≤ n) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively. Then m lines follow. Each of them contains three integers u, v and l (1 ≤ u, v ≤ n, 1 ≤ l ≤ 109, u ≠ v) meaning that there is a road between cities u and v of length of l kilometers . If k > 0, then the last line of the input contains k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n) — the number of cities having flour storage located in. If k = 0 then this line is not presented in the input. | ["3", "-1"] | /* Coached by rainboy */
#include <stdio.h>
#define N 100000
#define M 100000
#define INF 0x3f3f3f3f
int main() {
static int uu[M], vv[M], ll[M], flour[N];
int n, m, k, i, min;
scanf("%d%d%d", &n, &m, &k);
for (i = 0; i < m; i++)
scanf("%d%d%d", &uu[i], &vv[i], &ll[i]), uu[i]--, vv[i]--;
while (k--) {
int a;
scanf("%d", &a), a--;
flour[a] = 1;
}
min = INF;
for (i = 0; i < m; i++)
if (flour[uu[i]] != flour[vv[i]] && min > ll[i])
min = ll[i];
printf("%d\n", min == INF ? -1 : min);
return 0;
}
| |
Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities.To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only k storages, located in different cities numbered a1, a2, ..., ak.Unforunately the law of the country Masha lives in prohibits opening bakery in any of the cities which has storage located in it. She can open it only in one of another n - k cities, and, of course, flour delivery should be paid — for every kilometer of path between storage and bakery Masha should pay 1 ruble.Formally, Masha will pay x roubles, if she will open the bakery in some city b (ai ≠ b for every 1 ≤ i ≤ k) and choose a storage in some city s (s = aj for some 1 ≤ j ≤ k) and b and s are connected by some path of roads of summary length x (if there are more than one path, Masha is able to choose which of them should be used).Masha is very thrifty and rational. She is interested in a city, where she can open her bakery (and choose one of k storages and one of the paths between city with bakery and city with storage) and pay minimum possible amount of rubles for flour delivery. Please help Masha find this amount. | Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line. If the bakery can not be opened (while satisfying conditions) in any of the n cities, print - 1 in the only line. | C | b0e6a9b500b3b75219309b5e6295e105 | c1d07dcfd5d4f9a201c0f7b55108379c | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"graphs"
] | 1471698300 | ["5 4 2\n1 2 5\n1 2 3\n2 3 4\n1 4 10\n1 5", "3 1 1\n1 2 3\n3"] | NoteImage illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened. | PASSED | 1,300 | standard input | 2 seconds | The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 105, 0 ≤ k ≤ n) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively. Then m lines follow. Each of them contains three integers u, v and l (1 ≤ u, v ≤ n, 1 ≤ l ≤ 109, u ≠ v) meaning that there is a road between cities u and v of length of l kilometers . If k > 0, then the last line of the input contains k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n) — the number of cities having flour storage located in. If k = 0 then this line is not presented in the input. | ["3", "-1"] | #include <stdio.h>
struct ut{
int be;
int ki;
int hossz;
};
int main(){
int n, m, k;
scanf("%d %d %d", &n, &m, &k);
struct ut utak[m];
for(int i = 0; i < m; i++) scanf("%d %d %d", &(utak[i].be), &(utak[i].ki), &(utak[i].hossz));
int raktar[n+1];
for(int i = 0; i <= n; i++) raktar[i] = 0;
for(int i = 0; i < k; i++){
int a;
scanf("%d", &a);
raktar[a] = 1;
}
int min = -1;
for(int i = 0; i < m; i++){
if( ((raktar[utak[i].be] == 1) && (raktar[utak[i].ki] == 0)) || ((raktar[utak[i].be] == 0) && (raktar[utak[i].ki] == 1))){
if(min == -1) min = utak[i].hossz;
else if(min > utak[i].hossz) min = utak[i].hossz;
}
}
printf("%d", min);
}
| |
Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities.To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only k storages, located in different cities numbered a1, a2, ..., ak.Unforunately the law of the country Masha lives in prohibits opening bakery in any of the cities which has storage located in it. She can open it only in one of another n - k cities, and, of course, flour delivery should be paid — for every kilometer of path between storage and bakery Masha should pay 1 ruble.Formally, Masha will pay x roubles, if she will open the bakery in some city b (ai ≠ b for every 1 ≤ i ≤ k) and choose a storage in some city s (s = aj for some 1 ≤ j ≤ k) and b and s are connected by some path of roads of summary length x (if there are more than one path, Masha is able to choose which of them should be used).Masha is very thrifty and rational. She is interested in a city, where she can open her bakery (and choose one of k storages and one of the paths between city with bakery and city with storage) and pay minimum possible amount of rubles for flour delivery. Please help Masha find this amount. | Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line. If the bakery can not be opened (while satisfying conditions) in any of the n cities, print - 1 in the only line. | C | b0e6a9b500b3b75219309b5e6295e105 | 27b47fdfdfb58af13606b9f3e85d0b23 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"graphs"
] | 1471698300 | ["5 4 2\n1 2 5\n1 2 3\n2 3 4\n1 4 10\n1 5", "3 1 1\n1 2 3\n3"] | NoteImage illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened. | PASSED | 1,300 | standard input | 2 seconds | The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 105, 0 ≤ k ≤ n) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively. Then m lines follow. Each of them contains three integers u, v and l (1 ≤ u, v ≤ n, 1 ≤ l ≤ 109, u ≠ v) meaning that there is a road between cities u and v of length of l kilometers . If k > 0, then the last line of the input contains k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n) — the number of cities having flour storage located in. If k = 0 then this line is not presented in the input. | ["3", "-1"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct route {
unsigned a, b, c;
} route;
route neigh[100001];
unsigned baks[100001] = {0};
int main() {
unsigned n, m, k;
scanf("%u%u%u", &n, &m, &k);
for (unsigned i = 0; i < m; i++)
scanf("%u%u%u", &neigh[i].a, &neigh[i].b, &neigh[i].c);
for (unsigned i = 0; i < k; i++) {
unsigned a;
scanf("%u", &a);
baks[a] = 1;
}
unsigned min = -1;
for (unsigned i = 0; i < m; i++)
if (baks[neigh[i].a] != baks[neigh[i].b] && neigh[i].c < min)
min = neigh[i].c;
printf("%d\n", min);
}
| |
Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities.To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only k storages, located in different cities numbered a1, a2, ..., ak.Unforunately the law of the country Masha lives in prohibits opening bakery in any of the cities which has storage located in it. She can open it only in one of another n - k cities, and, of course, flour delivery should be paid — for every kilometer of path between storage and bakery Masha should pay 1 ruble.Formally, Masha will pay x roubles, if she will open the bakery in some city b (ai ≠ b for every 1 ≤ i ≤ k) and choose a storage in some city s (s = aj for some 1 ≤ j ≤ k) and b and s are connected by some path of roads of summary length x (if there are more than one path, Masha is able to choose which of them should be used).Masha is very thrifty and rational. She is interested in a city, where she can open her bakery (and choose one of k storages and one of the paths between city with bakery and city with storage) and pay minimum possible amount of rubles for flour delivery. Please help Masha find this amount. | Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line. If the bakery can not be opened (while satisfying conditions) in any of the n cities, print - 1 in the only line. | C | b0e6a9b500b3b75219309b5e6295e105 | 9ba072c068ea909717be3f7a9847d03d | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"graphs"
] | 1471698300 | ["5 4 2\n1 2 5\n1 2 3\n2 3 4\n1 4 10\n1 5", "3 1 1\n1 2 3\n3"] | NoteImage illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened. | PASSED | 1,300 | standard input | 2 seconds | The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 105, 0 ≤ k ≤ n) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively. Then m lines follow. Each of them contains three integers u, v and l (1 ≤ u, v ≤ n, 1 ≤ l ≤ 109, u ≠ v) meaning that there is a road between cities u and v of length of l kilometers . If k > 0, then the last line of the input contains k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n) — the number of cities having flour storage located in. If k = 0 then this line is not presented in the input. | ["3", "-1"] | m,i,j,y[1<<18],x[1<<18][3],r=1e10,a=1e10;
main(k){scanf("%d%d%d",&j,&m,&k);for(i=0;i<m;i++)scanf("%d%d%d",&x[i][0],&x[i][1],&x[i][2]);for(i=0;i<k;i++){scanf("%d",&j);y[j]=1;}for(i=0;i<m;i++)if(y[x[i][0]]^y[x[i][1]])r=r<x[i][2]?r:x[i][2];printf("%d",(r==a?-1:r));}
| |
Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities.To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only k storages, located in different cities numbered a1, a2, ..., ak.Unforunately the law of the country Masha lives in prohibits opening bakery in any of the cities which has storage located in it. She can open it only in one of another n - k cities, and, of course, flour delivery should be paid — for every kilometer of path between storage and bakery Masha should pay 1 ruble.Formally, Masha will pay x roubles, if she will open the bakery in some city b (ai ≠ b for every 1 ≤ i ≤ k) and choose a storage in some city s (s = aj for some 1 ≤ j ≤ k) and b and s are connected by some path of roads of summary length x (if there are more than one path, Masha is able to choose which of them should be used).Masha is very thrifty and rational. She is interested in a city, where she can open her bakery (and choose one of k storages and one of the paths between city with bakery and city with storage) and pay minimum possible amount of rubles for flour delivery. Please help Masha find this amount. | Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line. If the bakery can not be opened (while satisfying conditions) in any of the n cities, print - 1 in the only line. | C | b0e6a9b500b3b75219309b5e6295e105 | 6050a9a625b50a5aee23bca3ebb5852f | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"graphs"
] | 1471698300 | ["5 4 2\n1 2 5\n1 2 3\n2 3 4\n1 4 10\n1 5", "3 1 1\n1 2 3\n3"] | NoteImage illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened. | PASSED | 1,300 | standard input | 2 seconds | The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 105, 0 ≤ k ≤ n) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively. Then m lines follow. Each of them contains three integers u, v and l (1 ≤ u, v ≤ n, 1 ≤ l ≤ 109, u ≠ v) meaning that there is a road between cities u and v of length of l kilometers . If k > 0, then the last line of the input contains k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n) — the number of cities having flour storage located in. If k = 0 then this line is not presented in the input. | ["3", "-1"] | #include<stdio.h>
#include<math.h>
int b[1000000],c[1000000];
const int MAX = 1e5 + 1;
int main()
{
int n,m,k,i,j,l,flag=0,mini=1e9 + 2,check=0;
int bakery[MAX];
//printf("%d.", bakery[29]);
scanf("%d%d%d",&n,&m,&k);
int a[m+1][4];
for(i=0;i<m;i++){
for(j=0;j<3;j++){
scanf("%d",&a[i][j]);
}
}
if(k>0){
for(i=0;i<k;i++){
scanf("%d",&c[i]);
bakery[c[i]] = 1;
}
}
else{
printf("-1");
return 0;
}
for (i=0 ; i<m ; i++)
if ((bakery[a[i][0]]^bakery[a[i][1]] == 1) && a[i][2] < mini)
{
mini = a[i][2];
flag=1;
}
if(flag==1)
printf("%d",mini);
else
printf("-1");
return 0;
}
| |
Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities.To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only k storages, located in different cities numbered a1, a2, ..., ak.Unforunately the law of the country Masha lives in prohibits opening bakery in any of the cities which has storage located in it. She can open it only in one of another n - k cities, and, of course, flour delivery should be paid — for every kilometer of path between storage and bakery Masha should pay 1 ruble.Formally, Masha will pay x roubles, if she will open the bakery in some city b (ai ≠ b for every 1 ≤ i ≤ k) and choose a storage in some city s (s = aj for some 1 ≤ j ≤ k) and b and s are connected by some path of roads of summary length x (if there are more than one path, Masha is able to choose which of them should be used).Masha is very thrifty and rational. She is interested in a city, where she can open her bakery (and choose one of k storages and one of the paths between city with bakery and city with storage) and pay minimum possible amount of rubles for flour delivery. Please help Masha find this amount. | Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line. If the bakery can not be opened (while satisfying conditions) in any of the n cities, print - 1 in the only line. | C | b0e6a9b500b3b75219309b5e6295e105 | 9f32c18c359bd4a0f289b20b6ea5f23c | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"graphs"
] | 1471698300 | ["5 4 2\n1 2 5\n1 2 3\n2 3 4\n1 4 10\n1 5", "3 1 1\n1 2 3\n3"] | NoteImage illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened. | PASSED | 1,300 | standard input | 2 seconds | The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 105, 0 ≤ k ≤ n) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively. Then m lines follow. Each of them contains three integers u, v and l (1 ≤ u, v ≤ n, 1 ≤ l ≤ 109, u ≠ v) meaning that there is a road between cities u and v of length of l kilometers . If k > 0, then the last line of the input contains k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n) — the number of cities having flour storage located in. If k = 0 then this line is not presented in the input. | ["3", "-1"] | #include<stdio.h>
int main()
{
int n,m,k,i,a,j;
scanf("%d%d%d",&n,&m,&k);
int arr[100001][3];
int bal[100001]={0};
for(i=0;i<m;i++)
{
scanf("%d%d%d",&arr[i][0],&arr[i][1],&arr[i][2]);
}
int min=1000000009;
if(k>0)
{
for(i=0;i<k;i++)
{
scanf("%d",&a);
bal[a]=1;
}
}
for(i=0;i<m;i++)
{
if(bal[arr[i][0]]+bal[arr[i][1]]==1)
{
if(arr[i][2]<min)min=arr[i][2];
}
}
if(min==1000000009)printf("-1");
else
printf("%d",min);
}
| |
Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities.To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only k storages, located in different cities numbered a1, a2, ..., ak.Unforunately the law of the country Masha lives in prohibits opening bakery in any of the cities which has storage located in it. She can open it only in one of another n - k cities, and, of course, flour delivery should be paid — for every kilometer of path between storage and bakery Masha should pay 1 ruble.Formally, Masha will pay x roubles, if she will open the bakery in some city b (ai ≠ b for every 1 ≤ i ≤ k) and choose a storage in some city s (s = aj for some 1 ≤ j ≤ k) and b and s are connected by some path of roads of summary length x (if there are more than one path, Masha is able to choose which of them should be used).Masha is very thrifty and rational. She is interested in a city, where she can open her bakery (and choose one of k storages and one of the paths between city with bakery and city with storage) and pay minimum possible amount of rubles for flour delivery. Please help Masha find this amount. | Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line. If the bakery can not be opened (while satisfying conditions) in any of the n cities, print - 1 in the only line. | C | b0e6a9b500b3b75219309b5e6295e105 | f15480507e72953bbe96fb0eca4fb3fa | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"graphs"
] | 1471698300 | ["5 4 2\n1 2 5\n1 2 3\n2 3 4\n1 4 10\n1 5", "3 1 1\n1 2 3\n3"] | NoteImage illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened. | PASSED | 1,300 | standard input | 2 seconds | The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 105, 0 ≤ k ≤ n) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively. Then m lines follow. Each of them contains three integers u, v and l (1 ≤ u, v ≤ n, 1 ≤ l ≤ 109, u ≠ v) meaning that there is a road between cities u and v of length of l kilometers . If k > 0, then the last line of the input contains k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n) — the number of cities having flour storage located in. If k = 0 then this line is not presented in the input. | ["3", "-1"] | #include <stdio.h>
#define N 100000
int stg[N + 1];
struct info{
int u;
int v;
int l;
}edge[N + 1];
int main(){
int n, m, k, a, u, v, l, i;
scanf("%d%d%d", &n, &m, &k);
for(i = 0; i < m; i++){
scanf("%d%d%d", &edge[i].u, &edge[i].v, &edge[i].l);
}
for(i = 0; i < k; i++){
scanf("%d", &a);
stg[a] = 1;
}
int ans = -1;
for(i = 0; i < m; i++){
u = edge[i].u;
v = edge[i].v;
l = edge[i].l;
if( (stg[u] == 1 && stg[v] == 0) ||(stg[v] == 1 && stg[u] == 0) ){
if(ans == -1 || ans > l){
ans = l;
}
}
}
printf("%d\n", ans);
return 0;
} | |
Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities.To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only k storages, located in different cities numbered a1, a2, ..., ak.Unforunately the law of the country Masha lives in prohibits opening bakery in any of the cities which has storage located in it. She can open it only in one of another n - k cities, and, of course, flour delivery should be paid — for every kilometer of path between storage and bakery Masha should pay 1 ruble.Formally, Masha will pay x roubles, if she will open the bakery in some city b (ai ≠ b for every 1 ≤ i ≤ k) and choose a storage in some city s (s = aj for some 1 ≤ j ≤ k) and b and s are connected by some path of roads of summary length x (if there are more than one path, Masha is able to choose which of them should be used).Masha is very thrifty and rational. She is interested in a city, where she can open her bakery (and choose one of k storages and one of the paths between city with bakery and city with storage) and pay minimum possible amount of rubles for flour delivery. Please help Masha find this amount. | Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line. If the bakery can not be opened (while satisfying conditions) in any of the n cities, print - 1 in the only line. | C | b0e6a9b500b3b75219309b5e6295e105 | 7a268f73ce41f09e8684e247a4c15286 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"graphs"
] | 1471698300 | ["5 4 2\n1 2 5\n1 2 3\n2 3 4\n1 4 10\n1 5", "3 1 1\n1 2 3\n3"] | NoteImage illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened. | PASSED | 1,300 | standard input | 2 seconds | The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 105, 0 ≤ k ≤ n) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively. Then m lines follow. Each of them contains three integers u, v and l (1 ≤ u, v ≤ n, 1 ≤ l ≤ 109, u ≠ v) meaning that there is a road between cities u and v of length of l kilometers . If k > 0, then the last line of the input contains k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n) — the number of cities having flour storage located in. If k = 0 then this line is not presented in the input. | ["3", "-1"] | #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 100000
char stg[N + 1];
struct info{
int *a;
int cnt;
} edge[N + 1];
int traverse(int u, int v){
for(int i = 0; i < edge[u].cnt; i += 2){
if(edge[u].a[i] == v){
return i;
}
}
return -1;
}
void rlc(int u, int v, int c1, int c2){
edge[u].a = (int *) realloc(edge[u].a, c1 * sizeof(*edge[u].a));
edge[v].a = (int *) realloc(edge[v].a, c2 * sizeof(*edge[v].a));
}
void push(int u, int v, int l){
int ind = traverse(u, v);
int c1, c2;
if(ind == -1){
c1 = edge[u].cnt += 2;
c2 = edge[v].cnt += 2;
rlc(u, v, c1, c2);
edge[u].a[c1 - 2] = v;
edge[u].a[c1 - 1] = l;
edge[v].a[c2 - 2] = u;
edge[v].a[c2 - 1] = l;
}
else if(edge[u].a[ind + 1] > l){
edge[u].a[ind + 1] = l;
ind = traverse(v, u);
edge[v].a[ind + 1] = l;
}
}
int main() {
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
for(int i = 0; i < m; i++){
int u, v, l;
scanf("%d%d%d", &u, &v, &l);
push(u, v, l);
}
memset(stg, 0, sizeof(stg));
while(k--){
int a;
scanf("%d", &a);
stg[a] = 1;
}
int ans = -1;
for(int i = 1; i <= n; i++){
if(stg[i] == 1){
for(int j = 0; j < edge[i].cnt; j += 2){
int s, t;
s = edge[i].a[j];
t = edge[i].a[j + 1];
if(stg[s] == 0 && (ans == -1 || (ans > t))){
ans = t;
}
}
}
}
printf("%d\n", ans);
return 0;
} | |
You are given an array of positive integers. While there are at least two equal elements, we will perform the following operation. We choose the smallest value $$$x$$$ that occurs in the array $$$2$$$ or more times. Take the first two occurrences of $$$x$$$ in this array (the two leftmost occurrences). Remove the left of these two occurrences, and the right one is replaced by the sum of this two values (that is, $$$2 \cdot x$$$).Determine how the array will look after described operations are performed.For example, consider the given array looks like $$$[3, 4, 1, 2, 2, 1, 1]$$$. It will be changed in the following way: $$$[3, 4, 1, 2, 2, 1, 1]~\rightarrow~[3, 4, 2, 2, 2, 1]~\rightarrow~[3, 4, 4, 2, 1]~\rightarrow~[3, 8, 2, 1]$$$.If the given array is look like $$$[1, 1, 3, 1, 1]$$$ it will be changed in the following way: $$$[1, 1, 3, 1, 1]~\rightarrow~[2, 3, 1, 1]~\rightarrow~[2, 3, 2]~\rightarrow~[3, 4]$$$. | In the first line print an integer $$$k$$$ — the number of elements in the array after all the performed operations. In the second line print $$$k$$$ integers — the elements of the array after all the performed operations. | C | 297d68c8be0c3358548949f277b9c087 | 58a6342330acc68fe8b9401592db4734 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"implementation"
] | 1523370900 | ["7\n3 4 1 2 2 1 1", "5\n1 1 3 1 1", "5\n10 40 20 50 30"] | NoteThe first two examples were considered in the statement.In the third example all integers in the given array are distinct, so it will not change. | PASSED | 1,600 | standard input | 2 seconds | The first line contains a single integer $$$n$$$ ($$$2 \le n \le 150\,000$$$) — the number of elements in the array. The second line contains a sequence from $$$n$$$ elements $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^{9}$$$) — the elements of the array. | ["4\n3 8 2 1", "2\n3 4", "5\n10 40 20 50 30"] | #include <stdio.h>
#define N 150000
struct X {
int i; /* for heap */
long long a;
int i_;
} xx[N], *pq[1 + N];
int cnt;
#define LT(x, y) ((x)->a != (y)->a ? (x)->a < (y)->a : (x)->i_ < (y)->i_)
int i2(int i) {
return (i *= 2) > cnt ? 0 : i < cnt && LT(pq[i + 1], pq[i]) ? i + 1 : i;
}
void pq_up(struct X *x) {
int i, j;
for (i = x->i; (j = i / 2) && LT(x, pq[j]); i = j)
pq[pq[j]->i = i] = pq[j];
pq[x->i = i] = x;
}
void pq_dn(struct X *x) {
int i, j;
for (i = x->i; (j = i2(i)) && LT(pq[j], x); i = j)
pq[pq[j]->i = i] = pq[j];
pq[x->i = i] = x;
}
void pq_add(struct X *x) {
x->i = ++cnt;
pq_up(x);
}
struct X *pq_remove_first() {
struct X *x = pq[1], *y = pq[cnt--];
y->i = 1;
pq_dn(y);
return x;
}
int main() {
static char used[N];
int n, i, k;
scanf("%d", &n);
for (i = 0; i < n; i++) {
struct X *x = &xx[i];
scanf("%lld", &x->a);
x->i_ = i;
pq_add(x);
}
k = 0;
while (cnt) {
struct X *x = pq_remove_first();
if (cnt == 0 || x->a != pq[1]->a) {
used[x->i_] = 1;
k++;
} else {
struct X *y = pq_remove_first();
y->a = x->a * 2;
pq_add(y);
}
}
printf("%d\n", k);
for (i = 0; i < n; i++)
if (used[i])
printf("%lld ", xx[i].a);
printf("\n");
return 0;
}
| |
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | C | 74b90fe9458b147568ac9bd09f219aab | 022f92c83a9ad9656b4dc60d41598b5f | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1316098800 | ["4\n0 3\n2 5\n4 2\n4 0"] | NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | PASSED | 800 | standard input | 2 seconds | The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0. | ["6"] | #include<stdio.h>
int main()
{
int a[1000],b[1000],n,i,ans,max=0,k=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d%d",&a[i],&b[i]);
ans=b[i]-a[i]+k;
k=ans;
if(ans>max)
max=ans;
}
printf("%d\n",max);
return 0;
}
| |
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | C | 74b90fe9458b147568ac9bd09f219aab | 57394a718badcd6fbd7bae05f017df64 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1316098800 | ["4\n0 3\n2 5\n4 2\n4 0"] | NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | PASSED | 800 | standard input | 2 seconds | The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0. | ["6"] | #include<stdio.h>
int main()
{
int n,a[1000],b[1000],ans,i,k,maxx=0;
scanf("%d",&n);
for(i=0; i<n; i++)
{
scanf("%d%d",&a[i],&b[i]);
}
k=a[0];
for(i=0; i<n; i++)
{
ans=b[i]-a[i]+k;
k=ans;
if(ans>maxx)
maxx=ans;
}
printf("%d\n",maxx);
return 0;
} | |
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | C | 74b90fe9458b147568ac9bd09f219aab | 9205a00d57b250b26275c9ded9685768 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1316098800 | ["4\n0 3\n2 5\n4 2\n4 0"] | NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | PASSED | 800 | standard input | 2 seconds | The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0. | ["6"] | #include<stdio.h>
int main(){
int n, num1, num2, first = 0, last = 0;
scanf("%d", &n);
while(n--){
scanf("%d %d", &num1, &num2);
first -= num1;
first += num2;
if(first > last){
last = first;
}
}
printf("%d\n", last);
return 0;
} | |
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | C | 74b90fe9458b147568ac9bd09f219aab | b1ab29b4f791fa8a77b3b08dd886cefb | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1316098800 | ["4\n0 3\n2 5\n4 2\n4 0"] | NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | PASSED | 800 | standard input | 2 seconds | The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0. | ["6"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char const *argv[]) {
int n,i,j,tab[10000],mont[10000],desc[10000],a,bat[10000],x;
scanf("%d",&n );
for(i=0;i<n;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&tab[j] );
}
desc[i]=tab[0];
mont[i]=tab[1];
}
a=mont[0] ;
for(i=0;i<n-2;i++)
{
a=a+mont[i+1]-desc[i+1] ;
bat[i]=a;
}
for(j=0;j<n-2;j++)
{
for(i=0;i<n-2;i++)
{
if(bat[i]<bat[i+1])
{
a=bat[i];
bat[i]=bat[i+1];
bat[i+1]=a;
}
}
}
x=bat[0] ;
if(x<mont[0])
printf("%d",mont[0] );
else
printf("%d",x );
return 0;
}
| |
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | C | 74b90fe9458b147568ac9bd09f219aab | 5acbe89f0c56c16f48171bfabc030516 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1316098800 | ["4\n0 3\n2 5\n4 2\n4 0"] | NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | PASSED | 800 | standard input | 2 seconds | The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0. | ["6"] | #include <stdio.h>
int main(void)
{
int n;
int a,b;
int total=0,tt=0;
scanf("%d\n", &n);
for(int i=0; i<n ; i++)
{
scanf("%d %d", &a, &b);
//if((b-a)>0)
tt=tt-a+b;
if(total<tt)
total=tt;
//printf("%d\n",total);
}
printf("%d",total);
return 0;
} | |
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | C | 74b90fe9458b147568ac9bd09f219aab | 51920cc34531fd0c0971b496a4a8e1a5 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1316098800 | ["4\n0 3\n2 5\n4 2\n4 0"] | NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | PASSED | 800 | standard input | 2 seconds | The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0. | ["6"] | #include<stdio.h>
int main()
{
long long int i,j,n,x=0,sum=0,a[1000][2],b[1001];
scanf("%lld",&n);
for(i=0;i<n;i++)
{
for(j=0;j<2;j++)
{
scanf("%lld",&a[i][j]);
}
sum=sum-a[i][0]+a[i][1];
b[i]=sum;
if(b[i]>x)
x=b[i];
}
printf("%lld",x);
return 0;
}
| |
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | C | 74b90fe9458b147568ac9bd09f219aab | bfcd5988799ff37938b1bfab78f67d4a | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1316098800 | ["4\n0 3\n2 5\n4 2\n4 0"] | NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | PASSED | 800 | standard input | 2 seconds | The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0. | ["6"] | #include <stdio.h>
int main()
{
int n, a, b, c=0,m=0;
scanf("%d", &n);
while (n--)
{
scanf("%d%d", &a, &b);
c -= a;
c += b;
if (c > m)
{
m = c;
}
}
printf("%d\n", m);
return 0;
} | |
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | C | 74b90fe9458b147568ac9bd09f219aab | 905496ada627a5a7c145dc4863e655d2 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1316098800 | ["4\n0 3\n2 5\n4 2\n4 0"] | NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | PASSED | 800 | standard input | 2 seconds | The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0. | ["6"] | #include<stdio.h>
int main()
{
int a,b,c,d,i,j,k,n;
scanf("%d",&n);
c=0;d=0;j=0;
for(i=0;i<n;i++)
{
scanf("%d%d",&a,&b);
c=d+b-a;
if(c>j)
{
j=c;
}
d=c;
}
printf("%d",j);
return 0;
}
| |
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | C | 74b90fe9458b147568ac9bd09f219aab | a4c90c5f30a306751fe421dec773cb81 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1316098800 | ["4\n0 3\n2 5\n4 2\n4 0"] | NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | PASSED | 800 | standard input | 2 seconds | The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0. | ["6"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int *a, *b, i, n, *d, j, sum, max, fl = 0;
scanf("%d", &n);
a = (int *)malloc((n+1)*sizeof(int));
b = (int *)malloc((n+1)*sizeof(int));
d = (int *)malloc((n+1)*sizeof(int));
for (i=0; i < n+1; i++)
{
d[i] = 0;
}
for (i = 0; i < n; i++)
{
scanf("%d %d", &a[i], &b[i]);
d[i] = b[i] - a[i];
if (d[i] == 0 && fl ==0)
{
fl = 0;
}
else
{
fl = 1;
}
}
for (i = n-1; i >= 0; i--)
{
sum = 0;
for (j = 0; j < i; j++)
{
sum += d[j];
}
d[i] = sum;
}
max = d[0];
for (i = 0; i < n; i++)
{
if (d[i+1] > max)
{
max = d[i+1];
}
}
if (fl == 0)
max = 0;
printf("%d", max);
return 0;
} | |
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | C | 74b90fe9458b147568ac9bd09f219aab | a1b7d6152bf2a7e8a61c19d47f79e96e | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1316098800 | ["4\n0 3\n2 5\n4 2\n4 0"] | NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | PASSED | 800 | standard input | 2 seconds | The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0. | ["6"] | #include<stdio.h>
int main(){
int i,j,k;
int a[1000];
int b[1000];
int c[1000];
c[0]=0;
int n;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d%d",&a[i],&b[i]);
c[i+1]=c[i]+(b[i]-a[i]);}
for(i=0;i<n+1;i++){
k=0;
for(j=0;j<n+1;j++){
if(c[i]>=c[j])
k++;
}
if(k==n+1){
printf("%d",c[i]);
break;
}
}
return 0;
} | |
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | C | 74b90fe9458b147568ac9bd09f219aab | 28f7f14065955b2e741eb50dde3ae905 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1316098800 | ["4\n0 3\n2 5\n4 2\n4 0"] | NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | PASSED | 800 | standard input | 2 seconds | The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0. | ["6"] | #include<stdio.h>
int main()
{
int a[1000],b[1000],c=0,i,n,max=0;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d %d",&a[i],&b[i]);
}
for(i=1;i<=n;i++)
{
c=c-a[i];
c=c+b[i];
if(c>max)
max=c;
}
printf("%d",max);
return 0;
//😂😂😂😂🤣🤣🤣🤪🤪🤪🥴🥴🥴🧟♂
} | |
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | C | 74b90fe9458b147568ac9bd09f219aab | 8a0a87cdaab287adb9f3c938ac4545d5 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1316098800 | ["4\n0 3\n2 5\n4 2\n4 0"] | NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | PASSED | 800 | standard input | 2 seconds | The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0. | ["6"] | #include <stdio.h>
#include <math.h>
int main( int argc, char **argv )
{
int i;
int a;
int c;
int d;
int e=0;
int f=0;
scanf("%d", &a);
for (i=0;i<a;i++)
{
scanf("%d%d", &c, &d);
e=e-c+d;
if(e>f)
{
f=e;
}
}
printf("%d", f);
return 0;
}
/*
int b[a][2];
for (i=0;i<a;i++)
{
scanf("%d", &b[i][i-(i-1)]);
}
for (i=0;i<a;i++)
{
c==0-b[i][0]+b[i][1];
if(c>d)
{
d=c;
}
}
*/
| |
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | C | 74b90fe9458b147568ac9bd09f219aab | c325f15f9f73b188e18be00bc797fad4 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1316098800 | ["4\n0 3\n2 5\n4 2\n4 0"] | NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | PASSED | 800 | standard input | 2 seconds | The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0. | ["6"] | #include<stdio.h>
int main()
{
int n,i,ara[10000],ara2[10000];
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d %d",&ara[i],&ara2[i]);
}
int t=ara2[0];
int temp=ara2[0];
for(i=0;i<n;i++){
t=t-(ara[i+1]-ara2[i+1]);
if(t>temp)
temp=t;
} printf("%d",temp);
return 0;
}
| |
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | C | 74b90fe9458b147568ac9bd09f219aab | b356df0ce7d4656c850e261d30619745 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1316098800 | ["4\n0 3\n2 5\n4 2\n4 0"] | NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | PASSED | 800 | standard input | 2 seconds | The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0. | ["6"] | #include<stdio.h>
#include<math.h>
int main()
{
int arr[1000][2];
int nr[1000][2];
int i,j,p,n,sum,max,t;
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&arr[i][j]);
}
}
for(i=0;i<n-1;i++)
{
for(j=1; j<2; j++)
{
if(arr[i][1]==arr[i+1][0]&& arr[i+1][1]==0)
{
nr[i][1]=arr[i+1][0];
continue;
}
else if(arr[i][1]==arr[i+1][0] && arr[i+1][1]<arr[i][1])
{
nr[i][1]=arr[i][1];
sum= arr[i][1]+arr[i+1][1]-arr[i+1][0];
arr[i+1][1]=sum;
continue;
}
else if(arr[i][1]>arr[i+1][0] && arr[i+1][1]==0)
{
nr[i][1]= arr[i][1];
sum= arr[i][1]+arr[i+1][1]-arr[i+1][0];
arr[i+1][1]=sum;
continue;
}
else
{
sum= arr[i][1]+arr[i+1][1]-arr[i+1][0];
arr[i+1][1]=sum;
nr[i][1]=sum;
continue;
}
}
}
for(i=0;i<n-2;i++)
{
if(nr[0][1]<nr[i][1])
{
nr[0][1]=nr[i][1];
}
else{continue;}
}
printf("%d",nr[0][1]);
return 0;
}
| |
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | C | 74b90fe9458b147568ac9bd09f219aab | 0cdbd9388e0de27f88b231fe4d1104cd | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1316098800 | ["4\n0 3\n2 5\n4 2\n4 0"] | NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | PASSED | 800 | standard input | 2 seconds | The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0. | ["6"] | #include<stdio.h>
#include<math.h>
int main()
{
int arr[1000][2];
int nr[1000][2];
int i,j,p,n,sum,max,t;
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&arr[i][j]);
}
}
for(i=0;i<n-1;i++)
{
for(j=1; j<2; j++)
{
if(arr[i][1]==arr[i+1][0]&& arr[i+1][1]==0)
{
nr[i][1]=arr[i+1][0];
continue;
}
else if(arr[i][1]==arr[i+1][0] && arr[i+1][1]<arr[i][1])
{
nr[i][1]=arr[i][1];
sum= arr[i][1]+arr[i+1][1]-arr[i+1][0];
arr[i+1][1]=sum;
continue;
}
else if(arr[i][1]>arr[i+1][0] && arr[i+1][1]==0)
{
nr[i][1]= arr[i][1];
sum= arr[i][1]+arr[i+1][1]-arr[i+1][0];
arr[i+1][1]=sum;
continue;
}
else if(j==1)
{
sum= arr[i][1]+arr[i+1][1]-arr[i+1][0];
arr[i+1][1]=sum;
nr[i][1]=sum;
continue;
}
else{continue;}
}
}
for(i=0;i<n-2;i++)
{
if(nr[0][1]<nr[i][1])
{
nr[0][1]=nr[i][1];
}
else{continue;}
}
printf("%d",nr[0][1]);
return 0;
}
| |
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | C | 74b90fe9458b147568ac9bd09f219aab | b62a75e562d23114f64e902efcc60b5c | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1316098800 | ["4\n0 3\n2 5\n4 2\n4 0"] | NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | PASSED | 800 | standard input | 2 seconds | The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0. | ["6"] | #include <stdio.h>
#include <stdlib.h>
int main(){
int n=0;
scanf("%d",&n);
int pass=0;
int capacity=0;
//int change=enter-exitt;
for(int i=0;i<n;i++){
int exitt=0;
int enter=0;
scanf("%d %d\n",&exitt,&enter);
pass = pass+enter-exitt;
if(pass>capacity){
capacity=pass;
}
}
printf("%d",capacity);
return 0;
} | |
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | C | 74b90fe9458b147568ac9bd09f219aab | c28079bf6370345339e4367e8883d4c6 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1316098800 | ["4\n0 3\n2 5\n4 2\n4 0"] | NoteFor the first example, a capacity of 6 is sufficient: At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | PASSED | 800 | standard input | 2 seconds | The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops. Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement. The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0. At the last stop, all the passengers exit the tram and it becomes empty. More formally, . No passenger will enter the train at the last stop. That is, bn = 0. | ["6"] | #include<stdio.h>
int main()
{
int a,d,b,c,e,f=0,g=-1;
scanf("%d",&a);
for(b=1;b<=a;b++)
{
scanf("%d %d",&c,&e);
f=f-c;
f=f+e;
if(g<f)
g=f;
}
printf("%d",g);
}
| |
Polycarp wants to buy exactly $$$n$$$ shovels. The shop sells packages with shovels. The store has $$$k$$$ types of packages: the package of the $$$i$$$-th type consists of exactly $$$i$$$ shovels ($$$1 \le i \le k$$$). The store has an infinite number of packages of each type.Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly $$$n$$$ shovels?For example, if $$$n=8$$$ and $$$k=7$$$, then Polycarp will buy $$$2$$$ packages of $$$4$$$ shovels.Help Polycarp find the minimum number of packages that he needs to buy, given that he: will buy exactly $$$n$$$ shovels in total; the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from $$$1$$$ to $$$k$$$, inclusive. | Print $$$t$$$ answers to the test cases. Each answer is a positive integer — the minimum number of packages. | C | f00eb0452f5933103f1f77ef06473c6a | 43cd225ae5432fad46d3ae6df857b97d | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"number theory",
"math"
] | 1590327300 | ["5\n8 7\n8 1\n6 10\n999999733 999999732\n999999733 999999733"] | NoteThe answer to the first test case was explained in the statement.In the second test case, there is only one way to buy $$$8$$$ shovels — $$$8$$$ packages of one shovel.In the third test case, you need to buy a $$$1$$$ package of $$$6$$$ shovels. | PASSED | 1,300 | standard input | 2 seconds | The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then, $$$t$$$ test cases follow, one per line. Each test case consists of two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 10^9$$$) — the number of shovels and the number of types of packages. | ["2\n8\n1\n999999733\n1"] | #include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main()
{
int tc;
scanf("%d",&tc);
while(tc--){
long long n,k,i,d,dd,ans;
scanf("%lld%lld",&n,&k);
if(n<=k){
printf("1\n");
continue;
}
ans=n;
for(i=1;i<=ceil(sqrt(n));i++){
if(!(n%i)){
d=n/i;
if(d<=k){
ans=i;
break;
}
if(i<=k)
ans=d;
}
}
printf("%lld\n",ans);
}
} | |
Polycarp wants to buy exactly $$$n$$$ shovels. The shop sells packages with shovels. The store has $$$k$$$ types of packages: the package of the $$$i$$$-th type consists of exactly $$$i$$$ shovels ($$$1 \le i \le k$$$). The store has an infinite number of packages of each type.Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly $$$n$$$ shovels?For example, if $$$n=8$$$ and $$$k=7$$$, then Polycarp will buy $$$2$$$ packages of $$$4$$$ shovels.Help Polycarp find the minimum number of packages that he needs to buy, given that he: will buy exactly $$$n$$$ shovels in total; the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from $$$1$$$ to $$$k$$$, inclusive. | Print $$$t$$$ answers to the test cases. Each answer is a positive integer — the minimum number of packages. | C | f00eb0452f5933103f1f77ef06473c6a | 2bb4c1edbe9ddd501ef217572cb07cb1 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"number theory",
"math"
] | 1590327300 | ["5\n8 7\n8 1\n6 10\n999999733 999999732\n999999733 999999733"] | NoteThe answer to the first test case was explained in the statement.In the second test case, there is only one way to buy $$$8$$$ shovels — $$$8$$$ packages of one shovel.In the third test case, you need to buy a $$$1$$$ package of $$$6$$$ shovels. | PASSED | 1,300 | standard input | 2 seconds | The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then, $$$t$$$ test cases follow, one per line. Each test case consists of two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 10^9$$$) — the number of shovels and the number of types of packages. | ["2\n8\n1\n999999733\n1"] | #include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int T,t;
scanf("%d",&T);
for(t=0;t<T;t++)
{
long int n,k;
scanf("%ld %ld",&n,&k);
long int i,max=1;
if(k>=n)
{
printf("1\n");
}
else
{
long int m;
m = sqrt(n);
for(i=1; i <= m ;i++)
{
if(n%i == 0)
{
if(i>max && i<=k)
{
max = i;
//printf("max = %ld\n",max);
}
if(n/i > max && n/i <=k)
{
max = n/i;
//printf("max = %ld\n",max);
}
}
}
//printf("max = %ld",max);
max = n/max;
//printf("ld\n",max);
printf("%ld\n",max);
}
}
return 0;
} | |
Polycarp wants to buy exactly $$$n$$$ shovels. The shop sells packages with shovels. The store has $$$k$$$ types of packages: the package of the $$$i$$$-th type consists of exactly $$$i$$$ shovels ($$$1 \le i \le k$$$). The store has an infinite number of packages of each type.Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly $$$n$$$ shovels?For example, if $$$n=8$$$ and $$$k=7$$$, then Polycarp will buy $$$2$$$ packages of $$$4$$$ shovels.Help Polycarp find the minimum number of packages that he needs to buy, given that he: will buy exactly $$$n$$$ shovels in total; the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from $$$1$$$ to $$$k$$$, inclusive. | Print $$$t$$$ answers to the test cases. Each answer is a positive integer — the minimum number of packages. | C | f00eb0452f5933103f1f77ef06473c6a | 81b5a2e344b8e61f100d1d4fffc0684a | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"number theory",
"math"
] | 1590327300 | ["5\n8 7\n8 1\n6 10\n999999733 999999732\n999999733 999999733"] | NoteThe answer to the first test case was explained in the statement.In the second test case, there is only one way to buy $$$8$$$ shovels — $$$8$$$ packages of one shovel.In the third test case, you need to buy a $$$1$$$ package of $$$6$$$ shovels. | PASSED | 1,300 | standard input | 2 seconds | The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then, $$$t$$$ test cases follow, one per line. Each test case consists of two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 10^9$$$) — the number of shovels and the number of types of packages. | ["2\n8\n1\n999999733\n1"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
typedef unsigned long long int ull;
int compare(const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
void swap(int *x,int *y)
{
int temp=*x;
*x=*y;
*y=temp;
}
int max(int x,int y)
{
return x>y?x:y;
}
int min(int x,int y)
{
return x<y?x:y;
}
int abs(int x)
{
return x<0?(-1)*x:x;
}
int arrayMax(int *array,int n)
{
int max=INT_MIN;
for(int i=0;i<n;i++)
{
if(array[i]>max)
{
max=array[i];
}
}
return max;
}
void arrayReverse(int *array,int n)
{
int l=0;
int h=n-1;
while(l<h)
{
swap(&array[l],&array[h]);
l++;
h--;
}
}
int arrayMin(int *array,int n)
{
int min=INT_MAX;
for(int i=0;i<n;i++)
{
if(array[i]<min)
{
min=array[i];
}
}
return min;
}
int arraySum(int *array,int n)
{
int sum=0;
for(int i=0;i<n;i++)
{
sum+=array[i];
}
return sum;
}
void arrayPrint(int *array,int n)
{
for(int i=0;i<n;i++)
{
printf("%d ",array[i]);
}
}
void arrayScan(int *array,int n,int index)
{
if(index==0)
{
for(int i=0;i<n;i++)
{
scanf("%d",&array[i]);
}
}
else
{
for(int i=1;i<=n;i++)
{
scanf("%d",&array[i]);
}
}
}
void arrayInit(int *array,int n,int value)
{
for(int i=0;i<n;i++)
{
array[i]=value;
}
}
void arraySort(int *array,int n)
{
qsort(array,n,sizeof(array[0]),compare);
}
char *SieveOfEratosthenes(int n)
{
char *prime=(char *)calloc(sizeof(char),n+1);
for(int i=0;i<n;i++)
{
prime[i]=1;
}
for (int p=2;p*p<=n;p++)
{
if (prime[p] == 1)
{
for (int i=p*p; i<=n; i += p)
prime[i] = 0;
}
}
return prime;
}
int gcd(int x,int y)
{
if(y==0)
{
return x;
}
return gcd(y,x%y);
}
int *findDivisors(int n,int *x)
{
int *v=(int *)calloc(sizeof(int),n);
int k=0;
for (int i = 1; i <= sqrt(n); i++) {
if (n % i == 0) {
if (n / i == i)
v[k++]=i;
else {
v[k++]=i;
v[k++]=(n/i);
}
}
}
*x=k;
return v;
}
void solve()
{
int n,k;
scanf("%d %d",&n,&k);
if(k>=n)
{
printf("1\n");
}
else
{
int temp=(int)sqrt((double)n);
int i=2;
int mini=INT_MAX;
while(i<=temp)
{
if(n%i==0)
{
if(n/i<=k)
{
printf("%d\n",i);
return;
}
else if(i<=k)
{
if(mini>(n/i))
{
mini=(n/i);
}
}
}
i++;
}
printf("%d\n",min(n,mini));
}
}
int main()
{
int test;
scanf("%d",&test);
while(test>0)
{
solve();
test--;
}
// solve();
return 0;
} | |
Polycarp wants to buy exactly $$$n$$$ shovels. The shop sells packages with shovels. The store has $$$k$$$ types of packages: the package of the $$$i$$$-th type consists of exactly $$$i$$$ shovels ($$$1 \le i \le k$$$). The store has an infinite number of packages of each type.Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly $$$n$$$ shovels?For example, if $$$n=8$$$ and $$$k=7$$$, then Polycarp will buy $$$2$$$ packages of $$$4$$$ shovels.Help Polycarp find the minimum number of packages that he needs to buy, given that he: will buy exactly $$$n$$$ shovels in total; the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from $$$1$$$ to $$$k$$$, inclusive. | Print $$$t$$$ answers to the test cases. Each answer is a positive integer — the minimum number of packages. | C | f00eb0452f5933103f1f77ef06473c6a | 3ee89683c5c22aac4dbfb57261d9acd8 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"number theory",
"math"
] | 1590327300 | ["5\n8 7\n8 1\n6 10\n999999733 999999732\n999999733 999999733"] | NoteThe answer to the first test case was explained in the statement.In the second test case, there is only one way to buy $$$8$$$ shovels — $$$8$$$ packages of one shovel.In the third test case, you need to buy a $$$1$$$ package of $$$6$$$ shovels. | PASSED | 1,300 | standard input | 2 seconds | The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then, $$$t$$$ test cases follow, one per line. Each test case consists of two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 10^9$$$) — the number of shovels and the number of types of packages. | ["2\n8\n1\n999999733\n1"] | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
int arr[100];
void result(int n1)
{
int i;
for(i=0; i<n1; ++i)
{
printf("%d\n", arr[i]);
}
}
void timUoc(int m, int k, int n)
{
int i;
for(i=1; i<= sqrt(m); ++i)
{
if(m%i==0)
{
if(m/i <= k)
{
arr[n]=i;
break;
}
if(i <= k)
{
arr[n] = m/i;
}
else
{
break;
}
}
}
}
void nhap(int n)
{
int m, k;
scanf("%d%d", &m, &k);
timUoc(m, k, n);
}
int main()
{
int n1, i;
scanf("%d", &n1);
for(i=0; i<n1; ++i)
{
nhap(i);
}
result(n1);
return 0;
} | |
Polycarp wants to buy exactly $$$n$$$ shovels. The shop sells packages with shovels. The store has $$$k$$$ types of packages: the package of the $$$i$$$-th type consists of exactly $$$i$$$ shovels ($$$1 \le i \le k$$$). The store has an infinite number of packages of each type.Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly $$$n$$$ shovels?For example, if $$$n=8$$$ and $$$k=7$$$, then Polycarp will buy $$$2$$$ packages of $$$4$$$ shovels.Help Polycarp find the minimum number of packages that he needs to buy, given that he: will buy exactly $$$n$$$ shovels in total; the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from $$$1$$$ to $$$k$$$, inclusive. | Print $$$t$$$ answers to the test cases. Each answer is a positive integer — the minimum number of packages. | C | f00eb0452f5933103f1f77ef06473c6a | 9b57593fc20e4011be967485e92a60d0 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"number theory",
"math"
] | 1590327300 | ["5\n8 7\n8 1\n6 10\n999999733 999999732\n999999733 999999733"] | NoteThe answer to the first test case was explained in the statement.In the second test case, there is only one way to buy $$$8$$$ shovels — $$$8$$$ packages of one shovel.In the third test case, you need to buy a $$$1$$$ package of $$$6$$$ shovels. | PASSED | 1,300 | standard input | 2 seconds | The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then, $$$t$$$ test cases follow, one per line. Each test case consists of two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 10^9$$$) — the number of shovels and the number of types of packages. | ["2\n8\n1\n999999733\n1"] | #include<stdio.h>
#include<math.h>
#include<limits.h>
long long int min(long long int a,long long int b)
{
if(a>b)
return b;
else
return a;
}
int main()
{
int t ,i;
scanf("%d",&t);
for(i=0;i<t;i++)
{
long long int n=0,k=0,j=0,z=0;long long int b=LLONG_MAX;
scanf("%lld %lld",&n,&k);
if(n<=k)
{
b=1;
}
else if(k==1)
{
b=n;
}
else
{
for( j=2;j<=sqrt(n);j++)
{
if(n%j==0)
{
if(j==n/j && j<=k)
{
b=min(b,j);
z=-1;
}
else
{
if(j<=k)
{
b=min(b,n/j);
z=-1;
}
if(n/j<=k)
{
b=min(b,j);
z=-1;
}
}
}
}
if(z==0)
{
b=n;
}
}
printf("%lld\n",b);
}
} | |
Polycarp wants to buy exactly $$$n$$$ shovels. The shop sells packages with shovels. The store has $$$k$$$ types of packages: the package of the $$$i$$$-th type consists of exactly $$$i$$$ shovels ($$$1 \le i \le k$$$). The store has an infinite number of packages of each type.Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly $$$n$$$ shovels?For example, if $$$n=8$$$ and $$$k=7$$$, then Polycarp will buy $$$2$$$ packages of $$$4$$$ shovels.Help Polycarp find the minimum number of packages that he needs to buy, given that he: will buy exactly $$$n$$$ shovels in total; the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from $$$1$$$ to $$$k$$$, inclusive. | Print $$$t$$$ answers to the test cases. Each answer is a positive integer — the minimum number of packages. | C | f00eb0452f5933103f1f77ef06473c6a | bbc9ccff12df4de81e5b4f3995c8c4d7 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"number theory",
"math"
] | 1590327300 | ["5\n8 7\n8 1\n6 10\n999999733 999999732\n999999733 999999733"] | NoteThe answer to the first test case was explained in the statement.In the second test case, there is only one way to buy $$$8$$$ shovels — $$$8$$$ packages of one shovel.In the third test case, you need to buy a $$$1$$$ package of $$$6$$$ shovels. | PASSED | 1,300 | standard input | 2 seconds | The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then, $$$t$$$ test cases follow, one per line. Each test case consists of two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 10^9$$$) — the number of shovels and the number of types of packages. | ["2\n8\n1\n999999733\n1"] | #include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
long long int n,k,k1,i,r;
scanf("%lld%lld",&n,&k);
if(k>=n)
printf("1\n");
else
{
i=2;
k1=k;
while(1)
{
if(k1<=k&&n%k1==0)
break;
k1=n/i;
r=n%i;
r/=k1;
if(r!=0)
i+=r;
else
i++;
// printf("k1 %d n %d i %d\n",k1,n,i);
}
printf("%lld\n",n/k1);
}
}
return 0;
}
| |
Polycarp wants to buy exactly $$$n$$$ shovels. The shop sells packages with shovels. The store has $$$k$$$ types of packages: the package of the $$$i$$$-th type consists of exactly $$$i$$$ shovels ($$$1 \le i \le k$$$). The store has an infinite number of packages of each type.Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly $$$n$$$ shovels?For example, if $$$n=8$$$ and $$$k=7$$$, then Polycarp will buy $$$2$$$ packages of $$$4$$$ shovels.Help Polycarp find the minimum number of packages that he needs to buy, given that he: will buy exactly $$$n$$$ shovels in total; the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from $$$1$$$ to $$$k$$$, inclusive. | Print $$$t$$$ answers to the test cases. Each answer is a positive integer — the minimum number of packages. | C | f00eb0452f5933103f1f77ef06473c6a | bedf29f4dab1dd9d5ee9e4260fa70ee2 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"number theory",
"math"
] | 1590327300 | ["5\n8 7\n8 1\n6 10\n999999733 999999732\n999999733 999999733"] | NoteThe answer to the first test case was explained in the statement.In the second test case, there is only one way to buy $$$8$$$ shovels — $$$8$$$ packages of one shovel.In the third test case, you need to buy a $$$1$$$ package of $$$6$$$ shovels. | PASSED | 1,300 | standard input | 2 seconds | The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then, $$$t$$$ test cases follow, one per line. Each test case consists of two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 10^9$$$) — the number of shovels and the number of types of packages. | ["2\n8\n1\n999999733\n1"] | #include<stdio.h>
int main()
{
int t;
scanf("%d", &t);
long long int n, k;
long long int i;
long long int ans;
for (; t > 0; t--)
{
scanf("%lld %lld", &n, &k);
ans = n;
for (i = 1; i * i <= n; i++)
{
if (n % i == 0)
{
if (i <= k)
{
if (ans > n / i)
ans = n / i;
}
if (n / i <= k)
{
if (ans > i)
ans = i;
}
}
}
printf("%lld\n", ans);
}
return 0;
} | |
Polycarp wants to buy exactly $$$n$$$ shovels. The shop sells packages with shovels. The store has $$$k$$$ types of packages: the package of the $$$i$$$-th type consists of exactly $$$i$$$ shovels ($$$1 \le i \le k$$$). The store has an infinite number of packages of each type.Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly $$$n$$$ shovels?For example, if $$$n=8$$$ and $$$k=7$$$, then Polycarp will buy $$$2$$$ packages of $$$4$$$ shovels.Help Polycarp find the minimum number of packages that he needs to buy, given that he: will buy exactly $$$n$$$ shovels in total; the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from $$$1$$$ to $$$k$$$, inclusive. | Print $$$t$$$ answers to the test cases. Each answer is a positive integer — the minimum number of packages. | C | f00eb0452f5933103f1f77ef06473c6a | 6105cb72d5a6fb7e79328c72600e775c | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"number theory",
"math"
] | 1590327300 | ["5\n8 7\n8 1\n6 10\n999999733 999999732\n999999733 999999733"] | NoteThe answer to the first test case was explained in the statement.In the second test case, there is only one way to buy $$$8$$$ shovels — $$$8$$$ packages of one shovel.In the third test case, you need to buy a $$$1$$$ package of $$$6$$$ shovels. | PASSED | 1,300 | standard input | 2 seconds | The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then, $$$t$$$ test cases follow, one per line. Each test case consists of two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 10^9$$$) — the number of shovels and the number of types of packages. | ["2\n8\n1\n999999733\n1"] | #include <stdio.h>
#include <math.h>
#include <string.h>
int main()
{
int i,j,k,n,t,z;
scanf("%d",&t);
for(int z1=0;z1<t;z1++)
{
scanf("%d%d",&n,&k);
j=n;
for(i=1;i<=sqrt(n);i++)
{
z=i;
if(n%z==0&&z<=k)
{
z=n/z;
if(z<j)
j=z;
}
z=n/i;
if(n%z==0&&z<=k)
{
z=n/z;
if(z<j)
j=z;
}
}
printf("%d\n",j);
}
} | |
Polycarp wants to buy exactly $$$n$$$ shovels. The shop sells packages with shovels. The store has $$$k$$$ types of packages: the package of the $$$i$$$-th type consists of exactly $$$i$$$ shovels ($$$1 \le i \le k$$$). The store has an infinite number of packages of each type.Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly $$$n$$$ shovels?For example, if $$$n=8$$$ and $$$k=7$$$, then Polycarp will buy $$$2$$$ packages of $$$4$$$ shovels.Help Polycarp find the minimum number of packages that he needs to buy, given that he: will buy exactly $$$n$$$ shovels in total; the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from $$$1$$$ to $$$k$$$, inclusive. | Print $$$t$$$ answers to the test cases. Each answer is a positive integer — the minimum number of packages. | C | f00eb0452f5933103f1f77ef06473c6a | 1a51541bff4d78c61a20b01519aca9df | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"number theory",
"math"
] | 1590327300 | ["5\n8 7\n8 1\n6 10\n999999733 999999732\n999999733 999999733"] | NoteThe answer to the first test case was explained in the statement.In the second test case, there is only one way to buy $$$8$$$ shovels — $$$8$$$ packages of one shovel.In the third test case, you need to buy a $$$1$$$ package of $$$6$$$ shovels. | PASSED | 1,300 | standard input | 2 seconds | The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then, $$$t$$$ test cases follow, one per line. Each test case consists of two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 10^9$$$) — the number of shovels and the number of types of packages. | ["2\n8\n1\n999999733\n1"] | #include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
int cmp(const void* _a , const void* _b)
{
int* a = (int*)_a;
int* b = (int*)_b;
return *a - *b;
}
int main()
{
int t;
int i,j;
int k,n;
int sum[2]={0};
int max;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&k);
max=1;
if(k<=floor(sqrt(n)))
{
for(i=1;i<=k;i++)
{
if(n%i==0)
{
max=i;
}
}
}
else
{
for(i=1;i<=floor(sqrt(n));i++)
{
if(n%i==0)
{
if(k>=n/i)
{
max=n/i;
break;
}
if(max<i)max=i;
}
}
}
printf("%d\n",n/max);
}
return 0;
}
| |
Polycarp wants to buy exactly $$$n$$$ shovels. The shop sells packages with shovels. The store has $$$k$$$ types of packages: the package of the $$$i$$$-th type consists of exactly $$$i$$$ shovels ($$$1 \le i \le k$$$). The store has an infinite number of packages of each type.Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly $$$n$$$ shovels?For example, if $$$n=8$$$ and $$$k=7$$$, then Polycarp will buy $$$2$$$ packages of $$$4$$$ shovels.Help Polycarp find the minimum number of packages that he needs to buy, given that he: will buy exactly $$$n$$$ shovels in total; the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from $$$1$$$ to $$$k$$$, inclusive. | Print $$$t$$$ answers to the test cases. Each answer is a positive integer — the minimum number of packages. | C | f00eb0452f5933103f1f77ef06473c6a | 0cd5751112ddaaed329d1ae9c681c8c3 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"number theory",
"math"
] | 1590327300 | ["5\n8 7\n8 1\n6 10\n999999733 999999732\n999999733 999999733"] | NoteThe answer to the first test case was explained in the statement.In the second test case, there is only one way to buy $$$8$$$ shovels — $$$8$$$ packages of one shovel.In the third test case, you need to buy a $$$1$$$ package of $$$6$$$ shovels. | PASSED | 1,300 | standard input | 2 seconds | The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then, $$$t$$$ test cases follow, one per line. Each test case consists of two positive integers $$$n$$$ ($$$1 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 10^9$$$) — the number of shovels and the number of types of packages. | ["2\n8\n1\n999999733\n1"] | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
long long int min(long long a,long long b){
if(a<b)return a;
else return b;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
long long n,k;
scanf("%lld %lld",&n,&k);
if(n<=k)
printf("%d\n",1 );
else{
long long int max=2000000000;
for(long long int i=1;i<=sqrt(n) && i<=k;i++){
if(n%i==0){
max = min(max, n / i);
if (n / i <= k)
max = min(max, i);
}
}
printf("%lld\n",max);
}
}
return 0;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.