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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | fb817e4aa1da36603bdba818e555c3eb | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | #include<stdio.h>
#include<stdlib.h>
typedef struct IndM{
long long int I;
struct IndM *Sgte;
} INDM;
int minimo(INDM *, int * , int );
int main(){
int i,cant;
INDM *aux;
INDM *indices;
scanf("%d",&cant);
int edad[cant],desc[cant];
for(i=0;i<cant;i++){
scanf("%d",&edad[i]);
}
indices=(INDM *)malloc(sizeof(INDM));
indices->I=cant-1;
indices->Sgte=NULL;
for(i=cant-1;i>=0;i--){
if(edad[i]>edad[indices->I]){
desc[i]=minimo(indices,edad,i);
}
else{
if(edad[i]<edad[indices->I]){
aux=(INDM *)malloc(sizeof(INDM));
aux->I=i;
aux->Sgte=indices;
indices=aux;
}
desc[i]=-1;
}
}
for(i=0;i<cant;i++){
printf("%d ",desc[i]);
}
return 0;
}
int minimo(INDM *Aux, int E[],int N){
int I;
for(;Aux!=NULL && E[N]>E[Aux->I]; Aux=Aux->Sgte)
I=Aux->I-N-1;
return I;
}
| |
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | 3158310cb2a3b73333e26fe2f18890e0 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | #include<stdio.h>
#include<stdlib.h>
typedef struct Nodo
{
int posicion;
struct Nodo *siguiente;
} morsa;
int main()
{
morsa *siguiente,*aux;
int i,n;
scanf("%d",&n);
int a[n+1];
int v[n+1];
for(i = 0; i < n; i++)
scanf("%d",&a[i]);
siguiente = (morsa*)malloc(sizeof(morsa));
siguiente->posicion = n-1;
siguiente->siguiente = NULL ;
for(i = n-1; i >=0; i--)
{
if(a[i] > a[siguiente->posicion])
{
aux=siguiente;
while(aux != NULL && a[i] > a[aux->posicion])
{
v[i] = aux->posicion - i -1;
aux=aux->siguiente;
}
}
else
{
v[i] = -1;
if( a[i] < a[siguiente->posicion])
{
morsa *nuevo;
nuevo = (morsa*)malloc(sizeof(morsa));
nuevo->posicion = i;
nuevo->siguiente = siguiente;
siguiente = nuevo;
}
}
}
for(i = 0; i < n; i++)
printf("%d ",v[i]);
return 0;
}
| |
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | 47018fa70cae4c1b3a66d7517ce156bc | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | #include<stdio.h>
#include<stdlib.h>
typedef struct nodo
{
int pos; /*se guarda la posicion de los menores que se van encontrando en la fila a medida que se recorre el vector*/
struct nodo *sig; /*el orden es de menor a mayor*/
} contento;
int main()
{
contento *sig,*aux;
int i,n;
scanf("%d",&n);
int a[n+1];/*vector de edades*/
int v[n+1];/*vector de descontento*/
for(i = 0; i < n; i++)
scanf("%d",&a[i]);
sig = (contento*)malloc(sizeof(contento));
sig->pos = n-1;/*el primer contento(nodo de la lista) siempre es el primero en la fila*/
sig->sig = NULL ;
for(i = n-1; i >=0; i--)
{
if(a[i] > a[sig->pos])
{
aux=sig;
while(aux != NULL && a[i] > a[aux->pos])
{
v[i] = aux->pos - i -1;/*se van cambiando los valores (con la distancia) mientras que encuentre un contento menor al actual*/
aux=aux->sig;
}
}
else
{
v[i] = -1;/*se agrega un contento a la lista de descontentos*/
if( a[i] < a[sig->pos])/*si se encuentra un menor al menor actual, se agrega a la lista de contentos(no ocurre cuando es de edad igual*/
{
contento *nuevo;
nuevo = (contento*)malloc(sizeof(contento));
nuevo->pos = i;
nuevo->sig = sig;
sig = nuevo;
}
}
}
for(i = 0; i < n; i++)
printf("%d ",v[i]);
return 0;
}
| |
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | 98b829bfdc8cca8ea3eb73b876fdfa58 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | #include <stdio.h>
#include <stdlib.h>
#define N 100010
int vec[N];
int vec2[N];
int aux[N];
int aux2[N];
void mezcla( int l, int h);
int main(){
int n;
int que[N];
scanf("%d",&n);
int i=0;
for(i=0;i<n;i++)
{
scanf("%d",&que[i]);
vec[i]=que[i];
vec2[i]=i+1;
}
mezcla(0,n-1);
int cont=0;
for(i=0;i<n;i++)
{
if(i==0)
{
que[vec2[i]-1]=-1;
cont=vec2[i];
}
else if(vec2[i]<cont)
que[vec2[i]-1]=cont-vec2[i]-1;
else{
que[vec2[i]-1]=-1;
cont=vec2[i];
}
}
for(i=0;i<n;i++)
{
printf("%d",que[i]);
if(i+1<n)
printf(" ");
}
return 0;
}
void mezcla( int l, int h){
int i = 0;
int longitud = h - l + 1;
int pivot = 0;
int x = 0;
int y = 0;
if(l == h)
return;
pivot = (l + h) / 2;
mezcla( l, pivot);
mezcla( pivot + 1, h);
for(i = 0; i < longitud; i++){
aux[i] = vec[l + i];
aux2[i]=vec2[l+i];
}
x = 0;
y = pivot - l + 1;
for(i = 0; i < longitud; i++)
{
if(y <= h - l){
if(x <= pivot - l)
{
if(aux[x] > aux[y])
{
vec[i + l] = aux[y];
vec2[i + l] = aux2[y];
y++;
}
else
{
vec[i + l] = aux[x];
vec2[i + l] = aux2[x];
x++;
}
}
else{
vec[i + l] = aux[y];
vec2[i + l] = aux2[y];
y++;
}
}
else
{
vec[i + l] = aux[x];
vec2[i + l] = aux2[x];
x++;
}
}
}
| |
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | 20b36756832d355bc35aea57959fa07f | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | #include <stdio.h>
int morsas[100005], menor[100005];
int main() {
int n ,i, izq, der, med ;
scanf("%d", &n);
for(i = 0; i < n; i++) {
scanf("%d", &morsas[i]);
}
menor[n-1] = morsas[n-1];
for(i = n - 2; i >= 0; i--) {
if(morsas[i] < menor[i+1]){
menor[i] = morsas[i];
}else{
menor[i] = menor[i+1];
}
}
for(i = 0; i < n - 1; i++) {
if(menor[i+1] < morsas[i]) {
izq = i + 1;
der = n - 1;
while(izq < der-1) {
med = (izq+der)/2;
if(menor[med] < morsas[i]) {
izq = med;
} else {
der = med;
}
}
if(menor[der] < morsas[i]){
izq = der;
}
printf("%d ", izq - i - 1);
} else {
printf("-1 ");
}
}
printf("-1 ");
return 0;
}
| |
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | 2d7f6fa0c761d9b27b5129adeabe3c42 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | #include <stdio.h>
#define MAXN 100000
struct walrus_t
{
int position ;
int younger ;
int age ;
} ;
struct walrus_t walruses[MAXN] ;
void solve(int queue[], int size)
{
static int temp[MAXN] ;
int i, j, k, p ;
if (size > 1)
{
solve(queue, size / 2) ;
solve(queue + size / 2, size - size / 2) ;
for (i = 0 ; i < size / 2 ; i++)
{
temp[i] = queue[i] ;
}
for (i = size - 1, j = size / 2 ; i >= size / 2 ; i--, j++)
{
temp[i] = queue[j] ;
}
i = 0 ;
j = size - 1 ;
k = 0 ;
p = 0 ;
while (i <= j)
{
if (walruses[temp[i]].age < walruses[temp[j]].age || (walruses[temp[i]].age == walruses[temp[j]].age && walruses[temp[i]].position < walruses[temp[j]].position))
{
queue[k] = temp[i] ;
if (walruses[queue[k]].position < p)
{
walruses[queue[k]].younger = p ;
}
else
{
p = walruses[queue[k]].position ;
}
k++ ;
i++ ;
}
else
{
queue[k] = temp[j] ;
if (walruses[queue[k]].position < p)
{
walruses[queue[k]].younger = p ;
}
else
{
p = walruses[queue[k]].position ;
}
k++ ;
j-- ;
}
}
}
}
int displeasure(int d)
{
return (d < 0 ? -1 : d) ;
}
int main(int argc, char *argv[])
{
int queue[MAXN], i, size ;
scanf("%d", &size) ;
for (i = 0 ; i < size ; i++)
{
queue[i] = i ;
scanf("%d", &walruses[i].age) ;
walruses[i].position = i ;
}
solve(queue, size) ;
printf("%d", displeasure(walruses[0].younger - walruses[0].position - 1)) ;
for (i = 1 ; i < size ; i++)
{
printf(" %d", displeasure(walruses[i].younger - walruses[i].position - 1)) ;
}
printf("\n") ;
return 0 ;
}
| |
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | 01543bb288b382d6c41d27345cd28370 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | #include <stdio.h>
int morsas[100005], menor[100005];
int main() {
int n ,i, izq, der, med ;
scanf("%d", &n);
for(i = 0; i < n; i++) {
scanf("%d", &morsas[i]);
}
menor[n-1] = morsas[n-1];
for(i = n - 2; i >= 0; i--) {
if(morsas[i] < menor[i+1]){
menor[i] = morsas[i];
}else{
menor[i] = menor[i+1];
}
}
for(i = 0; i < n - 1; i++) {
if(menor[i+1] < morsas[i]) {
izq = i + 1;
der = n - 1;
while(izq < der-1) {
med = (izq+der)/2;
if(menor[med] < morsas[i]) {
izq = med;
} else {
der = med;
}
}
if(menor[der] < morsas[i]){
izq = der;
}
printf("%d ", izq - i - 1);
} else {
printf("-1 ");
}
}
printf("-1 ");
return 0;
} | |
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | 0a017e676c5407b6dfe30844ff5619c2 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | #include <stdio.h>
int a[100005],b[100005];
int main() {
int n,i,l,r,med ;
scanf("%d", &n);
for(i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
b[n-1]=a[n-1];
for(i = n - 2; i >= 0; i--) {
if(a[i]<b[i+1]){
b[i]=a[i];
}else{
b[i]=b[i+1];
}
}
for(i = 0; i < n - 1; i++) {
if(b[i+1]<a[i]) {
l= i + 1;
r=n-1;
while(l<r-1) {
med = (l+r)/2;
if(b[med]<a[i]) {
l=med;
} else {
r=med;
}
}
if(b[r] <a[i]){
l=r;
}
printf("%d ", l-i-1);
} else {
printf("-1 ");
}
}
printf("-1 ");
return 0;
}
| |
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | 0acc1ce7b79dab83f153f7bb5590566e | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | #include <stdio.h>
#define M 100005
typedef struct {
int no;
long long age;
} Record;
Record r[M];
int n;
int displs[100005];
int comp(const void *a, const void *b)
{
if((*(Record *)a).age != (*(Record *)b).age)
return (*(Record *)a).age > (*(Record *)b).age ? 1 : -1;
else
return (*(Record *)a).no > (*(Record *)b).no ? 1 : -1;
}
int main()
{
int i, j;
int max;
scanf("%d", &n);
for(i = 0; i < n; i++) {
scanf("%I64d", &r[i].age);
r[i].no = i;
}
qsort(r, n, sizeof(Record), comp);
max = 0;
for(i = 0; i < n; i++) {
if(r[i].no > max)
max = r[i].no;
displs[r[i].no] = max - r[i].no -1;
}
for(i = 0; i < n; i++)
printf("%d ", displs[i]);
printf("\n");
return 0;
}
| |
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | 942b555e44d20cc84deac917927cb85b | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | #include <stdio.h>
#include <stdlib.h>
typedef struct {
int a;
int b;
} walrus;
int cmp(const void *a, const void *b)
{
if (((walrus *)a)->a != ((walrus *)b)->a) {
return ((walrus *)a)->a - ((walrus *)b)->a;
} else {
return ((walrus *)a)->b - ((walrus *)b)->b;
}
}
int main()
{
int n, m = -1, i;
int a[100000];
walrus w[100000];
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &w[i].a);
w[i].b = i;
}
qsort(w, n, sizeof(walrus), cmp);
for (i = 0; i < n; i++) {
if (w[i].b > m) m = w[i].b;
a[w[i].b] = m - w[i].b - 1;
}
for (i = 0; i < n; i++) {
if (i > 0) putchar(' ');
printf("%d", a[i]);
}
puts("");
return 0;
}
| |
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | 64d2871f93bde2e687e4cfe4747a5b12 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | #include <stdio.h>
int main()
{
int n, mitad, der, izq, i;
int v[100000];
int minimo[100000];
scanf("%d", &n);
for(i = 0; i < n; i++)
{
scanf("%d", &v[i]);
}
minimo[n-1] = v[n-1];
for(i = n - 2; i >= 0; i--)
{
if(v[i] < minimo[i+1])
{
minimo[i] = v[i];
}else{
minimo[i] = minimo[i+1];
}
}
for(i = 0; i < n - 1; i++)
{
if(minimo[i+1] < v[i])
{
der = n - 1;
izq = i + 1;
while(izq < der-1)
{
mitad = (izq+der)/2;
if(minimo[mitad] < v[i])
{
izq = mitad;
}else{
der = mitad;
}
}
if(minimo[der] < v[i])
{
izq = der;
}
printf("%d ", izq - i - 1);
}else{
printf("%d ", -1);
}
}
printf("%d ", -1);
}
| |
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | e7c860e64582a55e2623da4a9f5af09b | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | #include<stdio.h>
#include<stdlib.h>
typedef struct Nodo{
int pos;
struct Nodo *sig;
}m;
int main(){
m *sig,*aux;
int i,n;
scanf("%d",&n);
int a[n + 1];
int dis[n + 1];
for(i = 0; i < n; i++){
scanf("%d",&a[i]);
}
sig = (m*)malloc(sizeof(m));
sig -> pos = n - 1;
sig -> sig = NULL ;
for(i = n - 1; i >= 0; i--){
if(a[i] > a[sig -> pos]){
aux = sig;
while(aux != NULL && a[i] > a[aux -> pos]){
dis[i] = aux -> pos - i - 1;
aux = aux -> sig;
}
}
else{
dis[i] = -1;
if( a[i] < a[sig->pos]){
m *nuevo;
nuevo = (m*)malloc(sizeof(m));
nuevo -> pos = i;
nuevo -> sig = sig;
sig = nuevo;
}
}
}
for(i = 0; i < n; i++){
printf("%d ",dis[i]);
}
return 0;
}
| |
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | 2c0ddf56aa0db1026ad6d598aac6c796 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | #include <stdio.h>
int morsas[100005], edad[100005];
int main()
{
int n ,i, izq, der, med ;
scanf("%d", &n);
for(i = 0; i < n; i++) {
scanf("%d", &morsas[i]);
}
edad[n-1] = morsas[n-1];
for(i = n - 2; i >= 0; i--)
if(morsas[i] < edad[i+1])
{
edad[i] = morsas[i];
}
else
{
edad[i] = edad[i+1];
}
for(i = 0; i < n - 1; i++)
{
if(edad[i+1] < morsas[i])
{
izq = i + 1;
der = n - 1;
while(izq < der-1) {
med = (izq+der)/2;
if(edad[med] < morsas[i]) {
izq = med;
} else {
der = med;
}
}
if(edad[der] < morsas[i]){
izq = der;
}
printf("%d ", izq - i - 1);
} else
{
printf("-1 ");
}
}
printf("-1");
return 0;
}
| |
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | 2fecf1469f709f628678d88fd6b890f2 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | #include <stdio.h>
int n,num[100010];
int mn[100010];
int work(int pos)
{
int head = pos,tail = n,mid;
while(head<tail)
{
mid = (head+tail+1)>>1;
if(mn[mid]<num[pos]) head = mid;
else tail = mid-1;
}
return head-pos-1;
}
int main()
{
int i;
scanf("%d",&n);
for(i=1;i<=n;i++) scanf("%d",&num[i]);
mn[n] = num[n];
for(i=n-1;i;i--) mn[i] = mn[i+1]<num[i]?mn[i+1]:num[i];
for(i=1;i<=n;i++) printf("%d ",work(i));
return 0;
} | |
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | d00f3b3a583007c8100914dcc9c56f8a | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | #include <stdio.h>
#include <time.h>
struct zxf
{
long c,num;
}a[100005]={0,0},tmp;
long ans[100005]={0};
void quick(long l,long r)
{
long i,j,t;
t=l+rand()%(r-l); i=l; j=r+1;
while(i<j)
{
while(i<j && a[i].c<a[t].c) i++;
if(i<j)
{
tmp=a[i]; a[i]=a[t]; a[t]=tmp;
t=i;
j--;
}
while(i<j && a[t].c<a[j].c ) j--;
if(i<j)
{
tmp=a[t]; a[t]=a[j]; a[j]=tmp;
t=j;
i++;
}
}
if(l<t-1)
quick(l,t-1);
if(t+1<r)
quick(t+1,r);
}
int main()
{
long n,now=0,i,j;
// freopen("b.in","r",stdin);
// freopen("b.out","w",stdout);
srand((unsigned)time(NULL));
scanf("%ld\n",&n);
for(i=1;i<=n;i++)
{
scanf("%ld ",&a[i].c);
a[i].num=i;
}
quick(1,n);
for(i=1;i<=n;i++)
{
if(now>a[i].num)
ans[a[i].num]=now-a[i].num-1;
else
ans[a[i].num]=-1;
if(a[i].c!=a[i+1].c )
for(j=i;j>=1;j--)
{
if(a[j].c!=a[i].c)
break;
if(a[j].num>now)
now=a[j].num;
}
}
for(i=1;i<=n;i++)
printf("%ld ",ans[i]);
return 0;
}
| |
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | 777736a3995eeb0d772d2ddfdca03411 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | #include<stdio.h>
#include<stdlib.h>
struct C{
int num;
int pos;
};
typedef struct C c;
void shell(c *v,int n);
int main()
{
int n,i=0,j,pos=0,b,k;
scanf("%d",&n);
c v[n+1];
int min[n+1];
for(i=1;i<=n;i++)
{
scanf("%d",&(v[i].num));
v[i].pos=i;
}
shell(v,n);
k=v[1].pos;
min[v[1].pos]=-1;
for(i=2;i<=n;i++)
{
if(k>=v[i].pos){
min[v[i].pos]=k-(v[i].pos)-1;
}else{
min[v[i].pos]=-1;
k=v[i].pos;
}
}
for(i=1;i<=n;i++)
{
printf("%d ",min[i]);
}
return 0;
}
void shell(c *v,int n)
{
int salto,a,i;
c aux;
salto=n/2;
while(salto>=1){
i=1;
a=0;
while(salto+i<=n)
{
if((v[i].num)>(v[salto+i].num))
{
aux.num=v[salto+i].num;
aux.pos=v[salto+i].pos;
v[salto+i].num=v[i].num;
v[salto+i].pos=v[i].pos;
v[i].num=aux.num;
v[i].pos=aux.pos;
a=1;
}
else if((v[i].num)==(v[salto+i].num) && (v[i].pos)>(v[salto+i].pos)){
aux.num=v[salto+i].num;
aux.pos=v[salto+i].pos;
v[salto+i].num=v[i].num;
v[salto+i].pos=v[i].pos;
v[i].num=aux.num;
v[i].pos=aux.pos;
a=1;
}
i++;
}
if(a==0){
salto=salto/2;
}
}
}
| |
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | 2799dffa61c912e7cbfed275ec24ba83 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | #include <stdio.h>
int main() {
int n ,i, izq, der, med ;
scanf("%d", &n);
int edadMorsas[n], menorEdad[n];
for(i = 0; i < n; i++) {
scanf("%d", &edadMorsas[i]);
}
menorEdad[n-1] = edadMorsas[n-1];
for(i = n - 2; i >= 0; i--){
if(edadMorsas[i] < menorEdad[i+1]){
menorEdad[i] = edadMorsas[i];
}else{
menorEdad[i] = menorEdad[i+1];
}
}
for(i = 0; i < n - 1; i++) {
if(menorEdad[i+1] < edadMorsas[i]) {
izq = i + 1;
der = n - 1;
while(izq < der-1) {
med = (izq+der)/2;
if(menorEdad[med] < edadMorsas[i]) {
izq = med;
} else {
der = med;
}
}
if(menorEdad[der] < edadMorsas[i]){
izq = der;
}
printf("%d ", izq - i - 1);
} else {
printf("-1 ");
}
}
printf("-1");
return 0;
}
| |
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | 07f5f097df085750681e97d8fe7fda93 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | #include <stdio.h>
#include <stdlib.h>
struct Nodo{
int valor;
int ind;
struct Nodo* sig;
};
typedef struct Nodo nodo;
int main(){
int n,h,i,j;
nodo* menor=malloc(sizeof(nodo));
nodo* aux;
scanf("%d",&n);
int l[n];
int v[n];
for(i=0;i<n;i++){
scanf("%d",&v[i]);
}
menor->sig=NULL;
menor->ind=n-1;
menor->valor=v[n-1];
for(i=n-1;i>=0;i--){
if(v[i]>menor->valor){
aux=menor;
while(aux!=NULL && v[i]>aux->valor){
l[i]=aux->ind-i-1;
aux=aux->sig;
}
}else{
l[i]=-1;
if(v[i]<menor->valor){
aux=malloc(sizeof(nodo));
aux->ind=i;
aux->sig=menor;
aux->valor=v[i];
menor=aux;
}
}
}
for(i=0;i<n;i++){
printf("%d ",l[i]);
}
}
| |
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | 672a791a1e468d8ad7557b8282186a72 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | #include <stdio.h>
#define MIN(a, b) ((a) < (b) ? (a) : (b))
struct segment_tree {
int left;
int right;
int minimum;
};
struct segment_tree t[300000];
int a[100000];
void init(int root, int l, int r) {
int mid;
t[root].left = l;
t[root].right = r;
mid = (l + r) >> 1;
if (l == r) {
t[root].minimum = a[l];
return;
}
init((root << 1) + 1, l, mid);
init((root << 1) + 2, mid + 1, r);
t[root].minimum = MIN(t[(root << 1) + 1].minimum, t[(root << 1) + 2].minimum);
}
int search(int d, int root) {
int ret;
if (t[root].right <= d) {
return -1;
}
if (t[root].minimum >= a[d]) {
return -1;
}
if (t[root].left == t[root].right) {
return t[root].left;
}
if (t[(root << 1) + 2].minimum < a[d]) {
ret = search(d, (root << 1) + 2);
}
else {
ret = search(d, (root << 1) + 1);
}
return ret;
}
void func(int n) {
int i, p;
init(0, 0, n - 1);
for (i = 0; i < n; i ++) {
p = search(i, 0);
if (p == -1) {
printf("-1");
}
else {
printf("%d", p - i - 1);
}
if (i == n - 1) {
printf("\n");
}
else {
printf(" ");
}
}
}
int main() {
int n, i;
while (scanf("%d", &n) == 1) {
for (i = 0; i < n; i ++) {
scanf("%d", &a[i]);
}
func(n);
}
return 0;
} | |
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | 7d5238b31d41fb5f4c792da0489040dd | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | // Queue
#include <stdio.h>
#include <stdlib.h>
#define MAX(a, b) ((a) > (b) ? (a) : (b))
struct Pair
{
int age;
int index;
}p[100001];
int maxs[100001];
int ans[100001];
int cmp(const void *a, const void *b)
{
return ((struct Pair *)a)->age - ((struct Pair *)b)->age;
}
void deal(int n)
{
int i, j, l, r, m;
qsort(p, n, sizeof(struct Pair), cmp);
maxs[0] = p[0].index;
for (i = 1; i < n; i++)
{
maxs[i] = MAX(p[i].index, maxs[i - 1]);
}
ans[p[0].index] = -1;
for (i = 1; i < n; i++)
{
l = 0;
r = i - 1;
j = -1;
while (l <= r)
{
m = (l + r) >> 1;
if (p[m].age == p[i].age)
{
r = m - 1;
}
else
{
j = m;
l = m + 1;
}
}
if (j == -1)
{
ans[p[i].index] = -1;
}
else
{
if (maxs[j] > p[i].index)
{
ans[p[i].index] = maxs[j] - p[i].index - 1;
}
else
{
ans[p[i].index] = -1;
}
}
}
for (i = 0; i < n - 1; i++)
{
printf("%d ", ans[i]);
}
printf("%d\n", ans[i]);
}
int main(int argc, char **argv)
{
int i, n;
while (scanf("%d", &n) == 1)
{
for (i = 0; i < n; i++)
{
scanf("%d", &p[i].age);
p[i].index = i;
}
deal(n);
}
return 0;
} | |
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | b3c599347f2895f84bb1a67fcd98fc32 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | #include<stdio.h>
#include<stdlib.h>
typedef struct morsasNoMolestas{
long int edad;
long int pos;
struct morsasNoMolestas *sig;
}MorsasNoMolestas;
long int distancia(long int r, MorsasNoMolestas menor);
void agregar( MorsasNoMolestas **ptr, long int edad, long int indice);
MorsasNoMolestas primero(MorsasNoMolestas *lista);
MorsasNoMolestas ultimoMenor(MorsasNoMolestas* lista, long int morsa);
int main(){
long int cant, i,d;
MorsasNoMolestas *menorCab=NULL, *ptr=NULL;
scanf("%d", &cant);
long int morsas[cant];
long int respuesta[cant];
MorsasNoMolestas cab;
for( i=0 ; i<cant ; i++){
scanf("%d", &morsas[i]);
}
agregar(&menorCab, morsas[cant-1], cant-1);
respuesta[cant-1]=-1;
for(i =cant-2 ; i>=0; i--){
if(morsas[i]> menorCab->edad){
ptr=menorCab;
while(ptr != NULL && morsas[i]>ptr->edad ){
respuesta[i] = ptr->pos - i -1;
ptr = ptr->sig;
}
}else {
respuesta[i]=-1;
if(morsas[i] < menorCab->edad)
agregar(&menorCab, morsas[i], i);
}
}
for( i= 0; i < cant ; i++)
printf("%d ",respuesta[i]);
return 0;
}
void agregar( MorsasNoMolestas **ptr, long int edad, long int indice){
MorsasNoMolestas *nuevo;
nuevo = malloc(sizeof(MorsasNoMolestas));
if( nuevo == NULL){
puts("Memoria insuficiente");
return;
}
nuevo->edad = edad;
nuevo->pos=indice;
nuevo->sig = *ptr;
*ptr = nuevo;
}
| |
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | 44208c6f932c1dd71bcc72cdcf5b230b | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | #include<stdio.h>
#include<stdlib.h>
typedef struct morsasNoMolestas{
long int edad;
long int pos;
struct morsasNoMolestas *sig;
}MorsasNoMolestas;
long int distancia(long int r, MorsasNoMolestas menor);
void agregar( MorsasNoMolestas **ptr, long int edad, long int indice);
MorsasNoMolestas primero(MorsasNoMolestas *lista);
MorsasNoMolestas ultimoMenor(MorsasNoMolestas* lista, long int morsa);
int main(){
long int cant, i,d;
MorsasNoMolestas *menorCab=NULL, *ptr=NULL;
scanf("%d", &cant);
long int morsas[cant];
long int respuesta[cant];
MorsasNoMolestas cab;
for( i=0 ; i<cant ; i++){
scanf("%d", &morsas[i]);
}
agregar(&menorCab, morsas[cant-1], cant-1);
respuesta[cant-1]=-1;
for(i =cant-2 ; i>=0; i--){
if(morsas[i]> menorCab->edad){
ptr=menorCab;
while(ptr != NULL && morsas[i]>ptr->edad ){
respuesta[i] = ptr->pos - i -1;
ptr = ptr->sig;
}
}else {
respuesta[i]=-1;
if(morsas[i] < menorCab->edad)//no mete si son dos iguales
agregar(&menorCab, morsas[i], i);
}
}
for( i= 0; i < cant ; i++)
printf("%d ",respuesta[i]);
return 0;
}
void agregar( MorsasNoMolestas **ptr, long int edad, long int indice){
MorsasNoMolestas *nuevo;
nuevo = malloc(sizeof(MorsasNoMolestas));
if( nuevo == NULL){
puts("Memoria insuficiente");
return;
}
nuevo->edad = edad;
nuevo->pos=indice;
nuevo->sig = *ptr;
*ptr = nuevo;
}
/*void agregar( MorsasNoMolestas **ptrS, long int edad, long int indice){
//crea variables para almacenar los elementos en la lista
MorsasNoMolestas *ptrNuevo;
MorsasNoMolestas *ptrActual;
MorsasNoMolestas *ptrAnterior;
//reservo memoria
ptrNuevo = malloc(sizeof(MorsasNoMolestas));
//si se creo
if ( ptrNuevo != NULL) {
//coloco la informacion en el MorsasNoMolestas
ptrNuevo->edad = edad;
ptrNuevo->pos=indice;
ptrNuevo->sig = NULL;
//asigno los MorsasNoMolestass, anterior no apunta a nada y actual es el primer MorsasNoMolestas
ptrAnterior = NULL;
ptrActual = *ptrS;
//ciclo para encontrar la posicion correcta
while( ptrActual != NULL && edad > ptrActual->edad){
ptrAnterior = ptrActual;
ptrActual = ptrActual->sig;
}
if ( ptrAnterior == NULL){//se inserta el primer MorsasNoMolestas o en el primer MorsasNoMolestas
ptrNuevo->sig = *ptrS;
*ptrS= ptrNuevo;
}else{
ptrAnterior->sig = ptrNuevo;
ptrNuevo->sig = ptrActual;
}
}
}
*/
| |
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | 0da25c14a8b4d33d3f8b290858ebaf60 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | #include<stdio.h>
#include<stdlib.h>
typedef struct morsasNoMolestas{
long int edad;
long int pos;
struct morsasNoMolestas *sig;
}MorsasNoMolestas;
long int distancia(long int r, MorsasNoMolestas menor);
void agregar( MorsasNoMolestas **ptr, long int edad, long int indice);
MorsasNoMolestas primero(MorsasNoMolestas *lista);
MorsasNoMolestas ultimoMenor(MorsasNoMolestas* lista, long int morsa);
int main(){
long int cant, i,d;
MorsasNoMolestas *menorCab=NULL, *ptr=NULL;
scanf("%d", &cant);
long int morsas[cant];
long int respuesta[cant];
MorsasNoMolestas cab;
for( i=0 ; i<cant ; i++){
scanf("%d", &morsas[i]);
}
agregar(&menorCab, morsas[cant-1], cant-1);
respuesta[cant-1]=-1;
for(i =cant-2 ; i>=0; i--){
if(morsas[i]> menorCab->edad){
ptr=menorCab;
while(ptr != NULL && morsas[i]>ptr->edad ){
respuesta[i] = ptr->pos - i -1;
ptr = ptr->sig;
}
}else {
respuesta[i]=-1;
if(morsas[i] < menorCab->edad)//no mete si son dos iguales
agregar(&menorCab, morsas[i], i);
}
}
for( i= 0; i < cant ; i++)
printf("%d ",respuesta[i]);
return 0;
}
/*void agregar( MorsasNoMolestas **ptr, long int edad, long int indice){
MorsasNoMolestas *nuevo;
nuevo = malloc(sizeof(MorsasNoMolestas));
if( nuevo == NULL){
puts("Memoria insuficiente");
return;
}
nuevo->edad = edad;
nuevo->pos=indice;
nuevo->sig = *ptr;
*ptr = nuevo;
}*/
void agregar( MorsasNoMolestas **ptrS, long int edad, long int indice){
//crea variables para almacenar los elementos en la lista
MorsasNoMolestas *ptrNuevo;
MorsasNoMolestas *ptrActual;
MorsasNoMolestas *ptrAnterior;
//reservo memoria
ptrNuevo = malloc(sizeof(MorsasNoMolestas));
//si se creo
if ( ptrNuevo != NULL) {
//coloco la informacion en el MorsasNoMolestas
ptrNuevo->edad = edad;
ptrNuevo->pos=indice;
ptrNuevo->sig = NULL;
//asigno los MorsasNoMolestass, anterior no apunta a nada y actual es el primer MorsasNoMolestas
ptrAnterior = NULL;
ptrActual = *ptrS;
//ciclo para encontrar la posicion correcta
while( ptrActual != NULL && edad > ptrActual->edad){
ptrAnterior = ptrActual;
ptrActual = ptrActual->sig;
}
if ( ptrAnterior == NULL){//se inserta el primer MorsasNoMolestas o en el primer MorsasNoMolestas
ptrNuevo->sig = *ptrS;
*ptrS= ptrNuevo;
}else{
ptrAnterior->sig = ptrNuevo;
ptrNuevo->sig = ptrActual;
}
}
}
| |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | 1a524230539e0f4e1b2f3bf9f048698f | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | #include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m,i,a,sum=0;
scanf("%d",&n);
scanf("%d",&m);
for(i=0;i<n;i++)
{
scanf("%d",&a);
sum+=a;
}
if(sum>m)
printf("%d\n",m);
else
printf("%d\n",sum);
}
return 0;
} | |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | 665690af413220e5087288c31b1d32fd | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | #include <stdio.h>
int main()
{
int t;
scanf("%d",&t);
for(int i=0;i<t;i++)
{
int n,m;
scanf("%d%d",&n,&m);
int arr[n];
for(int j=0;j<n;j++)
{
scanf("%d",&arr[j]);
}
int sum=0;
for(int k=0;k<n;k++)
{
sum+=arr[k];
}
if(sum>=m)
{
printf("%d\n",m);
}
else if(sum<m)
{
printf("%d\n",sum);
}
}
return 0;
}
| |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | eec9561e81620908cd09330ab9fcabc7 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | #include<stdio.h>
void solve();
int main()
{ int t;
scanf("%d", &t);
for(int k=0; k<t; k++){
solve();
}
return 0;
}
void solve (){
int n, total=0, possible, scored, cache, allot;
scanf("%d%d", &n, &possible);
int a[n];
for(int j=0; j<n; j++){
scanf("%d", &a[j]);
total= total+ a[j];
}
scored= a[0];
if(possible > total){
allot= total;
}else{
allot = possible;
}
printf("%d \n", allot);
} | |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | c963e4c6a5ba68ec67b6662ae04de7a0 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | #include<stdio.h>
int main(void)
{
int t;
//while (t >= 1 && t <=200)
// {
scanf("%d", &t);
int n, m;
while (t--)
{
scanf("%d", &n);
scanf("%d", &m);
int score[n];
int s = 0;
for (int i = 0; i < n; i++)
{
scanf("%d", &score[i]);
s += score[i];
}
if (s >= m){
printf("%d\n", m);
} else printf("%d\n", s);
}
// }
}
| |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | 46b2da184cc865c7f958473f74953eec | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | #include <stdio.h>
int main()
{
int t,n,m,a[100000],b[100000];
scanf("%d",&t);
for(int j=0;j<t;j++)
{
int s=0;
scanf("%d%d",&n,&m);
for (int i=0;i<n;i++)
{
scanf("%d",&a[i]);
s=s+a[i];
}
if(s<=m)
{b[j]=s;}
else
{
b[j]=m;
}
}
for(int j=0;j<t;j++)
{printf("%d\n",b[j]);
}
return 0;
}
| |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | 4c6bc197ac24c5fbf875f6fd973d62c0 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | #include<stdio.h>
int main(){
int t,a,b,i;
scanf("%d",&t);
while(t--){
int s=0;
scanf("%d%d",&a,&b);
int k[a];
for(i=0;i<a;i++){
scanf("%d",&k[i]);
}
for(i=0;i<a;i++){
s=s+k[i];
}
if(s<b){
printf("%d\n",s);
}
else{
printf("%d\n",b);
}
}
}
| |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | c1dbddfea0beb33c16e9e743f62dc550 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | #include<stdio.h>
#include<stdlib.h>
int main()
{
int n,m,i,t,j;
scanf("%d",&t);
for(j=0;j<t;j++)
{
scanf("%d%d",&n,&m);
int a[n];
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=1;i<n;i++)
{
a[0]+=a[i];
}
if(a[0]>=m)
{
printf("%d\n",m);
}
else
{
printf("%d\n",a[0]);
}
}
}
| |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | 32b15c92dcd0ec6d5cd9c928371177f6 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | #include<stdio.h>
int main()
{
int t,q,i,n,m;
scanf("%d", &t);
for(q=0;q<t;q++){
scanf("%d%d", &n, &m);
int a[n];
int sum=0;
for(i=0;i<n;i++){
scanf("%d", &a[i]);
sum=sum+a[i];
}
if(sum<m){
printf("%d\n", sum);
}
else{
printf("%d\n", m);
}
}
return 0;
}
| |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | c3b862b73fbbde2c568f8c544091aed2 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | #include <stdio.h>
int main()
{
long long int i,j,m,n,t,high,sum;
//double avg;
scanf("%lld", &t);
for(i=0;i<t;i++){
sum=0;
scanf("%lld%lld", &n,&high);
int a[n];
for(j=0;j<n;j++){
scanf("%lld", &a[j]);
sum+=a[j];
}
if(sum<=high)printf("%lld\n", sum);
else printf("%lld\n", high);
}
return 0;
}
| |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | fba1550a0fe305ef96fbf84cea496191 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | #include <stdio.h>
int main(){
int t;
scanf("%d", &t);
int n,m, soma=0, soma100eu=0, eu=0;
for(int testes=0; testes<t; testes++){
scanf("%d %d", &n, &m);
int notas[n+1];
soma = 0;
for(int i=0; i<n; i++){
scanf("%d", ¬as[i]);
soma += notas[i];
}
if(soma < m)
printf("%d\n",soma);
else
printf("%d\n", m);
}
return 0;
}
| |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | e2398c87d698654fd995452716e4566f | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | #include<stdio.h>
#include<string.h>
#define N 10000
int main()
{
int n,t,m,a[N]={0},i,j,sum=0;
scanf("%d",&t);
while(t--)
{
sum=0;
memset(a,0,sizeof(a));
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
if(sum==0)
{
printf("0\n");
continue;
}
for(j=m;j>=1;j--)
{
if(sum>=j)
{
printf("%d\n",j);
break;
}
}
}
}
| |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | a3ae2230a522a04cc60cb59a6f9b5140 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | #include<stdio.h>
void main()
{
int t=0,m=0,n=0,temp=0;
scanf("\n%d",&t);
while(t>0)
{
--t;
scanf("\n%d %d",&n,&m);
int a[n];
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
if(a[0]==m)
{ //printf("%d",m);
//return m;
}
else{
for(int i=1;i<n;i++)
{
temp=m-a[0];
if(a[i]==temp)
{
a[0]+=temp;
//printf("%d",m);
break;
//return m;
}
else
if(a[i]<temp)
{ a[0]+=a[i];
a[i]=0;
}
else
{
a[i]-=temp;
a[0]+=temp;
break;
}
}
}
//return a[0];
printf("\n%d",a[0]);
}
}
| |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | 7f7f3a08967c26be076f84f1f29bd831 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | #include <stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m,k=0,c=0;
scanf("%d%d",&n,&m);
int a[n],i;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
k=k+a[i];
if(a[i]==0)
c++;
}
//printf(" %d %d",k,c);
int max=a[0] ;
for(i=0;i<n;i++)
{ if(a[i]>max)
max=a[i];
}
if((c==n-1)||(c==n))
printf("%d \n",max);
else
{
float x=(float)k/n;
float y=(float)m/n;
if((x==y)||(x>y))
printf("%d\n",m);
else if(y>x)
printf("%d\n",k);
}
}
return 0;
} | |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | e3d188bb0826aabfa2aa88b06963b072 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | #include <stdio.h>
int main()
{
int a,b,i;
scanf("%d\n",&a);
for(i=a;i!=0;i--)
{int c,d,sum=0;
scanf("%d%d",&c,&d);
int j;
int s;
for(j=0;j<c;j++)
{
scanf("%d",&s);
sum=sum+s;
}
if(sum<d)
{
printf("%d\n",sum);
}else
{
printf("%d\n",d);
}
}
return 0;
} | |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | 60129850f2191e45f82dfb1e4bc1b8a4 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | #include<stdio.h>
int main()
{
int t,a[1000],n,i,h,sum,c=1;
scanf("%d",&t);
for(c=1; c<=t; c++)
{
scanf("%d %d",&n,&h);
for(i=1,sum=0; i<=n; i++)
{
scanf("%d",&a[i]);
sum=sum+a[i];
}
if(sum>=h)
{
printf("%d\n",h);
}
else
{
printf("%d\n",sum);
}
}
return 0;
}
| |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | aadf8b302472d62dba91d11d95813896 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | #include <stdio.h>
int main(){
int t, n, m, notas, total;
scanf("%d", &t);
total = 0;
for(int i = 0; i < t; ++i){
scanf("%d%d", &n, &m);
total = 0;
for(int u = 0; u < n; ++u){
scanf("%d", ¬as);
total += notas;
}
if(total >= m)
printf("%d\n", m);
else
printf("%d\n", total);
}
printf("\n");
return 0;
} | |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | e8c3fc7694a6a1890d0d3f078a7e5902 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | #include <stdio.h>
#include <string.h>
int main(){
int t, n, m, result, media, total, nota;
scanf("%d", &t);
media = 0;
result = 0;
total = 0;
for(int i = 0; i < t; ++i){
scanf("%d %d", &n, &m);
total = 0;
for(int u = 0; u < n; ++u){
scanf("%d", ¬a);
total += nota;
}
if(total >= m)
printf("%d\n", m);
else
printf("%d\n", total);
}
printf("\n");
return 0;
} | |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | 43dc0e0cab2d4d9d9c54b9c7e8a77548 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int t;
scanf("%d", &t);
for (int i = 0; i < t; i++)
{
int n, m;
scanf("%d%d", &n, &m);
int *arr = (int *)malloc(n * (sizeof(int)));
int sum = 0;
for (int j = 0; j < n; j++)
{
scanf("%d", &arr[j]);
sum += arr[j];
}
int score = arr[0];
float average = sum / n;
float new_average = sum;
int rem_sum = sum - score;
int temp = score;
while (temp <= m && rem_sum>=0)
{
new_average = (temp + rem_sum) / n;
if (new_average == average)
score = temp;
temp++;
rem_sum--;
}
printf("%d\n", score);
}
} | |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | 21d6b64b704bf21e13b137ecbe30724d | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | #include <stdio.h>
#define LL long long
LL int a,b,c,t;
LL int d;
int main(void)
{
scanf("%d",&a);
for(int i=0;i<a;i++)
{
c=0;
t=0;
scanf("%d %d",&b,&c);
for(int j=0;j<b;j++)
{
scanf("%d",&d);
t+=d;
}
if(t>c)
printf("%d\n",c);
else
printf("%d\n",t);
}
} | |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | 9df091ec2b72b1a6ec6e65b57c4f5970 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | int main()
{
int t=0;
scanf("%d",&t);
while(t--)
{
int n,m,s=0;
scanf("%d %d",&n,&m);
int a[n];
for(int i =0; i<n; i++)
{
scanf("%d ",&a[i]);
s=s+a[i];
}
if(s>=m)
printf("%d\n",m);
else
printf("%d\n",s);
}
return 0;
} | |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | dfff8975bc89a1c80ce2a487c8afbd22 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | #include<stdio.h>
main(){
int t,n,m,res,x;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
res=0;
while(n--){
scanf("%d",&x);
res+=x;
}
if(res>=m){
printf("%d\n",m);
}
else{
printf("%d\n",res);
}
}
}
| |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | 58a3cdbdb42d75fc171f63aee6de34da | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | #include<stdio.h>
#include<stdlib.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m,i,s=0;
scanf("%d %d",&n,&m);
int a[n+1];
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
s+=a[i];
}
if(m>s)
{
printf("%d\n",s);
}
else
{
printf("%d\n",m);
}}
return 0;
}
| |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | c18321a8d7bcc14d391d64e30c59a750 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | #include<stdio.h>
int main(void){
long long int n,t,m,a[1000],j,s=0,i;
scanf("%lld", &t);
for(i=0;i<t;i++){
s=0;
scanf("%lld %lld", &n,&m);
for(j=0;j<n;j++){
scanf("%lld", &a[i]);
s=s+a[i];
}
if(s<=m){
printf("%lld\n",s);}
else{
printf("%lld\n",m);}
}}
| |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | c117214e528f1d8514b7aaa6b7bb4a93 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | #include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t>0)
{
int n,m;
scanf("%d%d",&n,&m);
int a[n],i,s=0;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
s=s+a[i];
}
float avg=s/n;
if(s<=m)
{
printf("%d\n",s);
}
else
{
printf("%d\n",m);
}
t--;
}
return 0;
} | |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | 371c7db0cfd601b97bbf835161f9a9fe | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | #include <stdio.h>
#define ll long long
int main()
{
ll int t,n,m,i,j;
scanf("%lld",&t);
while(t--)
{
int x,s=0;
scanf("%lld %lld",&n,&m);
for(i=0;i<n;i++)
{
scanf("%d",&x);
s+=x;
}
j=(s<m)?s:m;
printf("%lld\n",j);
}
return 0;
}
| |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | 17b385005cd2ac7fee2a5f17f72c3f8a | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | #include<stdio.h>
#include<stdlib.h>
int main()
{
int *a,i,n,max,t;
scanf("%d",&t);
while(t--)
{
scanf("%d %d",&n,&max);
a=(int *)malloc(n*sizeof(int));
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
if(a[0]==max)
{
printf("%d\n",max);
}
else
{
for(i=1;i<n;i++)
{
a[0]=a[0]+a[i];
a[i]=0;
if(a[0]>=max)
{
printf("%d\n",max);
break ;
}
}
if(i==n)
printf("%d\n",a[0]);
}
}
return 0;
}
| |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | 822410e478453f38f598d22237a7565b | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | #include<stdio.h>
#include<math.h>
int main()
{
int t,n,m,i,j,a[1000],h,sum,b;
scanf("%d",&t);
for(i=0;i<t;i++)
{
sum=0;
scanf("%d %d",&n,&m);
for(j=0;j<n;j++)
{
scanf("%d",&a[j]);
}
for(j=0;j<n;j++)
{
sum=sum+a[j];
}
if(sum>=m)
printf("%d\n",m);
if(sum<m)
printf("%d\n",sum);
}
return 0;
} | |
$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied: All scores are integers $$$0 \leq a_{i} \leq m$$$ The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied. | For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._ | C | 7c2a61de728e6767b25e58c74497bbae | f430c48bbcc0c57b5b234f9a3347b7da | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1583332500 | ["2\n4 10\n1 2 3 4\n4 5\n1 2 3 4"] | NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$) — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$) — scores of the students. | ["10\n5"] | #include <stdio.h>
int high;
int max_of_arr(int A[],int siz){
high =A[0];
int i = 1;
while(i<siz){
if (A[i]>high ){
high = A[i];
}
i++;
}
return high;
}
void main(){
// total test cases t
int t;
scanf("%d",&t);
// number of students ie araray size
int siz;
int arr[siz];
//max marks
int max;
int avg;
int sum; // sum of scores
while(t>0){
t--;
sum = 0;
scanf("%d %d",&siz,&max);
int arr[siz];
for (int i=0;i<siz;i++){
scanf("%d",&arr[i]);
sum+=arr[i];
}
// code logic
if (siz==1){
if(arr[0]==0){
printf("%d\n",0);
}
else if(arr[0]<=max){
printf("%d\n",arr[0]);
}
}
else if (sum >= max){
printf("%d\n",max);
}
else if(sum < max){
printf("%d\n",sum);
}
}
}
| |
Ziota found a video game called "Monster Invaders".Similar to every other shooting RPG game, "Monster Invaders" involves killing monsters and bosses with guns.For the sake of simplicity, we only consider two different types of monsters and three different types of guns.Namely, the two types of monsters are: a normal monster with $$$1$$$ hp. a boss with $$$2$$$ hp. And the three types of guns are: Pistol, deals $$$1$$$ hp in damage to one monster, $$$r_1$$$ reloading time Laser gun, deals $$$1$$$ hp in damage to all the monsters in the current level (including the boss), $$$r_2$$$ reloading time AWP, instantly kills any monster, $$$r_3$$$ reloading time The guns are initially not loaded, and the Ziota can only reload 1 gun at a time.The levels of the game can be considered as an array $$$a_1, a_2, \ldots, a_n$$$, in which the $$$i$$$-th stage has $$$a_i$$$ normal monsters and 1 boss. Due to the nature of the game, Ziota cannot use the Pistol (the first type of gun) or AWP (the third type of gun) to shoot the boss before killing all of the $$$a_i$$$ normal monsters.If Ziota damages the boss but does not kill it immediately, he is forced to move out of the current level to an arbitrary adjacent level (adjacent levels of level $$$i$$$ $$$(1 < i < n)$$$ are levels $$$i - 1$$$ and $$$i + 1$$$, the only adjacent level of level $$$1$$$ is level $$$2$$$, the only adjacent level of level $$$n$$$ is level $$$n - 1$$$). Ziota can also choose to move to an adjacent level at any time. Each move between adjacent levels are managed by portals with $$$d$$$ teleportation time.In order not to disrupt the space-time continuum within the game, it is strictly forbidden to reload or shoot monsters during teleportation. Ziota starts the game at level 1. The objective of the game is rather simple, to kill all the bosses in all the levels. He is curious about the minimum time to finish the game (assuming it takes no time to shoot the monsters with a loaded gun and Ziota has infinite ammo on all the three guns). Please help him find this value. | Print one integer, the minimum time to finish the game. | C | b532deda90a4edc6e97b207cb05d3843 | 5c4b7eeebcbe654aafe7720fa4d79faa | GNU C11 | standard output | 512 megabytes | train_002.jsonl | [
"dp",
"implementation",
"greedy"
] | 1598798100 | ["4 1 3 4 3\n3 2 5 1", "4 2 4 4 1\n4 5 1 2"] | NoteIn the first test case, the optimal strategy is: Use the pistol to kill three normal monsters and AWP to kill the boss (Total time $$$1\cdot3+4=7$$$) Move to stage two (Total time $$$7+3=10$$$) Use the pistol twice and AWP to kill the boss (Total time $$$10+1\cdot2+4=16$$$) Move to stage three (Total time $$$16+3=19$$$) Use the laser gun and forced to move to either stage four or two, here we move to stage four (Total time $$$19+3+3=25$$$) Use the pistol once, use AWP to kill the boss (Total time $$$25+1\cdot1+4=30$$$) Move back to stage three (Total time $$$30+3=33$$$) Kill the boss at stage three with the pistol (Total time $$$33+1=34$$$) Note that here, we do not finish at level $$$n$$$, but when all the bosses are killed. | PASSED | 2,300 | standard input | 2 seconds | The first line of the input contains five integers separated by single spaces: $$$n$$$ $$$(2 \le n \le 10^6)$$$ — the number of stages, $$$r_1, r_2, r_3$$$ $$$(1 \le r_1 \le r_2 \le r_3 \le 10^9)$$$ — the reload time of the three guns respectively, $$$d$$$ $$$(1 \le d \le 10^9)$$$ — the time of moving between adjacent levels. The second line of the input contains $$$n$$$ integers separated by single spaces $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^6, 1 \le i \le n)$$$. | ["34", "31"] | #include <stdio.h>
#define N 1000000
long long min(long long a, long long b) { return a < b ? a : b; }
int main() {
static long long tt1[N], tt2[N], dp[N], dq[N];
int n, r1, r2, r3, d, i;
long long ans;
scanf("%d%d%d%d%d", &n, &r1, &r2, &r3, &d);
for (i = 0; i < n; i++) {
int a;
scanf("%d", &a);
tt1[i] = (long long) a * r1 + r3;
tt2[i] = min(tt1[i], min(r2 + r1, (long long) (a + 2) * r1));
}
dp[0] = min(tt1[0], tt2[0] + d * 2);
for (i = 1; i < n; i++)
dp[i] = min(dp[i - 1] + tt1[i], (i < 2 ? 0 : dp[i - 2]) + tt2[i - 1] + tt2[i] + d * 2);
dq[n - 1] = min(tt1[n - 1], tt2[n - 1] + d * 2);
for (i = n - 2; i >= 0; i--)
dq[i] = dq[i + 1] + tt2[i] + d;
ans = dp[n - 1];
for (i = 0; i < n; i++)
ans = min(ans, (i == 0 ? 0 : dp[i - 1]) + dq[i]);
ans += (long long) (n - 1) * d;
printf("%lld\n", ans);
return 0;
}
| |
Okabe and Super Hacker Daru are stacking and removing boxes. There are n boxes numbered from 1 to n. Initially there are no boxes on the stack.Okabe, being a control freak, gives Daru 2n commands: n of which are to add a box to the top of the stack, and n of which are to remove a box from the top of the stack and throw it in the trash. Okabe wants Daru to throw away the boxes in the order from 1 to n. Of course, this means that it might be impossible for Daru to perform some of Okabe's remove commands, because the required box is not on the top of the stack.That's why Daru can decide to wait until Okabe looks away and then reorder the boxes in the stack in any way he wants. He can do it at any point of time between Okabe's commands, but he can't add or remove boxes while he does it.Tell Daru the minimum number of times he needs to reorder the boxes so that he can successfully complete all of Okabe's commands. It is guaranteed that every box is added before it is required to be removed. | Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands. | C | 2535fc09ce74b829c26e1ebfc1ee17c6 | 209eb33a7dfbab10e524dfc6ecffb4ad | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"greedy",
"trees"
] | 1498401300 | ["3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove", "7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove"] | NoteIn the first sample, Daru should reorder the boxes after adding box 3 to the stack.In the second sample, Daru should reorder the boxes after adding box 4 and box 7 to the stack. | PASSED | 1,500 | standard input | 3 seconds | The first line of input contains the integer n (1 ≤ n ≤ 3·105) — the number of boxes. Each of the next 2n lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer x (1 ≤ x ≤ n) follows, indicating that Daru should add the box with number x to the top of the stack. It is guaranteed that exactly n lines contain "add" operations, all the boxes added are distinct, and n lines contain "remove" operations. It is also guaranteed that a box is always added before it is required to be removed. | ["1", "2"] | #include<stdio.h>
main()
{
int n,i,num,p=0,stack[300000], top=-1, count=0;
scanf("%d",&n);
char arr[10];
for(i=0;i<2*n;i++)
{
scanf("%s",arr);
if(arr[0]=='a')
{
scanf("%d", &num);
stack[++top]=num;
}
else if(arr[0]=='r')
{
p++;
if(top!=-1)
{
if(stack[top]==p)
top--;
else
{
count++;
top=-1;
}
}
}
}
printf("%d", count);
return 0;
} | |
Okabe and Super Hacker Daru are stacking and removing boxes. There are n boxes numbered from 1 to n. Initially there are no boxes on the stack.Okabe, being a control freak, gives Daru 2n commands: n of which are to add a box to the top of the stack, and n of which are to remove a box from the top of the stack and throw it in the trash. Okabe wants Daru to throw away the boxes in the order from 1 to n. Of course, this means that it might be impossible for Daru to perform some of Okabe's remove commands, because the required box is not on the top of the stack.That's why Daru can decide to wait until Okabe looks away and then reorder the boxes in the stack in any way he wants. He can do it at any point of time between Okabe's commands, but he can't add or remove boxes while he does it.Tell Daru the minimum number of times he needs to reorder the boxes so that he can successfully complete all of Okabe's commands. It is guaranteed that every box is added before it is required to be removed. | Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands. | C | 2535fc09ce74b829c26e1ebfc1ee17c6 | 731d580dbd55c519516ab342838a3230 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"greedy",
"trees"
] | 1498401300 | ["3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove", "7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove"] | NoteIn the first sample, Daru should reorder the boxes after adding box 3 to the stack.In the second sample, Daru should reorder the boxes after adding box 4 and box 7 to the stack. | PASSED | 1,500 | standard input | 3 seconds | The first line of input contains the integer n (1 ≤ n ≤ 3·105) — the number of boxes. Each of the next 2n lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer x (1 ≤ x ≤ n) follows, indicating that Daru should add the box with number x to the top of the stack. It is guaranteed that exactly n lines contain "add" operations, all the boxes added are distinct, and n lines contain "remove" operations. It is also guaranteed that a box is always added before it is required to be removed. | ["1", "2"] | #include<stdio.h>
#define MAX 300003
void push(int value);
void pop();
struct stack
{
int stk[MAX];
int top;
}stack;
void push(int value)
{
stack.top+=1;
stack.stk[stack.top]=value;
}
void pop()
{
stack.top-=1;
}
int main()
{
int n,i,num,count=1,ans=0;
char s[10];
stack.top=-1;
scanf("%d",&n);
for(i=0;i<2*n;i++)
{
scanf("%s",s);
if(s[0]=='a')
{
scanf("%d",&num);
push(num);
}
else if(s[0]=='r')
{
if(stack.stk[stack.top]==count && stack.top!=-1)
pop();
else if(stack.top==-1);
else
{
ans++;
while(stack.top!=-1)
pop();
}
count++;
}
}
printf("%d\n",ans);
return 0;
}
| |
Okabe and Super Hacker Daru are stacking and removing boxes. There are n boxes numbered from 1 to n. Initially there are no boxes on the stack.Okabe, being a control freak, gives Daru 2n commands: n of which are to add a box to the top of the stack, and n of which are to remove a box from the top of the stack and throw it in the trash. Okabe wants Daru to throw away the boxes in the order from 1 to n. Of course, this means that it might be impossible for Daru to perform some of Okabe's remove commands, because the required box is not on the top of the stack.That's why Daru can decide to wait until Okabe looks away and then reorder the boxes in the stack in any way he wants. He can do it at any point of time between Okabe's commands, but he can't add or remove boxes while he does it.Tell Daru the minimum number of times he needs to reorder the boxes so that he can successfully complete all of Okabe's commands. It is guaranteed that every box is added before it is required to be removed. | Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands. | C | 2535fc09ce74b829c26e1ebfc1ee17c6 | ed3fd9df653af06cfff84813f58ef560 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"greedy",
"trees"
] | 1498401300 | ["3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove", "7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove"] | NoteIn the first sample, Daru should reorder the boxes after adding box 3 to the stack.In the second sample, Daru should reorder the boxes after adding box 4 and box 7 to the stack. | PASSED | 1,500 | standard input | 3 seconds | The first line of input contains the integer n (1 ≤ n ≤ 3·105) — the number of boxes. Each of the next 2n lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer x (1 ≤ x ≤ n) follows, indicating that Daru should add the box with number x to the top of the stack. It is guaranteed that exactly n lines contain "add" operations, all the boxes added are distinct, and n lines contain "remove" operations. It is also guaranteed that a box is always added before it is required to be removed. | ["1", "2"] | #include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
int main()
{
int n,i,a[300000],top=-1,count=0,check=0;
scanf("%d",&n);
for(i=0;i<2*n;i++)
{
char s[10];
scanf("%s",s);
int m;
if(s[0]=='a')
{
top++;
scanf("%d",&m);
a[top]=m;
}
else if(s[0]=='r')
{
check++;
if(top!=-1)
{
if(a[top]!=check)
{
count++;
top=-1;
}
else
top--;
}
}
}
printf("%d\n",count);
return 0;
}
| |
Okabe and Super Hacker Daru are stacking and removing boxes. There are n boxes numbered from 1 to n. Initially there are no boxes on the stack.Okabe, being a control freak, gives Daru 2n commands: n of which are to add a box to the top of the stack, and n of which are to remove a box from the top of the stack and throw it in the trash. Okabe wants Daru to throw away the boxes in the order from 1 to n. Of course, this means that it might be impossible for Daru to perform some of Okabe's remove commands, because the required box is not on the top of the stack.That's why Daru can decide to wait until Okabe looks away and then reorder the boxes in the stack in any way he wants. He can do it at any point of time between Okabe's commands, but he can't add or remove boxes while he does it.Tell Daru the minimum number of times he needs to reorder the boxes so that he can successfully complete all of Okabe's commands. It is guaranteed that every box is added before it is required to be removed. | Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands. | C | 2535fc09ce74b829c26e1ebfc1ee17c6 | 38619291e2d2d1816cd3ea722dcf1b66 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"greedy",
"trees"
] | 1498401300 | ["3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove", "7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove"] | NoteIn the first sample, Daru should reorder the boxes after adding box 3 to the stack.In the second sample, Daru should reorder the boxes after adding box 4 and box 7 to the stack. | PASSED | 1,500 | standard input | 3 seconds | The first line of input contains the integer n (1 ≤ n ≤ 3·105) — the number of boxes. Each of the next 2n lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer x (1 ≤ x ≤ n) follows, indicating that Daru should add the box with number x to the top of the stack. It is guaranteed that exactly n lines contain "add" operations, all the boxes added are distinct, and n lines contain "remove" operations. It is also guaranteed that a box is always added before it is required to be removed. | ["1", "2"] | #include<stdio.h>
#include<string.h>
int main()
{
char s[7];
int rem = 0;
int n,temp=-1;
int in;
int heap[300001];
int ans = 0;
scanf("%d",&n);
for(int i = 0 ; i<(2*n) ; i++)
{
scanf("%s",s);
if(s[0]=='a')
{
scanf("%d",&in);
heap[++temp]=in;
}
else if(s[0]=='r')
{
rem++;
if(temp!=-1)
{
if(heap[temp]==rem)
{
temp--;
}
else
{
temp =-1;
ans++;
}
}
}
}
printf("%d",ans);
} | |
Okabe and Super Hacker Daru are stacking and removing boxes. There are n boxes numbered from 1 to n. Initially there are no boxes on the stack.Okabe, being a control freak, gives Daru 2n commands: n of which are to add a box to the top of the stack, and n of which are to remove a box from the top of the stack and throw it in the trash. Okabe wants Daru to throw away the boxes in the order from 1 to n. Of course, this means that it might be impossible for Daru to perform some of Okabe's remove commands, because the required box is not on the top of the stack.That's why Daru can decide to wait until Okabe looks away and then reorder the boxes in the stack in any way he wants. He can do it at any point of time between Okabe's commands, but he can't add or remove boxes while he does it.Tell Daru the minimum number of times he needs to reorder the boxes so that he can successfully complete all of Okabe's commands. It is guaranteed that every box is added before it is required to be removed. | Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands. | C | 2535fc09ce74b829c26e1ebfc1ee17c6 | 1728eca167800d5c33ab038301de6fd7 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"greedy",
"trees"
] | 1498401300 | ["3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove", "7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove"] | NoteIn the first sample, Daru should reorder the boxes after adding box 3 to the stack.In the second sample, Daru should reorder the boxes after adding box 4 and box 7 to the stack. | PASSED | 1,500 | standard input | 3 seconds | The first line of input contains the integer n (1 ≤ n ≤ 3·105) — the number of boxes. Each of the next 2n lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer x (1 ≤ x ≤ n) follows, indicating that Daru should add the box with number x to the top of the stack. It is guaranteed that exactly n lines contain "add" operations, all the boxes added are distinct, and n lines contain "remove" operations. It is also guaranteed that a box is always added before it is required to be removed. | ["1", "2"] | #include <stdio.h>
#include <string.h>
#include <stdlib.h>
/*
Problem 821C
C. Okabe and Boxes
*/
static int *stack;
static int sp = 0;
void print_stack(void)
{
int i;
puts("*********");
for(i = 0; i < sp; i ++)
printf("%d\n", stack[i]);
}
int compare(const void *x, const void *y)
{
int a = *(int *)x, b = *(int *)y;
// Order is inverted becouse the it
// goes from higher to lower
if(a < b)
return 1;
else if(a > b)
return -1;
else
return 0;
}
int main()
{
char buffer[64];
int i;
int n;
int a;
int swaps = 0, to_pop = 1;
scanf("%d\n", &n);
stack = malloc(n * sizeof(int));
for(i = 0; i < (2 * n); i ++)
{
fgets(buffer, sizeof(buffer), stdin);
if( buffer[0] == 'a' )
{
a = atoi(&buffer[4]);
stack[sp ++] = a;
}
else
{
if(sp != 0)
{
if(stack[sp - 1] != to_pop)
{
sp = 0;
swaps ++;
}
else
sp --;
}
to_pop ++;
}
}
printf("%d\n", swaps);
free(stack);
return 0;
}
| |
Okabe and Super Hacker Daru are stacking and removing boxes. There are n boxes numbered from 1 to n. Initially there are no boxes on the stack.Okabe, being a control freak, gives Daru 2n commands: n of which are to add a box to the top of the stack, and n of which are to remove a box from the top of the stack and throw it in the trash. Okabe wants Daru to throw away the boxes in the order from 1 to n. Of course, this means that it might be impossible for Daru to perform some of Okabe's remove commands, because the required box is not on the top of the stack.That's why Daru can decide to wait until Okabe looks away and then reorder the boxes in the stack in any way he wants. He can do it at any point of time between Okabe's commands, but he can't add or remove boxes while he does it.Tell Daru the minimum number of times he needs to reorder the boxes so that he can successfully complete all of Okabe's commands. It is guaranteed that every box is added before it is required to be removed. | Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands. | C | 2535fc09ce74b829c26e1ebfc1ee17c6 | 70070d17843a7499f40856109912f2fc | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"greedy",
"trees"
] | 1498401300 | ["3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove", "7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove"] | NoteIn the first sample, Daru should reorder the boxes after adding box 3 to the stack.In the second sample, Daru should reorder the boxes after adding box 4 and box 7 to the stack. | PASSED | 1,500 | standard input | 3 seconds | The first line of input contains the integer n (1 ≤ n ≤ 3·105) — the number of boxes. Each of the next 2n lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer x (1 ≤ x ≤ n) follows, indicating that Daru should add the box with number x to the top of the stack. It is guaranteed that exactly n lines contain "add" operations, all the boxes added are distinct, and n lines contain "remove" operations. It is also guaranteed that a box is always added before it is required to be removed. | ["1", "2"] | #include <stdio.h>
#include <string.h>
int a[1000000], b[1000000];
int main(int argc, char const *argv[])
{
int i,j,k,l,n,q,x,y,p,m,b;
char str[100];
scanf("%d", &n);
// for(i=0;i<n;i++)
// b[i] = 0;
int count = 0;
i=0;
j=0;
int num = 1;
for(l=0;l<2*n;l++){
// printf("statement : %d\n",l );
scanf("%s",str);
if(str[0] == 'a'){
scanf("%d",&x);
i++;
a[i] = x;
}
if(str[0] == 'r'){
if(j<i){
if(a[i] == num){
num++;
i--;
}
else{
j=i;
num++;
count++;
}
}
else{
num++;
}
}
}
printf("%d\n",count );
return 0;
} | |
Okabe and Super Hacker Daru are stacking and removing boxes. There are n boxes numbered from 1 to n. Initially there are no boxes on the stack.Okabe, being a control freak, gives Daru 2n commands: n of which are to add a box to the top of the stack, and n of which are to remove a box from the top of the stack and throw it in the trash. Okabe wants Daru to throw away the boxes in the order from 1 to n. Of course, this means that it might be impossible for Daru to perform some of Okabe's remove commands, because the required box is not on the top of the stack.That's why Daru can decide to wait until Okabe looks away and then reorder the boxes in the stack in any way he wants. He can do it at any point of time between Okabe's commands, but he can't add or remove boxes while he does it.Tell Daru the minimum number of times he needs to reorder the boxes so that he can successfully complete all of Okabe's commands. It is guaranteed that every box is added before it is required to be removed. | Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands. | C | 2535fc09ce74b829c26e1ebfc1ee17c6 | e36bf3b0c32b1598e64435cd375a9359 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"greedy",
"trees"
] | 1498401300 | ["3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove", "7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove"] | NoteIn the first sample, Daru should reorder the boxes after adding box 3 to the stack.In the second sample, Daru should reorder the boxes after adding box 4 and box 7 to the stack. | PASSED | 1,500 | standard input | 3 seconds | The first line of input contains the integer n (1 ≤ n ≤ 3·105) — the number of boxes. Each of the next 2n lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer x (1 ≤ x ≤ n) follows, indicating that Daru should add the box with number x to the top of the stack. It is guaranteed that exactly n lines contain "add" operations, all the boxes added are distinct, and n lines contain "remove" operations. It is also guaranteed that a box is always added before it is required to be removed. | ["1", "2"] | #include <stdio.h>
typedef struct {
int n;
int array[500000];
} stack;
stack S;
void push(int x) {
S.array[S.n] = x;
S.n += 1;
return;
}
int pop(void) {
S.n -= 1;
return S.array[S.n];
}
int top(void) {
if (S.n != 0)
return S.array[S.n - 1];
else
return 0;
}
int main(void) {
int n, x, t = 1, r = 0, m[500000] = {0};
char s[10];
scanf("%d", &n);
S.n = 0;
for (int i = 0; i < 2 * n; i++) {
scanf("%s", s);
if (s[0] == 'a') {
scanf("%d", &x);
push(x);
}
else {
if (m[top()] == 1) {
t += 1;
pop();
m[top()] = 1;
}
else if (top() == t) {
t += 1;
pop();
}
else {
t += 1;
r += 1;
pop();
m[top()] = 1;
}
}
}
printf("%d\n", r);
}
| |
Okabe and Super Hacker Daru are stacking and removing boxes. There are n boxes numbered from 1 to n. Initially there are no boxes on the stack.Okabe, being a control freak, gives Daru 2n commands: n of which are to add a box to the top of the stack, and n of which are to remove a box from the top of the stack and throw it in the trash. Okabe wants Daru to throw away the boxes in the order from 1 to n. Of course, this means that it might be impossible for Daru to perform some of Okabe's remove commands, because the required box is not on the top of the stack.That's why Daru can decide to wait until Okabe looks away and then reorder the boxes in the stack in any way he wants. He can do it at any point of time between Okabe's commands, but he can't add or remove boxes while he does it.Tell Daru the minimum number of times he needs to reorder the boxes so that he can successfully complete all of Okabe's commands. It is guaranteed that every box is added before it is required to be removed. | Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands. | C | 2535fc09ce74b829c26e1ebfc1ee17c6 | ed2af5afba794e49303e628aaa0b7457 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"greedy",
"trees"
] | 1498401300 | ["3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove", "7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove"] | NoteIn the first sample, Daru should reorder the boxes after adding box 3 to the stack.In the second sample, Daru should reorder the boxes after adding box 4 and box 7 to the stack. | PASSED | 1,500 | standard input | 3 seconds | The first line of input contains the integer n (1 ≤ n ≤ 3·105) — the number of boxes. Each of the next 2n lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer x (1 ≤ x ≤ n) follows, indicating that Daru should add the box with number x to the top of the stack. It is guaranteed that exactly n lines contain "add" operations, all the boxes added are distinct, and n lines contain "remove" operations. It is also guaranteed that a box is always added before it is required to be removed. | ["1", "2"] | #include <stdio.h>
typedef long long unsigned llu;
typedef unsigned u;
u A[333333],Q[333333],Qi,x=1;char cmd[9];
int main()
{
u n,q,k,r=0;
scanf("%u",&n);
for(q=n<<1;q--;)
{
scanf("%s",cmd);
if(*cmd=='a')
{
scanf("%u",&k);
Q[Qi++]=k;
}
if(*cmd=='r')
{
if(Qi&&Q[Qi-1]==x){--Qi;++x;}
else if(!Qi&&A[x])++x;
else for(++x,++r;Qi;)A[Q[--Qi]]=1;
}
}
printf("%u\n",r);
return 0;
} | |
You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that: $$$1 \le i < j < k \le n$$$; $$$p_i < p_j$$$ and $$$p_j > p_k$$$. Or say that there are no such indices. | For each test case: if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves; if there are no such indices, print NO (case insensitive). If there are multiple valid triples of indices, print any of them. | C | dd55e29ac9756325530ad2f4479d9f6d | 1df3d7dfbafbba322c9712e62a16a892 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"brute force"
] | 1594565100 | ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$. | ["YES\n2 3 4\nYES\n3 5 6\nNO"] | #include<stdio.h>
#include<stdlib.h>
int main()
{
int m,t;
int n,i,j,k,l,r,temp,flag;
scanf("%d",&t);
for(m=1;m<=t;m++)
{ flag=0;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
scanf("%d",&a[i]);
// i=0;
//j=1;
//k=2;
for(j=1;j<n-1;j++)
{
l=r=-1;
temp=a[j];
for(i=j-1;i>=0;i--)
{
if(a[i]<temp)
{
l=i;
break;
}
}
if(l!=-1)
{
for(k=j+1;k<n;k++)
{
if(a[k]<temp)
{
r=k;
break;
}
}
}
if(l!=-1 && r!=-1)
{
printf("YES\n");
printf("%d %d %d\n",l+1,j+1,r+1);
flag=-1;
break;
//exit(0);
}
}
if(flag==0)
{
printf("NO\n");
}
}
return 0;
}
| |
You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that: $$$1 \le i < j < k \le n$$$; $$$p_i < p_j$$$ and $$$p_j > p_k$$$. Or say that there are no such indices. | For each test case: if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves; if there are no such indices, print NO (case insensitive). If there are multiple valid triples of indices, print any of them. | C | dd55e29ac9756325530ad2f4479d9f6d | 6bb7462432e9b7165403910db43735a5 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"brute force"
] | 1594565100 | ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$. | ["YES\n2 3 4\nYES\n3 5 6\nNO"] | #include <stdio.h>
#include <stdlib.h>
void prob1380A(){
int T;
scanf("%d", &T);
while(T--){
int n, r1, r2, r3,i, state=0;
scanf("%d", &n);
int arr[n];
for (i =0; i<n; i++)scanf("%d", &arr[i]);
for (i=1; i<n-1; i++){
if (arr[i-1]<arr[i]&& arr[i]>arr[i+1]){
printf("YES\n");
printf("%d %d %d\n", i, i+1, i+2);
state =1;
break;
}
}
if (state ==0)printf("NO\n");
}
}
int main()
{
prob1380A();
return 0;
}
| |
You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that: $$$1 \le i < j < k \le n$$$; $$$p_i < p_j$$$ and $$$p_j > p_k$$$. Or say that there are no such indices. | For each test case: if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves; if there are no such indices, print NO (case insensitive). If there are multiple valid triples of indices, print any of them. | C | dd55e29ac9756325530ad2f4479d9f6d | e13aabbf1549f88736755c1765a7e3c2 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"brute force"
] | 1594565100 | ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$. | ["YES\n2 3 4\nYES\n3 5 6\nNO"] | #include<stdio.h>
#include<stdlib.h>
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int n, a[1000], f = 0, i;
scanf("%d", &n);
for (i = 0; i<n; i++)
{
scanf("%d", &a[i]);
}
for (i = 1; i<n - 1; i++)
{
if ((a[i] > a[i - 1]) && (a[i] > a[i + 1]))
{
printf("YES\n");
printf("%d %d %d\n", i, i + 1, i + 2);
f = 1;
break;
}
}
if (f == 0)
{
printf("NO\n");
}
}
return 0;
} | |
You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that: $$$1 \le i < j < k \le n$$$; $$$p_i < p_j$$$ and $$$p_j > p_k$$$. Or say that there are no such indices. | For each test case: if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves; if there are no such indices, print NO (case insensitive). If there are multiple valid triples of indices, print any of them. | C | dd55e29ac9756325530ad2f4479d9f6d | d4d76ff47056100b91b7265d81a54c16 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"brute force"
] | 1594565100 | ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$. | ["YES\n2 3 4\nYES\n3 5 6\nNO"] | #include <stdio.h>
#include <stdlib.h>
int main(void)
{
int i,n, arr[1000], j,k=0;
scanf("%d", &i);
for(;i>0;i--){
scanf("%d", &n);
for(j=0;j<n;j++) scanf("%d", &arr[j]);
for(j=1;j<n-1;j++){
if(arr[j]>arr[j-1] && arr[j]>arr[j+1]){
printf("YES\n");
printf("%d %d %d\n", j, j+1,j+2);
k=1;
break;
}
}
if(!k) printf("NO\n");
k=0;
}
return 0;
}
| |
You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that: $$$1 \le i < j < k \le n$$$; $$$p_i < p_j$$$ and $$$p_j > p_k$$$. Or say that there are no such indices. | For each test case: if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves; if there are no such indices, print NO (case insensitive). If there are multiple valid triples of indices, print any of them. | C | dd55e29ac9756325530ad2f4479d9f6d | fa291c2460ae117f79576d1391916614 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"brute force"
] | 1594565100 | ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$. | ["YES\n2 3 4\nYES\n3 5 6\nNO"] | #include <stdio.h>
int main() {
int num_cases, n, num;
scanf("%d", &num_cases);
for (int idx = 0; idx < num_cases; ++idx) {
scanf("%d", &n);
char incr = 0;
int prev, maxi = 0;
scanf("%d", &prev);
for (int i = 2; i <= n; ++i) {
scanf("%d", &num);
if (maxi) continue;
if (num > prev) {
incr = 1;
} else if (incr) {
maxi = i - 1;
}
prev = num;
}
if (maxi) {
printf("YES\n");
printf("%d %d %d\n", maxi - 1, maxi, maxi + 1);
} else {
printf("NO\n");
}
}
return 0;
} | |
You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that: $$$1 \le i < j < k \le n$$$; $$$p_i < p_j$$$ and $$$p_j > p_k$$$. Or say that there are no such indices. | For each test case: if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves; if there are no such indices, print NO (case insensitive). If there are multiple valid triples of indices, print any of them. | C | dd55e29ac9756325530ad2f4479d9f6d | 75f4ee027563802948060724a22c4a6d | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"brute force"
] | 1594565100 | ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$. | ["YES\n2 3 4\nYES\n3 5 6\nNO"] | // Online C compiler to run C online.
// Write C code in this online editor and run it.
// Online C compiler to run C online.
// Write C code in this online editor and run it.
#include<stdio.h>
int main()
{
int i=0,j=-1,k,x=1,c=1,d=0,t,h,n;
scanf("%d",&t);
while(c<=t)
{
d=0;i=1;j=-1;k=1002;x=2;
scanf("%d",&n);
int a[n+1];
for(h=1;h<=n;h++)
scanf("%d",&a[h]);
while(a[x]<=a[i] &&( x<=n))
{
i=x;x++;
}
if(i==n || j==n ||x>n)
{
d=3;printf("NO\n");c++;continue;
}
j=x;x=j+1;
while(x<=n)
{
if(a[x]<a[j])
{
k=x;d=2;break;
}
else if(j==n){
d=1;break;
}
else if(a[x]>a[j])
j=x;
x++;
}
if(d==1 || j==n)
printf("NO\n");
if(d==2){
if(i>=1 && k<=n){
printf("YES\n");printf("%d %d %d\n",i,j,k);
}
else
{
printf("NO\n");
}
}
c++;
}
}
| |
You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that: $$$1 \le i < j < k \le n$$$; $$$p_i < p_j$$$ and $$$p_j > p_k$$$. Or say that there are no such indices. | For each test case: if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves; if there are no such indices, print NO (case insensitive). If there are multiple valid triples of indices, print any of them. | C | dd55e29ac9756325530ad2f4479d9f6d | 9d780dad2c273e46de179fa2af5135e0 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"brute force"
] | 1594565100 | ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$. | ["YES\n2 3 4\nYES\n3 5 6\nNO"] | #include <stdio.h>
int main()
{
int t;
scanf("%d",&t);
for(int i=0;i<t;i++)
{
int A,b,c,n,v,pa,pb,pc;
pa=0;pb=0;pc=0;
b=0;v=0;
scanf("%d",&n);
int a[n];
for(int j=0;j<n;j++)
{
scanf("%d",&a[j]);
}
A=a[0];pa=1;
for(int j=1;j<n;j++)
{
if(b==0)
{
if(a[j]<=A)
{
A=a[j];
pa=j+1;
}
else
{
b=a[j];
pb=j+1;
}
}
else{
if(b<=a[j])
{
b=a[j];
pb=j+1;
}
else{
c=a[j];
pc=j+1;
v=1;
break;
}
}
}
if(v==0)
{
printf("NO\n");
}
else
{
printf("YES\n%d %d %d\n",pa,pb,pc);
}
}
return 0;
}
| |
You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that: $$$1 \le i < j < k \le n$$$; $$$p_i < p_j$$$ and $$$p_j > p_k$$$. Or say that there are no such indices. | For each test case: if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves; if there are no such indices, print NO (case insensitive). If there are multiple valid triples of indices, print any of them. | C | dd55e29ac9756325530ad2f4479d9f6d | 53c3c8902abff7652ea181b21e160419 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"brute force"
] | 1594565100 | ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$. | ["YES\n2 3 4\nYES\n3 5 6\nNO"] | #include <stdio.h>
int main()
{
long long int t;
scanf("%lld",&t);
while(t--)
{
long long int n,j,a[10000],count=1;
scanf("%lld",&n);
for(j=1;j<=n;j++) scanf("%lld",&a[j]);
for(j=2;j<=n-1;j++)
{
if((a[j]>a[j-1])&&(a[j]>a[j+1]))
{
printf("YES\n%lld %lld %lld\n",j-1,j,j+1);
count=0;
break;
}
}
if(count==1) printf("NO\n");
}
} | |
You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that: $$$1 \le i < j < k \le n$$$; $$$p_i < p_j$$$ and $$$p_j > p_k$$$. Or say that there are no such indices. | For each test case: if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves; if there are no such indices, print NO (case insensitive). If there are multiple valid triples of indices, print any of them. | C | dd55e29ac9756325530ad2f4479d9f6d | 9f405e17a6caa325f4e851d804684e61 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"brute force"
] | 1594565100 | ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$. | ["YES\n2 3 4\nYES\n3 5 6\nNO"] | #include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
int d,k,a=0,b=0,w=0,i,j,t,n,arr[1005],p=0,q=0,r=0;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
if(i)
{
if(arr[i]>arr[i-1])
{
if(!a)p=i;
a=1;
if(w<arr[i] &&(!b))
{
q=i+1;
w=arr[i];
}
}
if(arr[i]<w)
{
b=1;
r=i+1;
}
}
}
if(a*b)
printf("YES\n%d %d %d\n",p,q,r);
else
printf("NO\n");
a=b=p=q=r=w=0;
}
return 0;
} | |
You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that: $$$1 \le i < j < k \le n$$$; $$$p_i < p_j$$$ and $$$p_j > p_k$$$. Or say that there are no such indices. | For each test case: if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves; if there are no such indices, print NO (case insensitive). If there are multiple valid triples of indices, print any of them. | C | dd55e29ac9756325530ad2f4479d9f6d | 4816752d720e7bd62f80cfe923bb477b | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"brute force"
] | 1594565100 | ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$. | ["YES\n2 3 4\nYES\n3 5 6\nNO"] | #include <stdio.h>
int main()
{
int t, i, j, n, ar[2000], a, b, c, temp, k;
scanf("%d", &t);
for(i=0; i<t; i++){
temp = 0;
scanf("%d", &n);
for(j=0; j<n; j++){
scanf("%d", &ar[j]);
}
for(j=0; j<n-1; j++){
if(ar[j]<ar[j+1]){
a = j;
b = j+1;
for(k=b+1; k<n; k++){
if(ar[k] < ar[b]){
c = k;
temp = 1;
break;
}
}
if(temp){
break;
}
}
}
if(temp){
printf("YES\n%d %d %d\n", a+1, b+1, c+1);
}
else{
printf("NO\n");
}
}
return 0;
}
| |
You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that: $$$1 \le i < j < k \le n$$$; $$$p_i < p_j$$$ and $$$p_j > p_k$$$. Or say that there are no such indices. | For each test case: if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves; if there are no such indices, print NO (case insensitive). If there are multiple valid triples of indices, print any of them. | C | dd55e29ac9756325530ad2f4479d9f6d | 993d51f70b4b017a245160957d769026 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"brute force"
] | 1594565100 | ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$. | ["YES\n2 3 4\nYES\n3 5 6\nNO"] | #include<stdio.h>
int main(){
int i,j,k,n,t,arr[1001],p,h;
int ip,ik;
scanf("%d",&t);
for(ip=1;ip<=t;ip++){
int d=0,e=0;
scanf("%d",&n);
for(ik=0;ik<n;ik++){
scanf("%d",&arr[ik]);
}
for(j=1;j<n-1;j++){
for(i=0;i<j;i++){
if(arr[i]<arr[j]){
p=i;
d++;
break;
}
}
if(d!=0){
for(k=n-1;k>j;k--){
if(arr[j]>arr[k]){
h=k;
e++;
break;
}
}
}
if(d*e!=0) break;
}
if(d*e!=0) {
printf("YES\n");
printf("%d %d %d\n",i+1,j+1,k+1);}
else printf("NO\n");
}
return 0;
} | |
You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that: $$$1 \le i < j < k \le n$$$; $$$p_i < p_j$$$ and $$$p_j > p_k$$$. Or say that there are no such indices. | For each test case: if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves; if there are no such indices, print NO (case insensitive). If there are multiple valid triples of indices, print any of them. | C | dd55e29ac9756325530ad2f4479d9f6d | 80d061e7c24d90c0e2d3db504efafd31 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"brute force"
] | 1594565100 | ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$. | ["YES\n2 3 4\nYES\n3 5 6\nNO"] | #include<stdio.h>
#include<stdlib.h>
int N,n;
int a[1010];
int* solve(){
static int b[3];
int left;
b[0]=-1;
for (int i=1;i<n-1;i++){
left=-1;
for (int j=0;j<i;j++){
//printf("%d %d %d\n",i,a[i],a[j]);
if ((a[j]-a[i])<0){left=j+1;break;}
}
if (left==-1)continue;
for (int j=i+1;j<n;j++){
if ((a[j]-a[i])<0){
b[0]=left;
b[1]=i+1;
b[2]=j+1;
return b;
}
}
}
return b;
}
int main(){
if(scanf("%d",&N)!=EOF);
while(N--){
if(scanf("%d",&n)!=EOF);
//printf("%d\n",n);
for(int i=0;i<n;i++)if(scanf("%d",&a[i])!=EOF);
int* b=malloc(sizeof(int)*3);
b=solve();
if (b[0]==-1)printf("No\n");
else{
printf("YES\n%d %d %d\n",b[0],b[1],b[2]);
}
}
} | |
You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that: $$$1 \le i < j < k \le n$$$; $$$p_i < p_j$$$ and $$$p_j > p_k$$$. Or say that there are no such indices. | For each test case: if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves; if there are no such indices, print NO (case insensitive). If there are multiple valid triples of indices, print any of them. | C | dd55e29ac9756325530ad2f4479d9f6d | edad37af4c9ec023a13d12f5fa36896f | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"brute force"
] | 1594565100 | ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$. | ["YES\n2 3 4\nYES\n3 5 6\nNO"] | #include<stdio.h>
int main()
{
int T,p,i,j,k,l,m,count=0;
scanf("%d",&T);
int ary[1000];
while(T--){
scanf("%d",&p);
for(m=0;m<p;m++){
scanf("%d",&ary[m]);
}
for(l=0;l<p-2;l++){
i=l+1;
j=l+2;
k=l+3;
if(i>=1&&i<j&&j<k&&k<=p){
if(ary[i-1]<ary[j-1]&&ary[j-1]>ary[k-1]){
count++;
printf("YES\n");
printf("%d %d %d\n",i,j,k);
break;
}
}
}
if(count==0){
printf("NO\n");
}
count=0;
}
}
| |
You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that: $$$1 \le i < j < k \le n$$$; $$$p_i < p_j$$$ and $$$p_j > p_k$$$. Or say that there are no such indices. | For each test case: if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves; if there are no such indices, print NO (case insensitive). If there are multiple valid triples of indices, print any of them. | C | dd55e29ac9756325530ad2f4479d9f6d | 7d79d37c9803f9964c34bb98a9687162 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"brute force"
] | 1594565100 | ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$. | ["YES\n2 3 4\nYES\n3 5 6\nNO"] | #include <stdio.h>
int main()
{
int t,n,p[1005];
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
int i,j,k,flag1=0,flag2=0;
for(int i=0;i<n;i++)
scanf("%d",&p[i]);
for(i=1;i<n-1;i++)
{
for(j=i-1;j>=0;j--)
{
if(p[j]<p[i])
{
flag1=1;
break;
}
}
for(k=i+1;k<n;k++)
{
if(p[k]<p[i])
{
flag2=1;
break;
}
}
if(flag1&&flag2)
break;
else
{
flag1=0;
flag2=0;
}
}
if(flag1&&flag2)
{
printf("YES\n");
printf("%d %d %d\n",j+1,i+1,k+1);
}
else
printf("NO\n");
}
return 0;
}
| |
You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that: $$$1 \le i < j < k \le n$$$; $$$p_i < p_j$$$ and $$$p_j > p_k$$$. Or say that there are no such indices. | For each test case: if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves; if there are no such indices, print NO (case insensitive). If there are multiple valid triples of indices, print any of them. | C | dd55e29ac9756325530ad2f4479d9f6d | 65882ce8e220547aa5fe85d38e52ae55 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"brute force"
] | 1594565100 | ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$. | ["YES\n2 3 4\nYES\n3 5 6\nNO"] | #include<stdio.h>
int main()
{
int t,m;
scanf("%d",&t);
m=t-1;
int arr[t][4];
while(t--)
{
arr[t][0]=0;
int n,l=0,p=0,q=0,f=0,g=0;
scanf("%d",&n);
int ar[n];
for(int i=0;i<n;i++)
scanf("%d",&ar[i]);
for(int i=1;i<n-1;i++)
{
f=0;
g=0;
for(int j=0;j<i;j++)
{
if(ar[i]>ar[j])
{
f=1;
p=j;
break;
}
}
for(int j=n-1;j>i;j--)
{
if(ar[i]>ar[j])
{
g=1;
q=j;
break;
}
}
if(g==1&&f==1)
{
l=i;
arr[t][0]=1;
arr[t][1]=p+1;
arr[t][2]=l+1;
arr[t][3]=q+1;
break;
}
}
/*
if(ar[i]<max)
{
p=i;
break;
}
}
for()*/
}
for(int i=m;i>=0;i--)
{
if(arr[i][0]==0)
printf("%s\n","NO");
else
printf("%s\n%d %d %d\n","YES",arr[i][1],arr[i][2],arr[i][3]);
}
return 0;
} | |
You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that: $$$1 \le i < j < k \le n$$$; $$$p_i < p_j$$$ and $$$p_j > p_k$$$. Or say that there are no such indices. | For each test case: if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves; if there are no such indices, print NO (case insensitive). If there are multiple valid triples of indices, print any of them. | C | dd55e29ac9756325530ad2f4479d9f6d | 0acd8271a1c76ccb5685b5887350f848 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"brute force"
] | 1594565100 | ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$. | ["YES\n2 3 4\nYES\n3 5 6\nNO"] | #include <stdio.h>
#include <stdlib.h>
int main() {
int i,t,n,*p,flag;
scanf("%d",&t);
while(t--) {
flag = 0;
scanf("%d",&n);
p = (int*)calloc(n,sizeof(int));
for(i = 0; i < n; i++)
scanf("%d",&p[i]);
for(i = 0; i < n - 2; i++){
if(p[i] < p[i + 1] && p[i + 1] > p[i + 2]){
flag = 1;
break;
}
}
if(flag == 1){
printf("YES\n");
printf("%d %d %d\n",i + 1,i + 2,i + 3);
}
else
printf("NO\n");
}
} | |
You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that: $$$1 \le i < j < k \le n$$$; $$$p_i < p_j$$$ and $$$p_j > p_k$$$. Or say that there are no such indices. | For each test case: if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves; if there are no such indices, print NO (case insensitive). If there are multiple valid triples of indices, print any of them. | C | dd55e29ac9756325530ad2f4479d9f6d | 47f99f97df46d8269444844e465ee20e | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"brute force"
] | 1594565100 | ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$. | ["YES\n2 3 4\nYES\n3 5 6\nNO"] | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int main()
{
int cases;
scanf("%d", &cases);
for (int i = 1; i <= cases; i += 1) {
cycle();
}
return 0;
}
void cycle() {
int n;
scanf("%d", &n);
int items[n];
for (int i = 0; i < n; i += 1) {
scanf("%d", &items[i]);
}
int maximum = n + 1; // Added 1 for the first "Do"
int start = 0;
int end = n; // Added 1 for the first "Do"
int pos_max = end;
bool solved = false;
do {
if (pos_max == start) {
start += 1;
} else if (pos_max == end) { // End set to N - 1
end -= 1;
}
maximum -= 1;
for (int i = start; i <= end; i += 1) {
if (items[i] == maximum) {
pos_max = i;
}
}
if (pos_max != start && pos_max != end) {
solved = true;
break;
}
} while ((pos_max == start || pos_max == end) && (end - start + 1 > 3));
if (solved) {
printf("YES\n");
printf("%d %d %d\n", start + 1, pos_max + 1, end + 1);
} else {
printf("NO\n");
}
}
| |
You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that: $$$1 \le i < j < k \le n$$$; $$$p_i < p_j$$$ and $$$p_j > p_k$$$. Or say that there are no such indices. | For each test case: if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves; if there are no such indices, print NO (case insensitive). If there are multiple valid triples of indices, print any of them. | C | dd55e29ac9756325530ad2f4479d9f6d | 7c1b9bbad614aefc9068b0bea0289760 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"brute force"
] | 1594565100 | ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$. | ["YES\n2 3 4\nYES\n3 5 6\nNO"] | #include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
int d,k,a=0,b=0,w=0,i,j,t,n,arr[1005],p=0,q=0,r=0;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
if(i)
{
//printf("%d\n",q);
if(arr[i]>arr[i-1])
{
if(!a)p=i;
a=1;
if(w<arr[i] &&(!b))
{
q=i+1;
w=arr[i];
}
}
if(arr[i]<w)
{
b=1;
r=i+1;
}
}
}
if(a*b)
printf("YES\n%d %d %d\n",p,q,r);
else
printf("NO\n");
a=b=p=q=r=w=0;
}
return 0;
}
| |
You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that: $$$1 \le i < j < k \le n$$$; $$$p_i < p_j$$$ and $$$p_j > p_k$$$. Or say that there are no such indices. | For each test case: if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves; if there are no such indices, print NO (case insensitive). If there are multiple valid triples of indices, print any of them. | C | dd55e29ac9756325530ad2f4479d9f6d | 65c52e67a538498d80c705a0ecd53108 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"brute force"
] | 1594565100 | ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$. | ["YES\n2 3 4\nYES\n3 5 6\nNO"] | #include <stdio.h>
int main(){
int t, n, p[1001], s[1001], l, r, max, flag, i;
scanf("%d", &t);
while(t--){
scanf("%d", &n);
l = 1;
r = n;
max = n;
flag = 0;
for(i = 1; i <= n; i++){
scanf("%d", &p[i]);
s[p[i]] = i;
}
while(l < r && flag == 0){
//printf("%d %d %d", l, r, flag);
if(max == p[l]){
l++;
max--;
}
else if(max == p[r]){
r--;
max--;
}
else{
printf("YES\n");
printf("%d %d %d\n", s[max] - 1, s[max], s[max] + 1);
flag = 1;
}
}
if(flag == 0){
printf("No\n");
}
}
return 0;
} | |
You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that: $$$1 \le i < j < k \le n$$$; $$$p_i < p_j$$$ and $$$p_j > p_k$$$. Or say that there are no such indices. | For each test case: if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves; if there are no such indices, print NO (case insensitive). If there are multiple valid triples of indices, print any of them. | C | dd55e29ac9756325530ad2f4479d9f6d | d2c81a982d237d1dc81c7286f9eda067 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"brute force"
] | 1594565100 | ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$. | ["YES\n2 3 4\nYES\n3 5 6\nNO"] | #include <stdio.h>
int main(void)
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
int count;
int arr[n], check = 0;
for (count =0; count < n; count++)
scanf("%d",arr+count);
for (count =0; count < n-2; count++)
if (arr[count]<arr[count+1]&&arr[count+1]>arr[count+2])
{
printf("YES\n");
printf("%d %d %d\n",count+1, count+2,count+3);
check = 1;
break;
}
if (check == 1) 1;
else printf("NO\n");
}
} | |
You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that: $$$1 \le i < j < k \le n$$$; $$$p_i < p_j$$$ and $$$p_j > p_k$$$. Or say that there are no such indices. | For each test case: if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves; if there are no such indices, print NO (case insensitive). If there are multiple valid triples of indices, print any of them. | C | dd55e29ac9756325530ad2f4479d9f6d | f4cf7720620e0fb8dc508f6a49393c4c | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"brute force"
] | 1594565100 | ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$. | ["YES\n2 3 4\nYES\n3 5 6\nNO"] | #include <stdio.h>
int main()
{
int T = 0;
scanf("%d", &T);
int i;
int n = 0;
int j,p,q,r;
int temp1, temp2;
int count;
for(i=0; i<T; i++){
int x;
count = 0;
scanf("%d",&n);
int values[n];
int index[n];
scanf("%d",&values[count++]);
index[0] = 1;
scanf("%d",&temp1);
for(j=0; j<n-2; j++){
scanf("%d",&temp2);
if((values[count-1] < temp1) && (temp1 < temp2) || (values[count-1] > temp1)&& ( temp1> temp2)){
temp1 = temp2;
}
else{
values[count++] = temp1;
index[count-1] = j+2;
temp1 = temp2;
}
}
values[count++] = temp1;
index[count-1] = j+2;
for(p=1;p<count;p++){
for(q=0;q<p;q++){
if(values[p] > values[q]){
for(r=p+1;r<count;r++){
if(values[p]>values[r]){
printf("YES\n");
printf("%d %d %d\n",index[q], index[p], index[r]);
goto LABEL;
}
}
}
}
}
printf("NO\n");
LABEL:printf("");
}
} | |
You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that: $$$1 \le i < j < k \le n$$$; $$$p_i < p_j$$$ and $$$p_j > p_k$$$. Or say that there are no such indices. | For each test case: if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves; if there are no such indices, print NO (case insensitive). If there are multiple valid triples of indices, print any of them. | C | dd55e29ac9756325530ad2f4479d9f6d | e0b4213e700f1d4dfbe3a331d8c371c7 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"brute force"
] | 1594565100 | ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$. | ["YES\n2 3 4\nYES\n3 5 6\nNO"] | #include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,i,k;
scanf("%d",&n);
int A[n];
for(i=0;i<n;i++)
{
scanf("%d",&A[i]);
}
for(i=1;i<n-1;i++)
{
if(A[i]>A[i-1]&&A[i]>A[i+1])
{
break;
}
}
if(i==n-1)
{
printf("NO\n");
}
else
{
printf("YES\n%d %d %d\n",i,i+1,i+2);
}
}
return 0;
}
| |
You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that: $$$1 \le i < j < k \le n$$$; $$$p_i < p_j$$$ and $$$p_j > p_k$$$. Or say that there are no such indices. | For each test case: if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves; if there are no such indices, print NO (case insensitive). If there are multiple valid triples of indices, print any of them. | C | dd55e29ac9756325530ad2f4479d9f6d | 9c0b09a13dd05a01b30136da74837818 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"brute force"
] | 1594565100 | ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$. | ["YES\n2 3 4\nYES\n3 5 6\nNO"] | #include<stdio.h>
#include<stdlib.h>
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int n, a[1000], f = 0, i;
scanf("%d", &n);
for (i = 0; i<n; i++)
{
scanf("%d", &a[i]);
}
for (i = 1; i<n - 1; i++)
{
if ((a[i] > a[i - 1]) && (a[i] > a[i + 1]))
{
printf("YES\n");
printf("%d %d %d\n", i, i + 1, i + 2);
f = 1;
break;
}
}
if (f == 0)
{
printf("NO\n");
}
}
return 0;
} | |
You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that: $$$1 \le i < j < k \le n$$$; $$$p_i < p_j$$$ and $$$p_j > p_k$$$. Or say that there are no such indices. | For each test case: if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves; if there are no such indices, print NO (case insensitive). If there are multiple valid triples of indices, print any of them. | C | dd55e29ac9756325530ad2f4479d9f6d | f547b04a57e5b73d6dd8f8e77ac27802 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"brute force"
] | 1594565100 | ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$. | ["YES\n2 3 4\nYES\n3 5 6\nNO"] | #include<stdio.h>
#include<malloc.h>
#include<math.h>
int main()
{
int size,flag=0,i,cases,j,k;
scanf("%d",&cases);
int *arr;
for(i=0;i<cases;i++)
{
flag=0;
scanf("%d",&size);
arr=(int*)malloc(size*sizeof(int));
for(j=0;j<size;j++)
scanf("%d",&arr[j]);
for(k=0;k<size-2;k++)
{
if(arr[k]<arr[k+1]&&arr[k+2]<arr[k+1])
{
flag=1;
break;
}
}
if(flag==1)
printf("YES\n%d %d %d\n",k+1,k+2,k+3);
else
printf("NO\n");
}
} | |
You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that: $$$1 \le i < j < k \le n$$$; $$$p_i < p_j$$$ and $$$p_j > p_k$$$. Or say that there are no such indices. | For each test case: if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves; if there are no such indices, print NO (case insensitive). If there are multiple valid triples of indices, print any of them. | C | dd55e29ac9756325530ad2f4479d9f6d | c832967c7edf8020ebb91c8deaa5a7cb | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"brute force"
] | 1594565100 | ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$. | ["YES\n2 3 4\nYES\n3 5 6\nNO"] | #include<stdio.h>
int main(void)
{
int i,j,k,n,t,x,y,z,array[1000];
scanf("%d",&t);
for(i=0;i<t;i++)
{
int freq[1000]={0};
scanf("%d",&n);
for(j=0;j<n;j++)
scanf("%d",&array[j]);
for(j=1;j<n-1;j++)
{
x=-1;
y=-1;
z=-1;
if(array[j]>2)
{
for(k=0;k<j;k++)
{
if(array[j]>array[k])
{
x=k;
break;
}
}
for(k=j+1;k<n;k++)
{
if(array[j]>array[k])
{
z=k;
break;
}
}
if(x!=-1&&z!=-1)
y=j;
}
if(x!=-1&&y!=-1&&z!=-1)
break;
}
if(x==-1||y==-1||z==-1)
printf("NO\n");
else
printf("YES\n%d %d %d\n",x+1,y+1,z+1);
}
return 0;
}
| |
You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that: $$$1 \le i < j < k \le n$$$; $$$p_i < p_j$$$ and $$$p_j > p_k$$$. Or say that there are no such indices. | For each test case: if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves; if there are no such indices, print NO (case insensitive). If there are multiple valid triples of indices, print any of them. | C | dd55e29ac9756325530ad2f4479d9f6d | eff2333cf7b738955725576c31865b0c | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"brute force"
] | 1594565100 | ["3\n4\n2 1 4 3\n6\n4 6 1 2 5 3\n5\n5 3 1 2 4"] | null | PASSED | 900 | standard input | 2 seconds | The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$. | ["YES\n2 3 4\nYES\n3 5 6\nNO"] | int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,i,j,k;
scanf("%d",&n);
int a[n];
for(i=0; i<n; i++)
scanf("%d",&a[i]);
for(i=1; i<n-1; i++)
{
if(i<=n/2)
{
j= check_left(a,i);
//printf("%d\n",j);
if(j>=0)
{
k=check_right(a,i,n);
if(k==n)
continue;
else
break;
}
else
continue;
}
else
{
k= check_right(a,i,n);
//printf("%d\n",k);
if(k<n)
{
j=check_left(a,i);
if(j==-1)
continue;
else
break;
}
else
continue;
}
}
//printf("%d\n",i);
if(i==n-1)
printf("NO");
else
printf("YES\n%d %d %d",j+1,i+1,k+1);
printf("\n");
}
}
int check_left(int a[],int i)
{
int j;
for(j=i-1;j>=0;j--)
if(a[j]<a[i])
break;
return j;
}
int check_right(int a[],int i,int n)
{
int k;
for(k=i+1;k<n;k++)
if(a[k]<a[i])
break;
return k;
}
| |
The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually calculate some value which would represent how high the temperatures are.Mathematicians of Berland State University came up with a special heat intensity value. This value is calculated as follows:Suppose we want to analyze the segment of $$$n$$$ consecutive days. We have measured the temperatures during these $$$n$$$ days; the temperature during $$$i$$$-th day equals $$$a_i$$$.We denote the average temperature of a segment of some consecutive days as the arithmetic mean of the temperature measures during this segment of days. So, if we want to analyze the average temperature from day $$$x$$$ to day $$$y$$$, we calculate it as $$$\frac{\sum \limits_{i = x}^{y} a_i}{y - x + 1}$$$ (note that division is performed without any rounding). The heat intensity value is the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. For example, if analyzing the measures $$$[3, 4, 1, 2]$$$ and $$$k = 3$$$, we are interested in segments $$$[3, 4, 1]$$$, $$$[4, 1, 2]$$$ and $$$[3, 4, 1, 2]$$$ (we want to find the maximum value of average temperature over these segments).You have been hired by Berland State University to write a program that would compute the heat intensity value of a given period of days. Are you up to this task? | Print one real number — the heat intensity value, i. e., the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. Your answer will be considered correct if the following condition holds: $$$|res - res_0| < 10^{-6}$$$, where $$$res$$$ is your answer, and $$$res_0$$$ is the answer given by the jury's solution. | C | 7bdb68ab0752f8df94b4d5c7df759dfb | 18dc8540a25b7993a9105e115e0e71d4 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"brute force",
"math"
] | 1530628500 | ["4 3\n3 4 1 2"] | null | PASSED | 1,300 | standard input | 4 seconds | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 5000$$$) — the number of days in the given period, and the minimum number of days in a segment we consider when calculating heat intensity value, respectively. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le 5000$$$) — the temperature measures during given $$$n$$$ days. | ["2.666666666666667"] | #include <stdio.h>
#include <stdlib.h>
int main(void)
{
int n, k, x;
int max = 0, maxn = 1;
scanf("%d %d", &n, &k);
int s[n + 1];
s[0] = 0;
for (int i = 1; i <= n; i++){
scanf("%d", &x);
s[i] = s[i - 1] + x;
}
/*for (int i = 0; i <= n; i++){
printf("%d ", s[i]);
}*/
for (int i = 0; i <= n - k; i++){
for (int j = i + k; j <= n; j++){
x = s[j] - s[i];
if ((long long int) x * maxn > (long long int) max * (j - i)){
max = x;
maxn = j - i;
}
}
}
printf("%.10lf", (double) max / maxn);
return 0;
}
| |
The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually calculate some value which would represent how high the temperatures are.Mathematicians of Berland State University came up with a special heat intensity value. This value is calculated as follows:Suppose we want to analyze the segment of $$$n$$$ consecutive days. We have measured the temperatures during these $$$n$$$ days; the temperature during $$$i$$$-th day equals $$$a_i$$$.We denote the average temperature of a segment of some consecutive days as the arithmetic mean of the temperature measures during this segment of days. So, if we want to analyze the average temperature from day $$$x$$$ to day $$$y$$$, we calculate it as $$$\frac{\sum \limits_{i = x}^{y} a_i}{y - x + 1}$$$ (note that division is performed without any rounding). The heat intensity value is the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. For example, if analyzing the measures $$$[3, 4, 1, 2]$$$ and $$$k = 3$$$, we are interested in segments $$$[3, 4, 1]$$$, $$$[4, 1, 2]$$$ and $$$[3, 4, 1, 2]$$$ (we want to find the maximum value of average temperature over these segments).You have been hired by Berland State University to write a program that would compute the heat intensity value of a given period of days. Are you up to this task? | Print one real number — the heat intensity value, i. e., the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. Your answer will be considered correct if the following condition holds: $$$|res - res_0| < 10^{-6}$$$, where $$$res$$$ is your answer, and $$$res_0$$$ is the answer given by the jury's solution. | C | 7bdb68ab0752f8df94b4d5c7df759dfb | 5de9b7f230518b93173ae2e4713f740c | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"brute force",
"math"
] | 1530628500 | ["4 3\n3 4 1 2"] | null | PASSED | 1,300 | standard input | 4 seconds | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 5000$$$) — the number of days in the given period, and the minimum number of days in a segment we consider when calculating heat intensity value, respectively. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le 5000$$$) — the temperature measures during given $$$n$$$ days. | ["2.666666666666667"] | #include <stdio.h>
int main(void)
{
int n,k,num[5001],cum[5001]={0};
double max=0, con[5001],temp;
int i,j;
scanf("%d%d%d",&n,&k,&num[0]);
cum[0]=num[0];
for(i=1;i<n;++i){
scanf("%d",&num[i]);
cum[i] = cum[i-1]+num[i];
}
cum[-1]=0;
for(i=0;i<n;++i){
for(j=i+k-1;j<n;++j){
temp = ((cum[j]-cum[i-1])*1.0)/(j-i+1);
//printf("%lf ",temp);
if(temp>max) max=temp;
}
}
//for(i=0;i<n;++i) printf("\n%d ",cum[i]);
printf("%.13f",max);
return 0;
}
| |
The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually calculate some value which would represent how high the temperatures are.Mathematicians of Berland State University came up with a special heat intensity value. This value is calculated as follows:Suppose we want to analyze the segment of $$$n$$$ consecutive days. We have measured the temperatures during these $$$n$$$ days; the temperature during $$$i$$$-th day equals $$$a_i$$$.We denote the average temperature of a segment of some consecutive days as the arithmetic mean of the temperature measures during this segment of days. So, if we want to analyze the average temperature from day $$$x$$$ to day $$$y$$$, we calculate it as $$$\frac{\sum \limits_{i = x}^{y} a_i}{y - x + 1}$$$ (note that division is performed without any rounding). The heat intensity value is the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. For example, if analyzing the measures $$$[3, 4, 1, 2]$$$ and $$$k = 3$$$, we are interested in segments $$$[3, 4, 1]$$$, $$$[4, 1, 2]$$$ and $$$[3, 4, 1, 2]$$$ (we want to find the maximum value of average temperature over these segments).You have been hired by Berland State University to write a program that would compute the heat intensity value of a given period of days. Are you up to this task? | Print one real number — the heat intensity value, i. e., the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. Your answer will be considered correct if the following condition holds: $$$|res - res_0| < 10^{-6}$$$, where $$$res$$$ is your answer, and $$$res_0$$$ is the answer given by the jury's solution. | C | 7bdb68ab0752f8df94b4d5c7df759dfb | 3a6ac8e00b92146c8d3f5aa7bb627004 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"brute force",
"math"
] | 1530628500 | ["4 3\n3 4 1 2"] | null | PASSED | 1,300 | standard input | 4 seconds | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 5000$$$) — the number of days in the given period, and the minimum number of days in a segment we consider when calculating heat intensity value, respectively. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le 5000$$$) — the temperature measures during given $$$n$$$ days. | ["2.666666666666667"] | #include<stdio.h>
int a[5007],n,k;
int x[5007];
void run(){
int i,j;
double l,r;
while(scanf("%d%d",&n,&k)!=EOF){
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
for(i=0;i<n;i++){
x[i]=0;
}
x[0]=a[0];
for(i=1;i<n;i++){
x[i]=x[i-1]+a[i];
}
r=0;
for(i=0;i<n;i++){
for(j=i;j<n;j++){
if(j-i+1<k){
continue;
}
l=(double)(x[j]-(i-1>=0?x[i-1]:0))/(j-i+1);
if(r<l){
r=l;
}
}
}
printf("%.15f\n",r);
}
}
main(){
#ifndef ONLINE_JUDGE
freopen("4943c_min.in","rb",stdin);
freopen("4943c_.out","wb",stdout);
#endif
run();
return 0;
}
| |
The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually calculate some value which would represent how high the temperatures are.Mathematicians of Berland State University came up with a special heat intensity value. This value is calculated as follows:Suppose we want to analyze the segment of $$$n$$$ consecutive days. We have measured the temperatures during these $$$n$$$ days; the temperature during $$$i$$$-th day equals $$$a_i$$$.We denote the average temperature of a segment of some consecutive days as the arithmetic mean of the temperature measures during this segment of days. So, if we want to analyze the average temperature from day $$$x$$$ to day $$$y$$$, we calculate it as $$$\frac{\sum \limits_{i = x}^{y} a_i}{y - x + 1}$$$ (note that division is performed without any rounding). The heat intensity value is the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. For example, if analyzing the measures $$$[3, 4, 1, 2]$$$ and $$$k = 3$$$, we are interested in segments $$$[3, 4, 1]$$$, $$$[4, 1, 2]$$$ and $$$[3, 4, 1, 2]$$$ (we want to find the maximum value of average temperature over these segments).You have been hired by Berland State University to write a program that would compute the heat intensity value of a given period of days. Are you up to this task? | Print one real number — the heat intensity value, i. e., the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. Your answer will be considered correct if the following condition holds: $$$|res - res_0| < 10^{-6}$$$, where $$$res$$$ is your answer, and $$$res_0$$$ is the answer given by the jury's solution. | C | 7bdb68ab0752f8df94b4d5c7df759dfb | 90c039c754e9079d5345bcc1415b6b42 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"brute force",
"math"
] | 1530628500 | ["4 3\n3 4 1 2"] | null | PASSED | 1,300 | standard input | 4 seconds | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 5000$$$) — the number of days in the given period, and the minimum number of days in a segment we consider when calculating heat intensity value, respectively. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le 5000$$$) — the temperature measures during given $$$n$$$ days. | ["2.666666666666667"] | #include<stdio.h>
int a[5007],n,k;
int x[5007];
void run(){
int i,j;
double l,r;
while(scanf("%d%d",&n,&k)!=EOF){
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
x[0]=a[0];
for(i=1;i<n;i++){
x[i]=x[i-1]+a[i];
}
r=0;
for(i=0;i<n;i++){
for(j=i;j<n;j++){
if(j-i+1<k){
continue;
}
l=(double)(x[j]-(i-1>=0?x[i-1]:0))/(j-i+1);
if(r<l){
r=l;
}
}
}
printf("%.15f\n",r);
}
}
main(){
#ifndef ONLINE_JUDGE
freopen("4943c_min.in","rb",stdin);
freopen("4943c_.out","wb",stdout);
#endif
run();
return 0;
}
| |
The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually calculate some value which would represent how high the temperatures are.Mathematicians of Berland State University came up with a special heat intensity value. This value is calculated as follows:Suppose we want to analyze the segment of $$$n$$$ consecutive days. We have measured the temperatures during these $$$n$$$ days; the temperature during $$$i$$$-th day equals $$$a_i$$$.We denote the average temperature of a segment of some consecutive days as the arithmetic mean of the temperature measures during this segment of days. So, if we want to analyze the average temperature from day $$$x$$$ to day $$$y$$$, we calculate it as $$$\frac{\sum \limits_{i = x}^{y} a_i}{y - x + 1}$$$ (note that division is performed without any rounding). The heat intensity value is the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. For example, if analyzing the measures $$$[3, 4, 1, 2]$$$ and $$$k = 3$$$, we are interested in segments $$$[3, 4, 1]$$$, $$$[4, 1, 2]$$$ and $$$[3, 4, 1, 2]$$$ (we want to find the maximum value of average temperature over these segments).You have been hired by Berland State University to write a program that would compute the heat intensity value of a given period of days. Are you up to this task? | Print one real number — the heat intensity value, i. e., the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. Your answer will be considered correct if the following condition holds: $$$|res - res_0| < 10^{-6}$$$, where $$$res$$$ is your answer, and $$$res_0$$$ is the answer given by the jury's solution. | C | 7bdb68ab0752f8df94b4d5c7df759dfb | 1947f6478e60865c9c3f79f1db7bd6d2 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"brute force",
"math"
] | 1530628500 | ["4 3\n3 4 1 2"] | null | PASSED | 1,300 | standard input | 4 seconds | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 5000$$$) — the number of days in the given period, and the minimum number of days in a segment we consider when calculating heat intensity value, respectively. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le 5000$$$) — the temperature measures during given $$$n$$$ days. | ["2.666666666666667"] | #include<stdio.h>
int main()
{
int n,k,i,j;
scanf("%d%d",&n,&k);
int a[n];
for(i=0;i<n;i++)
scanf("%d",&a[i]);
int p1=0,p2=k;
float max=0.0,avg,sum=0.0;
while(p1<=n-k){
p2=p1+k-1;
sum=0.0;
for(j=p1;j<=p2;j++){
sum+=a[j];
}
while(p2<n){
if(p2!=p1+k-1)
sum+=a[p2];
avg=sum/(p2-p1+1);
if(avg>max)
max=avg;
p2++;
}
p1++;
}
printf("%f\n",max);
return 0;
}
| |
The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually calculate some value which would represent how high the temperatures are.Mathematicians of Berland State University came up with a special heat intensity value. This value is calculated as follows:Suppose we want to analyze the segment of $$$n$$$ consecutive days. We have measured the temperatures during these $$$n$$$ days; the temperature during $$$i$$$-th day equals $$$a_i$$$.We denote the average temperature of a segment of some consecutive days as the arithmetic mean of the temperature measures during this segment of days. So, if we want to analyze the average temperature from day $$$x$$$ to day $$$y$$$, we calculate it as $$$\frac{\sum \limits_{i = x}^{y} a_i}{y - x + 1}$$$ (note that division is performed without any rounding). The heat intensity value is the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. For example, if analyzing the measures $$$[3, 4, 1, 2]$$$ and $$$k = 3$$$, we are interested in segments $$$[3, 4, 1]$$$, $$$[4, 1, 2]$$$ and $$$[3, 4, 1, 2]$$$ (we want to find the maximum value of average temperature over these segments).You have been hired by Berland State University to write a program that would compute the heat intensity value of a given period of days. Are you up to this task? | Print one real number — the heat intensity value, i. e., the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. Your answer will be considered correct if the following condition holds: $$$|res - res_0| < 10^{-6}$$$, where $$$res$$$ is your answer, and $$$res_0$$$ is the answer given by the jury's solution. | C | 7bdb68ab0752f8df94b4d5c7df759dfb | 9648482a4aacc24369e051fcd2e41107 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"brute force",
"math"
] | 1530628500 | ["4 3\n3 4 1 2"] | null | PASSED | 1,300 | standard input | 4 seconds | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 5000$$$) — the number of days in the given period, and the minimum number of days in a segment we consider when calculating heat intensity value, respectively. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le 5000$$$) — the temperature measures during given $$$n$$$ days. | ["2.666666666666667"] | #define _USE_MATH_DEFINES
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdbool.h>
#include <float.h>
#include <limits.h>
#include <malloc.h>
#include <memory.h>
#include <complex.h>
#include <errno.h>
#include <time.h>
#define Max(X,Y) ((X)>(Y) ? (X) : (Y))
#define Min(X,Y) ((X)<(Y) ? (X) : (Y))
#define MOD 998244353
#define N 5005
int n,m,i,j,a[N];
long long s[N];
double sum,ans;
int main()
{
scanf("%d %d",&n,&m);
for (i=1,s[0]=0;i<=n;i++)
{
scanf("%d",&a[i]);
s[i]=(long long) s[i-1]+a[i];
}
for (i=m,ans=INT_MIN;i<=n;i++)
{
for (j=0;j<=n-i;j++)
{
sum=(double) s[j+i]-s[j];
sum/=(double) i;
ans=Max(ans,sum);
}
}
printf("%0.15lf\n",ans);
return 0;
}
| |
The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually calculate some value which would represent how high the temperatures are.Mathematicians of Berland State University came up with a special heat intensity value. This value is calculated as follows:Suppose we want to analyze the segment of $$$n$$$ consecutive days. We have measured the temperatures during these $$$n$$$ days; the temperature during $$$i$$$-th day equals $$$a_i$$$.We denote the average temperature of a segment of some consecutive days as the arithmetic mean of the temperature measures during this segment of days. So, if we want to analyze the average temperature from day $$$x$$$ to day $$$y$$$, we calculate it as $$$\frac{\sum \limits_{i = x}^{y} a_i}{y - x + 1}$$$ (note that division is performed without any rounding). The heat intensity value is the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. For example, if analyzing the measures $$$[3, 4, 1, 2]$$$ and $$$k = 3$$$, we are interested in segments $$$[3, 4, 1]$$$, $$$[4, 1, 2]$$$ and $$$[3, 4, 1, 2]$$$ (we want to find the maximum value of average temperature over these segments).You have been hired by Berland State University to write a program that would compute the heat intensity value of a given period of days. Are you up to this task? | Print one real number — the heat intensity value, i. e., the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. Your answer will be considered correct if the following condition holds: $$$|res - res_0| < 10^{-6}$$$, where $$$res$$$ is your answer, and $$$res_0$$$ is the answer given by the jury's solution. | C | 7bdb68ab0752f8df94b4d5c7df759dfb | b8daa7c57a7cd4684c1793f9248ff165 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"brute force",
"math"
] | 1530628500 | ["4 3\n3 4 1 2"] | null | PASSED | 1,300 | standard input | 4 seconds | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 5000$$$) — the number of days in the given period, and the minimum number of days in a segment we consider when calculating heat intensity value, respectively. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le 5000$$$) — the temperature measures during given $$$n$$$ days. | ["2.666666666666667"] | #include<stdio.h>
#include<string.h>
#define sc(x) {register char c7=getchar(),v7=1;for(x=0;c7<48||c7>57;c7=getchar())if(c7==45)v7=-1;for(;c7>=48&&c7<=57;x=(x<<1)+(x<<3)+c7-48,c7=getchar());x*=v7;}
int a[5678], _s[5678], *s = _s+1;
int main()
{
int n, k, now, i, j, ub, up, cnt;
double avr, sum;
sc(n)sc(k)
for(i=0; i<n; i++)
{
sc(a[i])
s[i] = s[i-1]+a[i];
}
int p=1, max=0;
for(i=k; i<=n; i++)
for(j=0; j<=n-i; j++)
{
int t=s[j+i-1]-s[j-1];
if((double)t/i>(double)max/p)
max=t,p=i;
}
printf("%.8lf\n",1.0*max/p);
}
| |
The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually calculate some value which would represent how high the temperatures are.Mathematicians of Berland State University came up with a special heat intensity value. This value is calculated as follows:Suppose we want to analyze the segment of $$$n$$$ consecutive days. We have measured the temperatures during these $$$n$$$ days; the temperature during $$$i$$$-th day equals $$$a_i$$$.We denote the average temperature of a segment of some consecutive days as the arithmetic mean of the temperature measures during this segment of days. So, if we want to analyze the average temperature from day $$$x$$$ to day $$$y$$$, we calculate it as $$$\frac{\sum \limits_{i = x}^{y} a_i}{y - x + 1}$$$ (note that division is performed without any rounding). The heat intensity value is the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. For example, if analyzing the measures $$$[3, 4, 1, 2]$$$ and $$$k = 3$$$, we are interested in segments $$$[3, 4, 1]$$$, $$$[4, 1, 2]$$$ and $$$[3, 4, 1, 2]$$$ (we want to find the maximum value of average temperature over these segments).You have been hired by Berland State University to write a program that would compute the heat intensity value of a given period of days. Are you up to this task? | Print one real number — the heat intensity value, i. e., the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. Your answer will be considered correct if the following condition holds: $$$|res - res_0| < 10^{-6}$$$, where $$$res$$$ is your answer, and $$$res_0$$$ is the answer given by the jury's solution. | C | 7bdb68ab0752f8df94b4d5c7df759dfb | 72f8759d99049bc697f2ac24ff6598ef | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"brute force",
"math"
] | 1530628500 | ["4 3\n3 4 1 2"] | null | PASSED | 1,300 | standard input | 4 seconds | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 5000$$$) — the number of days in the given period, and the minimum number of days in a segment we consider when calculating heat intensity value, respectively. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le 5000$$$) — the temperature measures during given $$$n$$$ days. | ["2.666666666666667"] | #include <stdio.h>
#include <stdlib.h>
double sum[10000];
int main()
{
double n, k, i, j, m;
scanf("%lf%lf", &n, &k);
n++;
m=-100;
for(i=1; i<n; i++)
{
scanf("%lf", &sum[(int)i]);
sum[(int)i]+=sum[(int)i-1];
}
for(i=k; i<n; i++)
{
for(j=i; j<n; j++)
{
if((sum[(int)j]-sum[(int)j-(int)i])/i>m)m=(sum[(int)j]-sum[(int)j-(int)i])/i;
}
}
printf("%.15lf", m);
return 0;
} | |
The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually calculate some value which would represent how high the temperatures are.Mathematicians of Berland State University came up with a special heat intensity value. This value is calculated as follows:Suppose we want to analyze the segment of $$$n$$$ consecutive days. We have measured the temperatures during these $$$n$$$ days; the temperature during $$$i$$$-th day equals $$$a_i$$$.We denote the average temperature of a segment of some consecutive days as the arithmetic mean of the temperature measures during this segment of days. So, if we want to analyze the average temperature from day $$$x$$$ to day $$$y$$$, we calculate it as $$$\frac{\sum \limits_{i = x}^{y} a_i}{y - x + 1}$$$ (note that division is performed without any rounding). The heat intensity value is the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. For example, if analyzing the measures $$$[3, 4, 1, 2]$$$ and $$$k = 3$$$, we are interested in segments $$$[3, 4, 1]$$$, $$$[4, 1, 2]$$$ and $$$[3, 4, 1, 2]$$$ (we want to find the maximum value of average temperature over these segments).You have been hired by Berland State University to write a program that would compute the heat intensity value of a given period of days. Are you up to this task? | Print one real number — the heat intensity value, i. e., the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. Your answer will be considered correct if the following condition holds: $$$|res - res_0| < 10^{-6}$$$, where $$$res$$$ is your answer, and $$$res_0$$$ is the answer given by the jury's solution. | C | 7bdb68ab0752f8df94b4d5c7df759dfb | 724131238bd59bd4536b5dd9b62fc05c | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"brute force",
"math"
] | 1530628500 | ["4 3\n3 4 1 2"] | null | PASSED | 1,300 | standard input | 4 seconds | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 5000$$$) — the number of days in the given period, and the minimum number of days in a segment we consider when calculating heat intensity value, respectively. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le 5000$$$) — the temperature measures during given $$$n$$$ days. | ["2.666666666666667"] | #include<stdio.h>
#include<stdlib.h>
int main()
{
int n,k,i,j,l;
scanf("%d %d",&n,&k);
int *a=(int*)malloc(sizeof(int)*n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
double max=0;
for(i=k;i<=n;i++)
{
double sum=0;
for(j=0;j<n-i+1;j++)
{
if(j==0)
{
for(l=0;l<i;l++)
sum+=a[l];
}
else{
sum-=a[j-1];
sum+=a[j+i-1];
}
double i1=i;
double temp=sum/i1;
if(temp>max)
max=temp;
}
}
printf("%.15lf",max);
}
| |
The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually calculate some value which would represent how high the temperatures are.Mathematicians of Berland State University came up with a special heat intensity value. This value is calculated as follows:Suppose we want to analyze the segment of $$$n$$$ consecutive days. We have measured the temperatures during these $$$n$$$ days; the temperature during $$$i$$$-th day equals $$$a_i$$$.We denote the average temperature of a segment of some consecutive days as the arithmetic mean of the temperature measures during this segment of days. So, if we want to analyze the average temperature from day $$$x$$$ to day $$$y$$$, we calculate it as $$$\frac{\sum \limits_{i = x}^{y} a_i}{y - x + 1}$$$ (note that division is performed without any rounding). The heat intensity value is the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. For example, if analyzing the measures $$$[3, 4, 1, 2]$$$ and $$$k = 3$$$, we are interested in segments $$$[3, 4, 1]$$$, $$$[4, 1, 2]$$$ and $$$[3, 4, 1, 2]$$$ (we want to find the maximum value of average temperature over these segments).You have been hired by Berland State University to write a program that would compute the heat intensity value of a given period of days. Are you up to this task? | Print one real number — the heat intensity value, i. e., the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. Your answer will be considered correct if the following condition holds: $$$|res - res_0| < 10^{-6}$$$, where $$$res$$$ is your answer, and $$$res_0$$$ is the answer given by the jury's solution. | C | 7bdb68ab0752f8df94b4d5c7df759dfb | da662a6b843a0a3e125bdf50994a8b4c | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"brute force",
"math"
] | 1530628500 | ["4 3\n3 4 1 2"] | null | PASSED | 1,300 | standard input | 4 seconds | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 5000$$$) — the number of days in the given period, and the minimum number of days in a segment we consider when calculating heat intensity value, respectively. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le 5000$$$) — the temperature measures during given $$$n$$$ days. | ["2.666666666666667"] | #include<stdio.h>
int main()
{
double n, k;
double num[5000]={0,}, sum[5000]={0,};
scanf("%lf %lf", &n, &k);
for(int i=0; i<n; i++) scanf("%lf", &num[i]);
for(int i=k; i<=n; i++){
int ssum=0;
for(int j=0; j<i; j++){
ssum+=num[j];
}
sum[i]=ssum;
for(int j=0; j<n-i; j++){
ssum=ssum-num[j]+num[j+i];
if(sum[i]<ssum) sum[i]=ssum;
}
}
double max=0;
for(int i=k; i<=n; i++){
if(max<sum[i]/(double)i){
max=sum[i]/(double)i;
}
}
printf("%lf", max);
} | |
The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually calculate some value which would represent how high the temperatures are.Mathematicians of Berland State University came up with a special heat intensity value. This value is calculated as follows:Suppose we want to analyze the segment of $$$n$$$ consecutive days. We have measured the temperatures during these $$$n$$$ days; the temperature during $$$i$$$-th day equals $$$a_i$$$.We denote the average temperature of a segment of some consecutive days as the arithmetic mean of the temperature measures during this segment of days. So, if we want to analyze the average temperature from day $$$x$$$ to day $$$y$$$, we calculate it as $$$\frac{\sum \limits_{i = x}^{y} a_i}{y - x + 1}$$$ (note that division is performed without any rounding). The heat intensity value is the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. For example, if analyzing the measures $$$[3, 4, 1, 2]$$$ and $$$k = 3$$$, we are interested in segments $$$[3, 4, 1]$$$, $$$[4, 1, 2]$$$ and $$$[3, 4, 1, 2]$$$ (we want to find the maximum value of average temperature over these segments).You have been hired by Berland State University to write a program that would compute the heat intensity value of a given period of days. Are you up to this task? | Print one real number — the heat intensity value, i. e., the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. Your answer will be considered correct if the following condition holds: $$$|res - res_0| < 10^{-6}$$$, where $$$res$$$ is your answer, and $$$res_0$$$ is the answer given by the jury's solution. | C | 7bdb68ab0752f8df94b4d5c7df759dfb | f353971d302da90ef9c0f502b4d3879d | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"brute force",
"math"
] | 1530628500 | ["4 3\n3 4 1 2"] | null | PASSED | 1,300 | standard input | 4 seconds | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 5000$$$) — the number of days in the given period, and the minimum number of days in a segment we consider when calculating heat intensity value, respectively. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le 5000$$$) — the temperature measures during given $$$n$$$ days. | ["2.666666666666667"] | #include <stdio.h>
int main(){
int i, k, n, temp[5000], sum[5001], c, dlina,nachalo ;
float max, z;
scanf("%d%d", &n, &k);
for(i=0; i < n; ++i){
scanf("%d", &temp[i]);
}
c = 0;
for(i=0; i < n; ++i){
c += temp[i];
sum[i+1] = c;
}
sum[0]=0;
max = 0;
for(dlina = n; dlina >= k; dlina--){
for( nachalo = 1; nachalo+dlina-1 <= n;nachalo++){
z =(sum[nachalo+dlina-1]-sum[nachalo-1])/(float)dlina;
if (max < z){
max = z;
}
}
}
printf("%f", max);
return 0;
}
| |
The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually calculate some value which would represent how high the temperatures are.Mathematicians of Berland State University came up with a special heat intensity value. This value is calculated as follows:Suppose we want to analyze the segment of $$$n$$$ consecutive days. We have measured the temperatures during these $$$n$$$ days; the temperature during $$$i$$$-th day equals $$$a_i$$$.We denote the average temperature of a segment of some consecutive days as the arithmetic mean of the temperature measures during this segment of days. So, if we want to analyze the average temperature from day $$$x$$$ to day $$$y$$$, we calculate it as $$$\frac{\sum \limits_{i = x}^{y} a_i}{y - x + 1}$$$ (note that division is performed without any rounding). The heat intensity value is the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. For example, if analyzing the measures $$$[3, 4, 1, 2]$$$ and $$$k = 3$$$, we are interested in segments $$$[3, 4, 1]$$$, $$$[4, 1, 2]$$$ and $$$[3, 4, 1, 2]$$$ (we want to find the maximum value of average temperature over these segments).You have been hired by Berland State University to write a program that would compute the heat intensity value of a given period of days. Are you up to this task? | Print one real number — the heat intensity value, i. e., the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. Your answer will be considered correct if the following condition holds: $$$|res - res_0| < 10^{-6}$$$, where $$$res$$$ is your answer, and $$$res_0$$$ is the answer given by the jury's solution. | C | 7bdb68ab0752f8df94b4d5c7df759dfb | 9e59f4ee0c26e9ff22d07c5fba626c63 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"brute force",
"math"
] | 1530628500 | ["4 3\n3 4 1 2"] | null | PASSED | 1,300 | standard input | 4 seconds | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 5000$$$) — the number of days in the given period, and the minimum number of days in a segment we consider when calculating heat intensity value, respectively. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le 5000$$$) — the temperature measures during given $$$n$$$ days. | ["2.666666666666667"] | #include <stdio.h>
int main()
{
int i, j, l, n, k;
float av, max=0, sum;
scanf("%d %d", &n, &k);
int arr[n];
for(i=0; i<n; i++)
scanf("%d", &arr[i]);
for(i=0; i<n; i++)
{
sum=0;
av=0;
for(j=i; j<n; j++)
{
sum+=arr[j];
if(j-i>=k-1)
av=sum/(j-i+1);
if(av>max)
max=av;
}
}
printf("%0.8f", max);
return 0;
} | |
The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually calculate some value which would represent how high the temperatures are.Mathematicians of Berland State University came up with a special heat intensity value. This value is calculated as follows:Suppose we want to analyze the segment of $$$n$$$ consecutive days. We have measured the temperatures during these $$$n$$$ days; the temperature during $$$i$$$-th day equals $$$a_i$$$.We denote the average temperature of a segment of some consecutive days as the arithmetic mean of the temperature measures during this segment of days. So, if we want to analyze the average temperature from day $$$x$$$ to day $$$y$$$, we calculate it as $$$\frac{\sum \limits_{i = x}^{y} a_i}{y - x + 1}$$$ (note that division is performed without any rounding). The heat intensity value is the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. For example, if analyzing the measures $$$[3, 4, 1, 2]$$$ and $$$k = 3$$$, we are interested in segments $$$[3, 4, 1]$$$, $$$[4, 1, 2]$$$ and $$$[3, 4, 1, 2]$$$ (we want to find the maximum value of average temperature over these segments).You have been hired by Berland State University to write a program that would compute the heat intensity value of a given period of days. Are you up to this task? | Print one real number — the heat intensity value, i. e., the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. Your answer will be considered correct if the following condition holds: $$$|res - res_0| < 10^{-6}$$$, where $$$res$$$ is your answer, and $$$res_0$$$ is the answer given by the jury's solution. | C | 7bdb68ab0752f8df94b4d5c7df759dfb | e8b459abdae42bb0476d5ad96d2ca7ea | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"brute force",
"math"
] | 1530628500 | ["4 3\n3 4 1 2"] | null | PASSED | 1,300 | standard input | 4 seconds | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 5000$$$) — the number of days in the given period, and the minimum number of days in a segment we consider when calculating heat intensity value, respectively. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le 5000$$$) — the temperature measures during given $$$n$$$ days. | ["2.666666666666667"] | #include<stdio.h>
#include<string.h>
#include<stdlib.h>
double calc_hiv(int *arr,int i,int k);
int main(){
int n,k;
scanf("%d%d",&n,&k);
int arr[n];
for(int i=0;i<n;i++){
scanf("%d",&arr[i]);
}
double hiv=0;
double sum=0,temphiv=0;
for(int i=0;i<n;i++){
sum=0;
for(int j=i;j<n;j++){
sum+=arr[j];
if((j-i+1)>=k){
temphiv=sum/(j-i+1);
if(temphiv>hiv){
hiv=temphiv;
}
}
}
}
printf("%.9lf\n",hiv);
return 0;
}
double calc_hiv(int *arr,int i,int k){
double res;
double sum=0;
for(int count =0;count<k;count++){
sum=sum+arr[i+count];
}
res = sum/k;
return res;
}
| |
The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually calculate some value which would represent how high the temperatures are.Mathematicians of Berland State University came up with a special heat intensity value. This value is calculated as follows:Suppose we want to analyze the segment of $$$n$$$ consecutive days. We have measured the temperatures during these $$$n$$$ days; the temperature during $$$i$$$-th day equals $$$a_i$$$.We denote the average temperature of a segment of some consecutive days as the arithmetic mean of the temperature measures during this segment of days. So, if we want to analyze the average temperature from day $$$x$$$ to day $$$y$$$, we calculate it as $$$\frac{\sum \limits_{i = x}^{y} a_i}{y - x + 1}$$$ (note that division is performed without any rounding). The heat intensity value is the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. For example, if analyzing the measures $$$[3, 4, 1, 2]$$$ and $$$k = 3$$$, we are interested in segments $$$[3, 4, 1]$$$, $$$[4, 1, 2]$$$ and $$$[3, 4, 1, 2]$$$ (we want to find the maximum value of average temperature over these segments).You have been hired by Berland State University to write a program that would compute the heat intensity value of a given period of days. Are you up to this task? | Print one real number — the heat intensity value, i. e., the maximum of average temperatures over all segments of not less than $$$k$$$ consecutive days. Your answer will be considered correct if the following condition holds: $$$|res - res_0| < 10^{-6}$$$, where $$$res$$$ is your answer, and $$$res_0$$$ is the answer given by the jury's solution. | C | 7bdb68ab0752f8df94b4d5c7df759dfb | 596ff2e844a8de30ae9b1b33e0454c7e | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"brute force",
"math"
] | 1530628500 | ["4 3\n3 4 1 2"] | null | PASSED | 1,300 | standard input | 4 seconds | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 5000$$$) — the number of days in the given period, and the minimum number of days in a segment we consider when calculating heat intensity value, respectively. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le 5000$$$) — the temperature measures during given $$$n$$$ days. | ["2.666666666666667"] | #include<stdio.h>
#define SIZE 5010
int tree[SIZE * 8];
int start_i, tree_size;
double ans = 0;
int make_tree(int cur_idx) {
if (cur_idx >= start_i) {
return tree[cur_idx];
}
return tree[cur_idx] = make_tree(cur_idx * 2) + make_tree(cur_idx * 2 + 1);
}
int getSum(int cur_idx, int ql, int qr, int cl, int cr) {
if ((ql<=cl && qr>=cr))
return tree[cur_idx];
if (qr<cl || ql>cr)
return 0;
int mid = (cl + cr) / 2;
return getSum(cur_idx * 2, ql, qr, cl, mid) + getSum(cur_idx * 2 + 1, ql, qr, mid + 1, cr);
}
int main() {
int n, k; scanf("%d %d", &n, &k);
for (start_i = 1; start_i < n; start_i *= 2);
tree_size = start_i * 2;
for (int i = 0; i < n; i++) {
scanf("%d", &tree[start_i + i]);
}
make_tree(1);
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++)
if (j - i + 1 >= k) {
double avg = getSum(1, i, j, 1, start_i) / (double)(j - i + 1);
if (avg > ans) {
ans = avg;
}
}
}
printf("%lf\n", ans);
return 0;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.