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
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
c0a6e19401d4b00ccb42ddecfa48308c
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include<stdio.h> #include<stdlib.h> typedef long long int lli; int cmpfunc(const void *a, const void *b){ return(*(int*)a - *(int*)b); } int main() { int m,n; scanf("%d %d", &m, &n); int ans=0; int arr[m]; for(int i=0;i<m;i++){ scanf("%d", &arr[i]); } qsort(arr,m,sizeof(int), cmpfunc); int x=0; while(n--){ if(arr[x]<0){ ans = ans+ abs(arr[x]); x++; } else if(arr[x]==0 || arr[x]>0){ break; } } printf("%d\n", ans); return 0; }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
8ee511f941b8eae5d5d54df4b638a5bd
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include <stdio.h> int main() { int n,m,temp,sum=0; scanf("%d%d",&n,&m); int a[n]; for(int i=0;i<n;i++) { scanf("%d",&a[i]); } for(int i=0;i<n-1;i++) { for(int j=i+1;j<n;j++) { if(a[i]>a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } } for(int i=0;i<m;i++) { if(a[i]<=0) { sum=sum+a[i]; } } printf("%d ",-sum); return 0; }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
bb41e069f707489e1072bf9ae791853f
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> #include<limits.h> #define MOD 1000000007 #define MAX(a, b) (a>b?a:b) #define MIN(a, b) (a<b?a:b) int compare(const void* a, const void* b) { return *(int*)a-*(int*)b; } int abs(int n) { if(n < 0) return n*(-1); return n; } void swap(char s[], int n, int m) { char temp = s[m]; s[m] = s[n]; s[n] = temp; } long long int binSearch(long long int a[], int n, int l, int r, long long int x) { if(l > r) return -1; int mid = l+((r-l)>>1); if(a[mid] >= x && a[mid-1] < x) return mid; if(x > a[mid]) return binSearch(a, n, mid+1, r, x); return binSearch(a, n, l, mid-1, x); } void testCase() { int n, m; scanf("%d%d", &n, &m); int a[n], i, x, j=0, res=0; for(i=0;i<n;i++) { scanf("%d", &x); if(x < 0) a[j++] = x; } qsort(a, j, sizeof(a[0]), compare); for(i=0;i<j;i++) { if(i == m) break; res += (a[i]*(-1)); } printf("%d\n", res); } int main() { int t=1; // scanf("%d", &t); while(t--) { testCase(); } return 0; }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
be579bbaab3ec03e9919d78fd9dde706
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include<stdio.h> #include<string.h> int main() { int i,j, n, m, swapped, sum=0; int a[101], b[101], temp; scanf("%d %d", &n, &m); for(i=0; i<n; i++) scanf("%d", &b[i]); for(i=0; i<n-1; i++) { for(j=0; j<n-1-i; j++) { if(b[j]>b[j+1]) { temp=b[j]; b[j]=b[j+1]; b[j+1]=temp; } } } for(j=0; j<m; j++) { if(b[j]<1) sum+=(b[j])*(-1); } printf("%d", sum); return 0; }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
285154983afa3b726b12eda735634af0
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include <stdio.h> int main (){ int n,m,total = 0; scanf ("%d %d",&n,&m); int price[n]; for (int i = 0;i<n;i++){ scanf ("%d",&price[i]); } for (int i = 0;i<n;i++){ for (int j = 0;j<n-1;j++){ if (price[j] > price[j+1]){ int temp = price[j]; price[j] = price[j+1]; price[j+1] = temp; } } } for (int i = 0;i<m;i++){ if (price[i] <= 0){ total += price[i] * -1; } } printf ("%d",total); return 0; }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
5da3cbdbc4bca583b239624d43359cb1
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include<stdio.h> int main(){ int n,m,a[1004],ne[123],k=0,s=0,t; scanf("%d %d",&n,&m); for(int i=0;i<n;i++){ scanf("%d",&a[i]); } for(int i=0;i<n;i++){ if(a[i]<0){ ne[k]=a[i]; k++; } } for(int i=0;i<k;i++){ for(int j=0;j<k-i;j++){ if(ne[j]>ne[j+1]){ t=ne[j]; ne[j]=ne[j+1]; ne[j+1]=t; } } } for(int i=0;i<m;i++){ s=s-ne[i]; } printf("%d\n",s); return 0; }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
ef6b17c028e0e9d58559ae8cc369f933
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include<stdio.h> int main() { int n, m, i, j, k, sum = 0, temp; scanf("%d%d",&n,&m); int a[n+1], b[m+1]; for(i = 1, j = 1; i <= n; i++){ scanf("%d",&a[i]); if(a[i] < 0){ b[j] = a[i]; j++; } } for(i = 1; i < j; i++){ for(k = 1; k < j - i; k++ ){ if(b[k] > b[k+1]){ temp = b[k]; b[k] = b[k+1]; b[k+1] = temp; } } } if(j <= m){ for(i = 1; i < j; i++){ sum = sum + b[i]; } } if(j > m){ for(i = 1; i <= m; i++){ sum = sum + b[i]; } } sum = 0 - sum; printf("%d\n",sum); return 0; }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
6f7ee430f37337d05ed313264f96b50a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include <stdio.h> #include <stdlib.h> int ordena( const void *x, const void *y){ int a = *((int *) x); int b = *((int *) y); if(a < b) return -1; if(a > b) return 1; return 0; } int main(){ int n, x; int total = 0; scanf("%d %d", &n, &x); int v[n]; for(int i = 0; i < n; ++i) scanf("%d", &v[i]); qsort (v, n, sizeof(v[0]), ordena); for(int i = 0; i < x; ++i){ if(v[i] < 0){ v[i] = -1*v[i]; total += v[i]; } } printf("%d\n", total); return 0; }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
6bcb33893f324d6ff9d723ca6c682201
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
//Bismillahir Rahmanir Rahim #include<stdio.h> int main() { int x,y,i,s[100],j,temp,sum=0; scanf("%d%d",&x,&y); for(i=1; i<=x; i++) { scanf("%d",&s[i]); } for(i=1; i<=x; i++) { for(j=1; j<=x; j++) { if(s[i]<=s[j]) { temp=s[i]; s[i]=s[j]; s[j]=temp; } } } for(i=1; i<=y; i++) { if(s[i]<0) sum+=s[i]; else break; } printf("%d\n",(-1)*sum); return 0; } // 5 3 -6 0 35 -2 4
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
ce473c20a0e5dc2a811b8a44586c2708
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include<stdio.h> #include<stdlib.h> int main() { int n,m,i,a[10000],sum=0,temp,j; scanf("%d%d",&n,&m); for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=0;i<n;i++) { for(j=0;j<n-i-1;j++) { if(a[j]>a[j+1]) { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } } for(i=0;i<m;i++) { if(a[i]<=0) { a[i]=abs(a[i]); sum+=a[i]; } } printf("%d\n",sum); return 0; }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
48e86c886a8a0dd35159c0e6178af75a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include<stdio.h> #include<string.h> int main() { int arr[105],n,m,i,j,temp,sum=0,number; scanf("%d %d",&n,&m); for(i=0;i<n;i++) { scanf("%d",&arr[i]); } for(i=0;i<n-1;i++) { for(j=i+1;j<n;j++) { if(arr[i]>=arr[j]) { temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } } } for(i=0;i<m;i++) { number=arr[i]; if(number<0) { sum=sum+number; } } printf("%d\n",(sum*(-1))); return 0; }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
46761498d8b108f08a31449b467fe8a6
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include<stdio.h> int sort(int arr[],int n) { int i,j,a; for (i = 0; i < n; ++i) { for (j = i + 1; j < n; ++j) { if (arr[i] > arr[j]) { a = arr[i]; arr[i] = arr[j]; arr[j] = a; } } } } int main() { int n,m,i,s=0,g=0; scanf("%d%d",&n,&m); int array[n]; for (i=0;i<n;i++) { scanf("%d",&array[i]); } sort(array,n); for (i=0;i<n;i++) { if (array[i]<0) { s=s+array[i]; g=g+1; if (g>=m) break; } } s=s*(-1); printf("%d",s); return 0; }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
5826f5bb83bbd27d96acc2d6cf884e64
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include<stdio.h> #include<stdlib.h> int cmp(const void *,const void *); int fun(int [],int ,int ); int cmp(const void *a,const void *b) { return *(int *)b-*(int *)a; } int fun(int a[],int n,int m) { int i,ans=0; for(i=0;i<n;i++) { a[i]=-a[i]; } qsort(a,n,sizeof(a[i]),cmp); for(i=0;i<m;i++) { if(a[i]>0) { ans=ans+a[i]; } else { break; } } return ans; } int main() { int a[105]; int n,i,m; scanf("%d%d",&n,&m); for(i=0;i<n;i++) { scanf("%d",&a[i]); } printf("%d\n",fun(a,n,m)); return 0; }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
398e2511fa4adda59990875d68ce8a4f
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include <stdio.h> int main() { int n,m; scanf("%d %d",&n,&m); int a[n],i,j,k,l; for(i=1;i<=n;i++) scanf("%d",&a[i]); for(i=1;i<n;i++) { for(j=i+1;j<=n;j++) { if(a[i]>a[j]) { k=a[j]; a[j]=a[i]; a[i]=k; } } } l=0; for(i=1;i<=m;i++) { if(a[i]<=0) l+=a[i]; else l+=0; } printf("%d",(-l)); }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
d18c32b30added98bb5e4fde1ad9a29c
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include <stdio.h> void swap(int arr[], int a, int b); void sort(int arr[], int len); int main(void) { int n, m; scanf("%d %d", &n, &m); int a[100] = {0}; for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); } sort(a, n); int c = 0; for (int i = 0; i < m && a[i] < 0; ++i) { if (a[i] < 0) c += a[i]; } printf("%d\n", c < 0 ? -c : c); return 0; } void swap(int arr[], int a, int b) { int t = arr[a]; arr[a] = arr[b]; arr[b] = t; } void sort(int arr[], int len) { for (int i = 0; i < len; ++i) { for (int j = 0; j < len - i - 1; ++j) { if (arr[j] > arr[j + 1]) { swap(arr, j, j + 1); } } } }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
9179266ff9650c412515e239eb951b8b
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#pragma warning(disable:4996) #include <stdio.h> #include <malloc.h> #include <math.h> #include <stdlib.h> #include <string.h> #define forn(i,n) for (i = 0; i<n; i++) int lol(const void *x1, const void *x2) { return *(int*)x1 - *(int*)x2; } int gcd(int a, int b) { int c; while (b) { c = a % b; a = b; b = c; } return a; } int main(void) { int n, m, i, a[100], sum = 0; scanf("%i%i", &n, &m); forn(i, n) scanf("%i", &a[i]); qsort(a, n, sizeof(int), lol); forn(i, m) if (a[i]<0) sum += a[i]; printf("%i", -sum); return 0; }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
ce470c7bffb5c30dd3aa9da4da16c575
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include<stdio.h> int main() { int n,m,i,j,k,s=0,t; scanf("%d%d",&n,&m); int arr[n],arr1[n]; for(i=0; i<n; i++) scanf("%d",&arr[i]); for(i=0,j=0; i<n; i++) { if(arr[i]< 0) { arr1[j]= -arr[i]; j++; } } if(j<= m) { for(i=0; i<j; i++) s= s+ arr1[i]; } else { for(i=0; i<j-1; i++) { for(k=i+1; k<j; k++) { if(arr1[i]< arr1[k]) { t= arr1[i]; arr1[i]= arr1[k]; arr1[k]= t; } } } for(i=0; i<m; i++) s= s+ arr1[i]; } printf("%d",s); }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
f7a572ad01c279fa7e1ee84f9773db9b
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include <stdio.h> #include <stdlib.h> int cm(const void* a, const void* b){return *(int *)a-*(int *)b;} const int M = 102; int main(){ int n,m,i,a[M],s=0; scanf("%i%i",&n,&m); for(i=0;i<n;i++) scanf("%i",a+i); qsort(a,n,sizeof a[0],cm); for(i=0;i<m;i++) if(a[i]<0) s+=a[i]; printf("%i\n",-1*s); return 0-0-0; }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
9ceb3326833364448a033cf2e258ec4c
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include <stdio.h> #include <stdlib.h> int cmp (const void * a, const void * b) { if(*(int*)a > *(int*)b) { return 1; } if(*(int*)a < *(int*)b) { return -1; } else { return 0; } } int main() { int n, m; scanf("%d%d", &n, &m); int tv[n]; for(int i=0; i<n; i++) { scanf("%d", &tv[i]); } qsort(tv, n, sizeof(int), cmp); int sum = 0; int i = 0; while(i<m) { if(tv[i] < 0) { sum += abs(tv[i]); } i++; } printf("%d", sum); return 0; }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
bb57de764bff85b1cf07e07cbd4b8d2d
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include<stdio.h> int main() { int n,m; scanf("%d %d\n",&n,&m); int a[n],i; for(i=0;i<n;i++) scanf("%d ",&a[i]); int min,pos; for(i=0;i<n;i++) { min=a[i]; pos=i; for(int j=i;j<n;j++) { if(min>a[j]) { min=a[j]; pos=j; } } a[pos]=a[i]; a[i]=min; } int sum=0; i=0; while(a[i]<=0 && i<m) { sum+=a[i]; i++; } printf("%d",-sum); return 0; }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
569810fbcad2d273718b8c4c8a28c309
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include <stdio.h> #include <stdlib.h> #include <math.h> int cmp(const void *a,const void *b){ int *a1=(int *)a,*b1=(int *)b; return *a1-*b1; } int sets[1005],sum=0; int main() { int n,m; scanf("%d%d",&n,&m); for(int i=0;i<n;i++)scanf("%d",&sets[i]); qsort(sets,n,sizeof(int),cmp); for(int i=0;i<m&&sets[i]<0;i++)sum+=sets[i]; printf("%d\n",0-sum); return 0; }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
b928a5aefcef367a5a3039a5e0df7e99
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include <stdio.h> int main (){ int n,m,t = 0,i,j; scanf ("%d %d",&n,&m); int price[n]; for ( i = 0;i<n;i++){ scanf ("%d",&price[i]); } for ( i = 0;i<n;i++){ for ( j = 0;j<n-1-i;j++){ if (price[j] > price[j+1]){ int temp = price[j]; price[j] = price[j+1]; price[j+1] = temp; } } } for (i = 0;i<m;i++){ if (price[i] <= 0){ t += price[i] * -1; } } printf ("%d",t); return 0; }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
463e61e2bbd38b8bd1a19253e7127dc2
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include <stdio.h> int main (){ int n,m,t = 0,i,j; scanf ("%d %d",&n,&m); int price[n]; for ( i = 0;i<n;i++){ scanf ("%d",&price[i]); } for ( i = 0;i<n;i++){ for ( j = 0;j<n;j++){ if (price[j] > price[j+1]){ int temp = price[j]; price[j] = price[j+1]; price[j+1] = temp; } } } for (i = 0;i<m;i++){ if (price[i] <= 0){ t += price[i] * -1; } } printf ("%d",t); return 0; }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
c17f824106615408d95cae21f93eb7a5
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include<stdio.h> int main() { int ara[110]; int n,m; while(2==scanf("%d%d",&n,&m)) { int sum = 0,l=0,temp; for(int i =0; i<n; i++) { scanf("%d",&temp); if(temp <0) { ara[l++]=(-1*temp); } } //printf("l er man %d\n",l); for(int i =1;i<l; i++) { for(int j =i; j>0;j--) { if(ara[j]>=ara[j-1]) { temp = ara[j]; ara[j]=ara[j-1]; ara[j-1]=temp; } else break; } // printf("%d ",ara[i]); } int limit = l; if(limit>=m) limit = m; for(int i=0; i<limit; i++) { sum+=ara[i]; //printf("%d ",ara[i]); } //printf("\n"); printf("%d\n",sum); } return 0; }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
33aa6e915c6799b932280600b55026fd
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include<stdio.h> int main() { int m,n,i,t,s=0; scanf("%d%d",&n,&m); int a[n]; for(i=0;i<n;++i) scanf("%d",&a[i]); for(int j=0;j<n;++j) { for(int k=0;k<n-j-1;++k) { if(a[k]>=a[k+1]) { t=a[k]; a[k]=a[k+1]; a[k+1]=t; } } } for(int l=0;l<m;++l) { if(a[l]<0) s=s+a[l]; } printf("%d\n",-s); return 0; }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
edfc88fb71436cc191bd3cec76f389a2
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include <stdio.h> int main(void) { int n, m; scanf("%d%d", &n, &m); int arr[n]; for(int i = 0; i < n; i++) scanf("%d", arr+i); int tot = 0; for(int i = 0; i < m; i++){ int min = 1000, index = i; for(int j = 0; j < n; j++){ if(arr[j]<min){ min = arr[j]; index = j; } } if(min<0) tot -= min; else break; arr[index] = 1000; } printf("%d", tot); return 0; }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
b79180119cd76c21c076a074c9c95d1f
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include<string.h> #include<stdlib.h> int main() { int i,n,a[1000],m,j,min,ans=0,minindex; scanf("%d%d",&n,&m); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<m;i++) { min=1001; for(j=0;j<n;j++) { if(a[j]<min) { min=a[j]; minindex=j; } } // printf("%d ",ans); if(min<=0) ans-=min; a[minindex]=1001; } printf("%d",ans); }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
4214c943c5203e62f578e5a461cff0a8
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include<stdio.h> #include<stdlib.h> int sort(const void*x,const void*y) { return ( *(int*)x - *(int*)y ); } int main() { int n,m,a[200],i,j,total=0; scanf("%d%d",&n,&m); for(i=0;i<n;i++) { scanf("%d",&a[i]); } qsort(a,n,sizeof(int),sort); for(j=0;j<m;j++) { if(a[j]<=0) { total=total+((-1)*a[j]); } } printf("%d\n",total); return 0; }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
1fce72acc6dbaf3961d10aa782bde6a0
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include<stdio.h> #include<stdlib.h> int cmp(const void *a,const void *b) { int c=*(int*)a-*(int*)b; return c; } main() { int n,m; scanf("%d %d",&n,&m); int a[n],i; for(i=0;i<n;i++) scanf("%d",&a[i]); qsort(a,n,sizeof(int),cmp); int s=0; for(i=0;i<=m-1;i++) { if(a[i]<=0) s+=a[i]; } printf("%d",-1*s); }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
b69cd852bdbfa346afa4bdd50bc0c7ed
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include<stdio.h> int main() { int m,n,i,j,k,a[101],temp=0,s=0; scanf("%d%d",&n,&m); for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=0;i<n-1;i++) { for(j=i+1;j<n;j++) { if(a[i]>a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } } for(k=0;k<m;k++) { if(a[k]<0)s=s+abs(a[k]); } printf("%d",s); }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
89a5acb567646816824e112309949e63
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include<stdio.h> int main() { int n, m; scanf("%d%d", &n, &m); int tv[n], i, j, a[1000], f = 0; for(i=0; i<n; i++) { scanf("%d", &tv[i]); if(tv[i]<0) { a[f] = tv[i]; f++; } } for(i=0; i<f; i++) { for(j=0; j<f-i; j++) { if(a[j]>a[j+1]) { int temp = a[j]; a[j] = a[j+1]; a[j+1] = temp; } } } int sum = 0; if(f-1<m) { for(i=0; i<f; i++) sum = sum - a[i]; } else { for(i=0; i<m; i++) sum = sum - a[i]; } printf("%d\n", sum); return 0; }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
37e6fef0f940f8f55f182c3d8f1ace67
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include<stdio.h> int main() { int n,m,i,x,a[1000],temp,j,max,sum=0; scanf("%d %d",&n,&m); for(i=0;i<n;i++) scanf("%d",&a[i]); x=n; for(i=0; i<x; i++) { max=a[0]; for(j=1; j<x; j++) { if(a[j]>max) { max=a[j]; } else { temp=a[j-1]; a[j-1]=a[j]; a[j]=temp; } } } for(i=0;i<m;i++) { if(a[i]>0) break; sum+=a[i]; } printf("%d\n",-sum); return 0; }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
c12e2aeac7265545541d344d550a8e46
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include<stdio.h> int main() { int m,n; scanf("%d %d",&n,&m); int a[n]; for(int i=0;i<n;i++){ scanf("%d",&a[i]); } for(int i=0;i<n;i++){ for(int j=0;j<n-i-1;j++){ if(a[j]>a[j+1]){ int t=a[j]; a[j]=a[j+1]; a[j+1]=t; } } } int x=0; for(int i=0;i<m;i++){ if(a[i]<0){ x=x+(-1)*a[i]; } } printf("%d\n",x); return 0; }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
a4f480fcded9394cb7f3471a3b93c410
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include<stdio.h> int main() { int n,m,temp,ans=0; scanf("%d%d",&n,&m); int a[n+1],i,j; for(i=1;i<=n;i++) { scanf("%d",&a[i]); } for(i=1;i<=n;i++) { for(j=i;j<=n;j++) { if(a[j]<a[i]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } } for(i=1;i<=m;i++) { if(a[i]<0) ans=ans+a[i]; } printf("%d",-1*ans); return 0; }
Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price β€” their owners are ready to pay Bob if he buys their useless apparatus. Bob can Β«buyΒ» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Output the only number β€” the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.
C
9a56288d8bd4e4e7ef3329e102f745a5
4cfc8ebcd092b4c6f962c173e21c5a26
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "greedy" ]
1286802000
["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7"]
null
PASSED
900
standard input
2 seconds
The first line contains two space-separated integers n and m (1 ≀ m ≀ n ≀ 100) β€” amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains n space-separated integers ai ( - 1000 ≀ ai ≀ 1000) β€” prices of the TV sets.
["8", "7"]
#include <stdio.h> #include <stdlib.h> #include<math.h> int cmpfunc(const void*a,const void*b){ return *(int *)a-*(int *)b; } int main() { int n,m; scanf("%d %d",&n,&m); int arr[n]; for(int i=0;i<n;i++){ scanf("%d",&arr[i]); } qsort(arr,n,sizeof(int),cmpfunc); int neg=0; for(int i=0;i<n;i++){ if(arr[i]<0){ neg++; } } if(neg==0){ printf("%d",0); } int sum=0; if(neg!=0){ if(m>neg){ for(int i=0;i<neg;i++){ sum+=arr[i]; } } if(m<=neg){ for(int i=0;i<m;i++){ sum+=arr[i]; } } printf("%d",abs(sum)); } return 0; }
Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.Overall the group has n students. They received marks for m subjects. Each student got a mark from 1 to 9 (inclusive) for each subject.Let's consider a student the best at some subject, if there is no student who got a higher mark for this subject. Let's consider a student successful, if there exists a subject he is the best at.Your task is to find the number of successful students in the group.
Print the single number β€” the number of successful students in the given group.
C
41bdb08253cf5706573f5d469ab0a7b3
6d452823b090177c520ddff0160c7fc4
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1329750000
["3 3\n223\n232\n112", "3 5\n91728\n11828\n11111"]
NoteIn the first sample test the student number 1 is the best at subjects 1 and 3, student 2 is the best at subjects 1 and 2, but student 3 isn't the best at any subject.In the second sample test each student is the best at at least one subject.
PASSED
900
standard input
1 second
The first input line contains two integers n and m (1 ≀ n, m ≀ 100) β€” the number of students and the number of subjects, correspondingly. Next n lines each containing m characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepatated by spaces.
["2", "3"]
#include <stdio.h> #include <stdlib.h> int main() { int n,m,ans=0; scanf("%d %d",&n,&m); char data[n][m]; int i=0; while(i<n*m) { int a,b; a = i / m; b = i % m; if (b==0) { scanf("\n%c",&data[a][b]); } else { scanf("%c",&data[a][b]); } i++; } int j=0; while(j<n) { int k=0; int br1 = 0; while(k<m) { int comp = data[j][k] - '0'; int x=0,count=0; while(x<n) { int compare = data[x][k] - '0'; if (compare <= comp) { count++; } if (count == n) { ans++; br1 = 1; } x++; } if (br1 == 1) { break; } k++; } j++; } printf("%d",ans); return 0; }
Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.Overall the group has n students. They received marks for m subjects. Each student got a mark from 1 to 9 (inclusive) for each subject.Let's consider a student the best at some subject, if there is no student who got a higher mark for this subject. Let's consider a student successful, if there exists a subject he is the best at.Your task is to find the number of successful students in the group.
Print the single number β€” the number of successful students in the given group.
C
41bdb08253cf5706573f5d469ab0a7b3
87d457c2c0726d91bd0685d6b4d80326
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1329750000
["3 3\n223\n232\n112", "3 5\n91728\n11828\n11111"]
NoteIn the first sample test the student number 1 is the best at subjects 1 and 3, student 2 is the best at subjects 1 and 2, but student 3 isn't the best at any subject.In the second sample test each student is the best at at least one subject.
PASSED
900
standard input
1 second
The first input line contains two integers n and m (1 ≀ n, m ≀ 100) β€” the number of students and the number of subjects, correspondingly. Next n lines each containing m characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepatated by spaces.
["2", "3"]
#include<stdio.h> char str[200][200]; char ara[200]; int main() { int n,m,i,j,k,max,count=0; scanf("%d %d",&n,&m); for(i=0;i<n;i++) { scanf("%s",str[i]); } for(i=0;i<m;i++) { max=0; for(j=0;j<n;j++) { if(str[j][i]>max) max=str[j][i]; } ara[i]=max; } for(i=0;i<n;i++) { for(j=0;j<m;j++) { if(str[i][j]==ara[j]) { count++; j=m; } } } printf("%d\n",count); return 0; }
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0).Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
Print a single integer β€” the minimum number of shots Han Solo needs to destroy all the stormtroopers.
C
8d2845c33645ac45d4d37f9493b0c380
3ad9e510a106563e7fcb1e62c224ca31
GNU C
standard output
256 megabytes
train_001.jsonl
[ "geometry", "math", "implementation", "data structures", "brute force" ]
1423931400
["4 0 0\n1 1\n2 2\n2 0\n-1 -1", "2 1 2\n1 1\n1 0"]
NoteExplanation to the first and second samples from the statement, respectively:
PASSED
1,400
standard input
1 second
The first line contains three integers n, x0 ΠΈ y0 (1 ≀ n ≀ 1000,  - 104 ≀ x0, y0 ≀ 104) β€” the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≀ xi, yi ≀ 104) β€” the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
["2", "1"]
/* _____________________________________________ PURPOSE : created by -ABHINAV AGGARWAL _____________________________________________ */ #include <stdio.h> int cmp(const void *a,const void *b) { double diff; diff=*(double *)a-*(double *)b; if (diff>0) return 1; else if (diff<0) return -1; return 0; } int main() { int n,x,y; scanf("%d%d%d",&n,&x,&y); double A[1000][2]; int i; for(i=0;i<n;i++) { scanf("%lf%lf",&A[i][0],&A[i][1]); } double slope[1000]; for(i=0;i<n;i++) { if((A[i][0]-x)==0) slope[i]=10000007; else slope[i]=(A[i][1]-y)/(A[i][0]-x); } qsort(slope,n,sizeof(double),cmp); int count=1; for(i=1;i<n;i++) { // printf("%lf %lf\n",slope[i-1],slope[i]); if(slope[i]!=slope[i-1]) count++; } printf("%d\n",count); return 0; }
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0).Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
Print a single integer β€” the minimum number of shots Han Solo needs to destroy all the stormtroopers.
C
8d2845c33645ac45d4d37f9493b0c380
82220025f58dee1be0594599ccc16f9c
GNU C
standard output
256 megabytes
train_001.jsonl
[ "geometry", "math", "implementation", "data structures", "brute force" ]
1423931400
["4 0 0\n1 1\n2 2\n2 0\n-1 -1", "2 1 2\n1 1\n1 0"]
NoteExplanation to the first and second samples from the statement, respectively:
PASSED
1,400
standard input
1 second
The first line contains three integers n, x0 ΠΈ y0 (1 ≀ n ≀ 1000,  - 104 ≀ x0, y0 ≀ 104) β€” the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≀ xi, yi ≀ 104) β€” the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
["2", "1"]
#include <stdio.h> int main() { int n,x0,y0,x,y,vert,ind,i,count; count=ind=vert=0; scanf("%d %d %d",&n,&x0,&y0); double slop[n],swap; for(i=0;i<n;i++) { scanf("%d %d",&x,&y); if(x==x0) { vert++; slop[i]=0; } if(x!=x0) {slop[i]=(y0-y); swap=x0-x; slop[i]=slop[i]/swap;} if(x!=x0&&slop[i]==0) ind++; } for(i=1;i<n;i++) { for(count=i;count>0&&slop[count]<slop[count-1];count--) { swap=slop[count]; slop[count]=slop[count-1]; slop[count-1]=swap; } } count=1; if(vert>0&&ind>0) count++; for(i=0;i<n;i++) { if(i>0&&slop[i]!=slop[i-1]) count++; } printf("%d",count); }
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0).Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
Print a single integer β€” the minimum number of shots Han Solo needs to destroy all the stormtroopers.
C
8d2845c33645ac45d4d37f9493b0c380
8244fe3040f24ad10465f6b3b80985b8
GNU C
standard output
256 megabytes
train_001.jsonl
[ "geometry", "math", "implementation", "data structures", "brute force" ]
1423931400
["4 0 0\n1 1\n2 2\n2 0\n-1 -1", "2 1 2\n1 1\n1 0"]
NoteExplanation to the first and second samples from the statement, respectively:
PASSED
1,400
standard input
1 second
The first line contains three integers n, x0 ΠΈ y0 (1 ≀ n ≀ 1000,  - 104 ≀ x0, y0 ≀ 104) β€” the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≀ xi, yi ≀ 104) β€” the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
["2", "1"]
#include<stdio.h> #include<limits.h> int main() { int n,i,j,t,k,l,s=0,mx,my; int a,b,x,y; float m; scanf("%d",&n); int X[n],Y[n],vis[n]; scanf("%d",&x); scanf("%d",&y); for(i=0;i<n;i++) { scanf("%d",&X[i]); scanf("%d",&Y[i]); vis[i]=0; } int num=n; float tx,ty,tm; for(i=0;i<n;i++) { if(vis[i]==0) { mx=x-X[i]; my=y-Y[i]; vis[i]==1; if(mx==0) m=INT_MAX; else m=(float)my/(float)mx; for(j=i+1;j<n;j++) { tx=x-X[j]; ty=y-Y[j]; if(mx==0) { if(tx==0) { num--; vis[j]=1; } } else { if(tx!=0) { tm=ty/tx; if(tm==m) { num--; vis[j]=1; } } } } } } printf("%d",num); return 0; }
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0).Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
Print a single integer β€” the minimum number of shots Han Solo needs to destroy all the stormtroopers.
C
8d2845c33645ac45d4d37f9493b0c380
8b3f663b266dc26d6410e50619a1688a
GNU C
standard output
256 megabytes
train_001.jsonl
[ "geometry", "math", "implementation", "data structures", "brute force" ]
1423931400
["4 0 0\n1 1\n2 2\n2 0\n-1 -1", "2 1 2\n1 1\n1 0"]
NoteExplanation to the first and second samples from the statement, respectively:
PASSED
1,400
standard input
1 second
The first line contains three integers n, x0 ΠΈ y0 (1 ≀ n ≀ 1000,  - 104 ≀ x0, y0 ≀ 104) β€” the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≀ xi, yi ≀ 104) β€” the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
["2", "1"]
#include <stdio.h> #include <stdlib.h> #include <math.h> #define MAX_TROOPS 1000 #define EPS 1e-9 int lfeq(long double x, long double y) { return (fabsl(x - y) <= EPS); } int cmp(const void *x, const void *y) { const long double *dx; const long double *dy; dx = x; dy = y; if(*dx < *dy) return -1; else if(*dx > *dy) return 1; else return 0; } int main(void) { int n; long double angle[MAX_TROOPS]; int i, j, k, x, y; scanf("%d %d %d", &n, &i, &j); for(k = n; k --;) { scanf("%d %d", &x, &y); x -= i; y -= j; if(x == 0) angle[k] = M_PI / 2; else angle[k] = atanl((long double)y / (long double)x); } qsort(angle, n, sizeof(long double), cmp); //for(i = 0; i < n; i ++) // printf("%Lf\n", angle[i]); j = 0; for(i = 0; i < n;) { j ++; for(i ++; i < n && lfeq(angle[i], angle[i - 1]); i ++); } printf("%d\n", j); return 0; }
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0).Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
Print a single integer β€” the minimum number of shots Han Solo needs to destroy all the stormtroopers.
C
8d2845c33645ac45d4d37f9493b0c380
8393b1ab277a7aed434242b14e0b5d97
GNU C
standard output
256 megabytes
train_001.jsonl
[ "geometry", "math", "implementation", "data structures", "brute force" ]
1423931400
["4 0 0\n1 1\n2 2\n2 0\n-1 -1", "2 1 2\n1 1\n1 0"]
NoteExplanation to the first and second samples from the statement, respectively:
PASSED
1,400
standard input
1 second
The first line contains three integers n, x0 ΠΈ y0 (1 ≀ n ≀ 1000,  - 104 ≀ x0, y0 ≀ 104) β€” the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≀ xi, yi ≀ 104) β€” the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
["2", "1"]
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<math.h> typedef long int ll; typedef struct { ll y,x; ll n,d; }L; L p[1005],q; ll gcd(ll a,ll b) { ll t,retval; while(a%b!=0) { t=b; b=a%b; a=t; } retval=b; return retval; } ll mi(ll a,ll b) { return a-b; } ll po(ll n) { if(n<0) { return -n; } return n; } int compare(const void *a,const void *b) { L *e1 = (L *)a; L *e2 = (L *)b; if(e1->d==e2->d) { return e1->n-e2->n; } return e1->d-e2->d; } int main() { ll i,n,x0,y0,ans=1,g,j,cnt=0,cnt1=0,k; scanf("%ld%ld%ld",&n,&x0,&y0); k=n; j=0; for(i=0;i<n;i++) { scanf("%ld%ld",&q.x,&q.y); p[j].n=mi(q.y,y0); p[j].d=mi(q.x,x0); if(p[j].d==0) { if(cnt==0) cnt++; k--; } else if(p[j].n==0) { if(cnt1==0) cnt1++; k--; } else { g=gcd(po(p[j].n),po(p[j].d)); if(p[j].d<0&&p[j].n<0) { p[j].d=-p[j].d; p[j].n=-p[j].n; } else if(p[j].d<0) { p[j].d=-p[j].d; p[j].n=-p[j].n; } p[j].n=p[j].n/g; p[j].d=p[j].d/g; j++; } } qsort(p,k,sizeof(L),compare); i=0; for(;i<k-1;) { if(p[i].d==p[i+1].d) { if(p[i].d!=0) { if(p[i].n!=p[i+1].n) { ans++; } } } else if(p[i].n==p[i+1].n) { if(p[i].n!=0) { ans++; } } else { ans++; } i++; } if(ans==1) { if(j==0) { if(cnt1!=0&&cnt!=0) { ans++; } } else { if(cnt1!=0&&cnt!=0) { ans++; ans++; } else if(cnt!=0||cnt1!=0) { ans++; } } } else { ans=ans+cnt+cnt1; } printf("%ld\n",ans); return 0; }
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0).Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
Print a single integer β€” the minimum number of shots Han Solo needs to destroy all the stormtroopers.
C
8d2845c33645ac45d4d37f9493b0c380
b90b7fc87073f56a9058c6a7dacc081d
GNU C
standard output
256 megabytes
train_001.jsonl
[ "geometry", "math", "implementation", "data structures", "brute force" ]
1423931400
["4 0 0\n1 1\n2 2\n2 0\n-1 -1", "2 1 2\n1 1\n1 0"]
NoteExplanation to the first and second samples from the statement, respectively:
PASSED
1,400
standard input
1 second
The first line contains three integers n, x0 ΠΈ y0 (1 ≀ n ≀ 1000,  - 104 ≀ x0, y0 ≀ 104) β€” the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≀ xi, yi ≀ 104) β€” the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
["2", "1"]
#include <stdio.h> int main() { int i,j,n,count=0; double x0,y0,x,y; scanf("%d %lf %lf",&n,&x0,&y0); double slope[n]; for(i=0;i<n;i++){ scanf("%lf %lf",&x,&y); if(x!=x0){ if(y0==y) slope[i]=0; else{ slope[i]=(y0-y)/(x0-x); } //printf("y0-y = %d\nx0-x = %d\n",y0-y,x0-x); } else{ slope[i]=40000; } //printf("slope[%d] = %lf\n",i,slope[i]); } //printf("\n"); for(i=0;i<n;i++){ if(slope[i]!=30000){ for(j=i+1;j<n;j++){ if(slope[i]==slope[j]){ slope[j]=30000; //printf("slope[%d] = %lf\n",j,slope[j]); } } count++; //printf("count = %d\n\n",count); } } printf("%d",count); return 0; }
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0).Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
Print a single integer β€” the minimum number of shots Han Solo needs to destroy all the stormtroopers.
C
8d2845c33645ac45d4d37f9493b0c380
329dbbfbadcbeb522326b4d14dbb32b6
GNU C
standard output
256 megabytes
train_001.jsonl
[ "geometry", "math", "implementation", "data structures", "brute force" ]
1423931400
["4 0 0\n1 1\n2 2\n2 0\n-1 -1", "2 1 2\n1 1\n1 0"]
NoteExplanation to the first and second samples from the statement, respectively:
PASSED
1,400
standard input
1 second
The first line contains three integers n, x0 ΠΈ y0 (1 ≀ n ≀ 1000,  - 104 ≀ x0, y0 ≀ 104) β€” the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≀ xi, yi ≀ 104) β€” the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
["2", "1"]
#include <stdio.h> int main() { int n, i, j, x[1001], y[1002], fin[1001]={0}, count=0; scanf("%d", &n); for(i=0; i<n+1; i++) scanf("%d %d", &x[i], &y[i]); for(i=1; i<=n; i++) { if(!fin[i]) { count++; fin[i]=count; if(x[i]!=x[0]) { float m=(float)(y[i]-y[0])/(float)(x[i]-x[0]); //printf("m=%f x[%d]=%d x[0]=%d\n", m, i, x[i], x[0]); for(j=i+1; j<=n; j++) { float m1=(float)(y[j]-y[0])/(float)(x[j]-x[0]); if(m1==m) { fin[j]=fin[i]; } } } else if(x[i]==x[0]) { for(j=i+1; j<=n; j++) { if(x[j]==x[0]) { fin[j]=fin[i]; } } } } //printf("count=%d\n", count); } printf("%d\n", count); return 0; }
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0).Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
Print a single integer β€” the minimum number of shots Han Solo needs to destroy all the stormtroopers.
C
8d2845c33645ac45d4d37f9493b0c380
4611ec4464d153ee37ac8d54c77c2307
GNU C
standard output
256 megabytes
train_001.jsonl
[ "geometry", "math", "implementation", "data structures", "brute force" ]
1423931400
["4 0 0\n1 1\n2 2\n2 0\n-1 -1", "2 1 2\n1 1\n1 0"]
NoteExplanation to the first and second samples from the statement, respectively:
PASSED
1,400
standard input
1 second
The first line contains three integers n, x0 ΠΈ y0 (1 ≀ n ≀ 1000,  - 104 ≀ x0, y0 ≀ 104) β€” the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≀ xi, yi ≀ 104) β€” the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
["2", "1"]
#include<stdio.h> int main() { int x,y; int a[1000][2]; int n; int i,j; int c=0; int k[1000]; scanf("%d %d %d",&n,&x,&y); for(i=0; i<n; i++,c++) { scanf("%d %d",&a[i][0],&a[i][1]); for(j=0; j<i; j++) { if((a[i][0]-x)*(a[j][1]-y)==(a[i][1]-y)*(a[j][0]-x)) { c=c-1; break; } } } printf("%d\n",c); return 0; }
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0).Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
Print a single integer β€” the minimum number of shots Han Solo needs to destroy all the stormtroopers.
C
8d2845c33645ac45d4d37f9493b0c380
94cbdb7340d0dcb3e59c01d2233594da
GNU C
standard output
256 megabytes
train_001.jsonl
[ "geometry", "math", "implementation", "data structures", "brute force" ]
1423931400
["4 0 0\n1 1\n2 2\n2 0\n-1 -1", "2 1 2\n1 1\n1 0"]
NoteExplanation to the first and second samples from the statement, respectively:
PASSED
1,400
standard input
1 second
The first line contains three integers n, x0 ΠΈ y0 (1 ≀ n ≀ 1000,  - 104 ≀ x0, y0 ≀ 104) β€” the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≀ xi, yi ≀ 104) β€” the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
["2", "1"]
#include<stdio.h> int main() { int i,j,k,n,m,x0,y0,t,x[1010],y[1010],count,count1,shot; scanf("%d%d%d",&n,&x0,&y0); for(i=0;i<n;i++) scanf("%d%d",&x[i],&y[i]); shot=n; count1=0; for(i=0;i<n;i++) { count=0; if(x[i]!=-100000&&y[i]!=-100000) { for(j=i+1;j<n;j++) { if(x[j]!=-100000&&y[j]!=-100000) { t=x0*y[i]-x0*y[j]+x[j]*y0-x[i]*y0+x[i]*y[j]-y[i]*x[j]; if(t==0) { count++; x[j]=-100000; y[j]=-100000; count1++; } } } x[i]=-100000; y[i]=-100000; shot=shot-count; count1++; if(count1==n) break; } } printf("%d\n",shot); return 0; }
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0).Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
Print a single integer β€” the minimum number of shots Han Solo needs to destroy all the stormtroopers.
C
8d2845c33645ac45d4d37f9493b0c380
45ca1388ffb57a687a52c6b4772b53b5
GNU C
standard output
256 megabytes
train_001.jsonl
[ "geometry", "math", "implementation", "data structures", "brute force" ]
1423931400
["4 0 0\n1 1\n2 2\n2 0\n-1 -1", "2 1 2\n1 1\n1 0"]
NoteExplanation to the first and second samples from the statement, respectively:
PASSED
1,400
standard input
1 second
The first line contains three integers n, x0 ΠΈ y0 (1 ≀ n ≀ 1000,  - 104 ≀ x0, y0 ≀ 104) β€” the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≀ xi, yi ≀ 104) β€” the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
["2", "1"]
#include<stdio.h> void quicksort(double x2[],double first,double last); int main() { long int n,i,j; double x0,y0,count=1; scanf("%ld%lf%lf",&n,&x0,&y0); double a[n]; for(i=0;i<n;i++) { double x,y; double m=0; scanf("%lf%lf",&x,&y); if(x0-x!=0) { m=(y0-y)/(x0-x); a[i]=m; } else a[i]=899; } quicksort(a,0,n-1); for(i=0;i<n-1;i++) { if(a[i]==a[i+1]) continue; else count++; } printf("%.0lf",count); return 0; } void quicksort(double x2[],double first,double last) { double temp; long int i,j,pivot; if(first<last){ pivot=first; i=first; j=last; while(i<j){ while(x2[i]<=x2[pivot]&&i<last) i++; while(x2[j]>x2[pivot]) j--; if(i<j){ temp=x2[i]; x2[i]=x2[j]; x2[j]=temp; } } temp=x2[pivot]; x2[pivot]=x2[j]; x2[j]=temp; quicksort(x2,first,j-1); quicksort(x2,j+1,last); } }
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0).Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
Print a single integer β€” the minimum number of shots Han Solo needs to destroy all the stormtroopers.
C
8d2845c33645ac45d4d37f9493b0c380
b2b33ac2959f0db9fc3f836b64284dd8
GNU C
standard output
256 megabytes
train_001.jsonl
[ "geometry", "math", "implementation", "data structures", "brute force" ]
1423931400
["4 0 0\n1 1\n2 2\n2 0\n-1 -1", "2 1 2\n1 1\n1 0"]
NoteExplanation to the first and second samples from the statement, respectively:
PASSED
1,400
standard input
1 second
The first line contains three integers n, x0 ΠΈ y0 (1 ≀ n ≀ 1000,  - 104 ≀ x0, y0 ≀ 104) β€” the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≀ xi, yi ≀ 104) β€” the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
["2", "1"]
#include <stdio.h> #include <math.h> #include <string.h> int main(void) { int n, x0, y0; scanf("%d %d %d", &n, &x0, &y0); int coordinate[n][2];//0 is x and 1 is y int flag[n]; int i, j; for (i = 0; i < n; ++i) { scanf("%d %d", &coordinate[i][0], &coordinate[i][1]); flag[i] = 1; } int count = n; for (i = 0; i < n; ++i) { if (flag[i] == 0) continue; for (j = i+1; j < n; ++j) { if ((coordinate[i][0] - x0) * (coordinate[j][1] - y0) == (coordinate[i][1] - y0) * (coordinate[j][0] - x0)) { flag[j] = 0; count -= 1; } } } printf("%d\n", count); return 0; }
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0).Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
Print a single integer β€” the minimum number of shots Han Solo needs to destroy all the stormtroopers.
C
8d2845c33645ac45d4d37f9493b0c380
621c3f27ef06bede74e91208c5d4d883
GNU C
standard output
256 megabytes
train_001.jsonl
[ "geometry", "math", "implementation", "data structures", "brute force" ]
1423931400
["4 0 0\n1 1\n2 2\n2 0\n-1 -1", "2 1 2\n1 1\n1 0"]
NoteExplanation to the first and second samples from the statement, respectively:
PASSED
1,400
standard input
1 second
The first line contains three integers n, x0 ΠΈ y0 (1 ≀ n ≀ 1000,  - 104 ≀ x0, y0 ≀ 104) β€” the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≀ xi, yi ≀ 104) β€” the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
["2", "1"]
#include<stdio.h> int arr[2000][3]; int equation(int x1, int y1, int x2, int y2, int x3, int y3) { return (y1 - y2) * (x1 - x3) == (y1 - y3) * (x1 - x2); } int main(){ int a,b,c,d; int x,y; scanf("%d%d%d",&a,&x,&y); int i; for(i=0;i<a;i++){ scanf("%d%d",&arr[i][0],&arr[i][1]); } getchar(); int cnt=0; int ind=0; for(i=0;i<a;i++){ ind=0; for(b=0;b<a;b++){ if(equation(x,y,arr[i][0],arr[i][1],arr[b][0],arr[b][1]) && arr[b][2]!=1){ ind=1; arr[b][2]=1; } } if(ind) cnt++; } printf("%d",cnt); }
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x0, y0).Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
Print a single integer β€” the minimum number of shots Han Solo needs to destroy all the stormtroopers.
C
8d2845c33645ac45d4d37f9493b0c380
bf55b036ca93b34dffdd496b296e9611
GNU C
standard output
256 megabytes
train_001.jsonl
[ "geometry", "math", "implementation", "data structures", "brute force" ]
1423931400
["4 0 0\n1 1\n2 2\n2 0\n-1 -1", "2 1 2\n1 1\n1 0"]
NoteExplanation to the first and second samples from the statement, respectively:
PASSED
1,400
standard input
1 second
The first line contains three integers n, x0 ΠΈ y0 (1 ≀ n ≀ 1000,  - 104 ≀ x0, y0 ≀ 104) β€” the number of stormtroopers on the battle field and the coordinates of your gun. Next n lines contain two integers each xi, yi ( - 104 ≀ xi, yi ≀ 104) β€” the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
["2", "1"]
#include<stdio.h> int arr[2000][3]; int equation(int x1,int y1,int x2,int y2,int x3,int y3){ return (y1-y2)*(x1-x3)==(y1-y3)*(x1-x2); } int main(){ int a,b,c,d; int x,y; scanf("%d%d%d",&a,&x,&y); int i; for(i=0;i<a;i++){ scanf("%d%d",&arr[i][0],&arr[i][1]); } int cnt=0; int ind=0; for(i=0;i<a;i++){ ind=0; for(b=0;b<a;b++){ if(equation(x,y,arr[i][0],arr[i][1],arr[b][0],arr[b][1]) && arr[b][2]!=1){ ind=1; arr[b][2]=1; } } if(ind) cnt++; } printf("%d",cnt); }
You are given an array $$$a$$$ consisting of $$$n$$$ elements. You may apply several operations (possibly zero) to it.During each operation, you choose two indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$; $$$i \ne j$$$), increase $$$a_j$$$ by $$$a_i$$$, and remove the $$$i$$$-th element from the array (so the indices of all elements to the right to it decrease by $$$1$$$, and $$$n$$$ also decreases by $$$1$$$).Your goal is to make the array $$$a$$$ strictly ascending. That is, the condition $$$a_1 &lt; a_2 &lt; \dots &lt; a_n$$$ should hold (where $$$n$$$ is the resulting size of the array).Calculate the minimum number of actions required to make the array strictly ascending.
For each test case, print the answer as follows: In the first line, print $$$k$$$ β€” the minimum number of operations you have to perform. Then print $$$k$$$ lines, each containing two indices $$$i$$$ and $$$j$$$ for the corresponding operation. Note that the numeration of elements in the array changes after removing elements from it. If there are multiple optimal sequences of operations, print any one of them.
C
2ff113d7c71c6e91c8254cbdaf27e9ae
250392e34600f524d86d7cae696b6ed8
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "dp", "bitmasks", "brute force" ]
1587911700
["4\n8\n2 1 3 5 1 2 4 5\n15\n16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1\n2\n3 3\n14\n1 2 3 4 5 6 7 8 9 10 11 12 13 14"]
NoteIn the first test case, the sequence of operations changes $$$a$$$ as follows:$$$[2, 1, 3, 5, 1, 2, 4, 5] \rightarrow [2, 1, 3, 5, 1, 4, 7] \rightarrow [1, 3, 5, 1, 6, 7] \rightarrow [2, 3, 5, 6, 7]$$$.
PASSED
3,000
standard input
7 seconds
The first line contains one integer $$$T$$$ ($$$1 \le T \le 10000$$$) β€” the number of test cases. Each test case consists of two lines. The first line contains one integer $$$n$$$ ($$$1 \le n \le 15$$$) β€” the number of elements in the initial array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le 10^6$$$). It is guaranteed that: the number of test cases having $$$n \ge 5$$$ is not greater than $$$5000$$$; the number of test cases having $$$n \ge 8$$$ is not greater than $$$500$$$; the number of test cases having $$$n \ge 10$$$ is not greater than $$$100$$$; the number of test cases having $$$n \ge 11$$$ is not greater than $$$50$$$; the number of test cases having $$$n \ge 12$$$ is not greater than $$$25$$$; the number of test cases having $$$n \ge 13$$$ is not greater than $$$10$$$; the number of test cases having $$$n \ge 14$$$ is not greater than $$$3$$$; the number of test cases having $$$n \ge 15$$$ is not greater than $$$1$$$.
["3\n6 8\n1 6\n4 1\n7\n1 15\n1 13\n1 11\n1 9\n1 7\n1 5\n1 3\n1\n2 1\n0"]
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/time.h> #define N 15 #define B (1 << N) #define C 14348907 /* C = 3^N */ #define INF 0x3f3f3f3f int max(int a, int b) { return a > b ? a : b; } int p3[N + 1]; void init() { struct timeval tv; int i; gettimeofday(&tv, NULL); srand(tv.tv_sec ^ tv.tv_usec); p3[0] = 1; for (i = 1; i <= N; i++) p3[i] = p3[i - 1] * 3; } int rand_(int n) { return (rand() * 76543LL + rand()) % n; } int ss[B], bb[B]; int compare(const void *a, const void *b) { int i = *(int *) a; int j = *(int *) b; return ss[i] - ss[j]; } void sort(int *ii, int n) { int i; for (i = 0; i < n; i++) { int j = rand_(i + 1), tmp; tmp = ii[i], ii[i] = ii[j], ii[j] = tmp; } qsort(ii, n, sizeof *ii, compare); } char deleted[N]; void move(int i, int j) { int h, i_, j_; i_ = 0; for (h = 0; h < i; h++) if (!deleted[h]) i_++; j_ = 0; for (h = 0; h < j; h++) if (!deleted[h]) j_++; deleted[i] = 1; printf("%d %d\n", i_ + 1, j_ + 1); } int main() { int t; init(); scanf("%d", &t); while (t--) { static int aa[N], cc[B]; static char dp[C][N], dq[B][N + 1]; int n, g, h, h_, i, j, b, b_, c, all, x; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &aa[i]); for (b = 0; b < 1 << n; b++) { int sum; c = 0, sum = 0; for (i = 0; i < n; i++) if ((b & 1 << i) != 0) c += p3[i], sum += aa[i]; cc[b] = c, ss[b] = sum, bb[b] = b; } sort(bb, 1 << n); memset(dp[0], 0, n * sizeof *dp[0]); memset(dq[0], 0, (n + 1) * sizeof *dq[0]); for (b = 1; b < 1 << n; b++) memset(dq[b], -1, (n + 1) * sizeof *dq[b]); all = (1 << n) - 1; for (h = 1; h < 1 << n; h = h_) { int sum, a, s; sum = ss[bb[h]]; h_ = h + 1; while (h_ < 1 << n && ss[bb[h_]] == sum) h_++; for (g = h; g < h_; g++) { b = bb[g], a = all ^ b, s = 0; do { int p; c = cc[s] + cc[b] * 2; p = -1; for (j = 0; j < n; j++) dp[c][j] = p = max(p, (b & 1 << j) != 0 && dq[s][j] != -1 ? dq[s][j] + 1 : -1); } while ((s = s - a & a)); } for (g = h; g < h_; g++) { b = bb[g], a = all ^ b, s = 0; do { int q; b_ = s ^ b, c = cc[s] + cc[b] * 2; q = -1; for (j = 0; j < n; j++) dq[b_][j + 1] = q = max(q, max(dq[b_][j + 1], dp[c][j])); } while ((s = s - a & a)); } } printf("%d\n", n - dq[all][n]); memset(deleted, 0, n * sizeof *deleted); b = all, j = n - 1, x = INF; while (b) { int s, p, s_; s = 0, p = -1, s_ = -1; do { b_ = b ^ s, c = cc[b_] + cc[s] * 2; if (ss[s] < x && p < dp[c][j]) p = dp[c][j], s_ = s; } while ((s = s - b & b)); while ((s_ & 1 << j) == 0) j--; for (i = 0; i < n; i++) if (i != j && (s_ & 1 << i) != 0) move(i, j); b ^= s_, j--, x = ss[s_]; } } return 0; }
In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.Note that in this problem you do not have to minimize the number of swaps β€” your task is to find any sequence that is no longer than n.
In the first line print k (0 ≀ k ≀ n) β€” the number of swaps. Next k lines must contain the descriptions of the k swaps, one per line. Each swap should be printed as a pair of integers i, j (0 ≀ i, j ≀ n - 1), representing the swap of elements ai and aj. You can print indices in the pairs in any order. The swaps are performed in the order they appear in the output, from the first to the last. It is allowed to print i = j and swap the same pair of elements multiple times. If there are multiple answers, print any of them. It is guaranteed that at least one answer exists.
C
b3c6058893f935d88196113fab581cf8
bb6ec994caebb050dc55f6d715fe0b43
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "sortings", "greedy" ]
1416238500
["5\n5 2 5 1 4", "6\n10 20 20 40 60 60", "2\n101 100"]
null
PASSED
1,200
standard input
1 second
The first line of the input contains integer n (1 ≀ n ≀ 3000) β€” the number of array elements. The second line contains elements of array: a0, a1, ..., an - 1 ( - 109 ≀ ai ≀ 109), where ai is the i-th element of the array. The elements are numerated from 0 to n - 1 from left to right. Some integers may appear in the array more than once.
["2\n0 3\n4 2", "0", "1\n0 1"]
#include <stdio.h> #include <stdlib.h> int seats[4][11]; int main() { int n = 0, k = 0, i = 0, j = 0, hold = 0, pos = 0; scanf("%d", &n); int nums[n], ans[n*n][2]; for(i = 0; i < n; i++) scanf("%d", &nums[i]); for(i = 0; i < n-1; i++) { hold = nums[i]; for(j = i+1; j < n; j++) { if(hold > nums[j]) { hold = nums[j]; pos = j; } } if(hold != nums[i]) { hold = nums[i]; nums[i] = nums[pos]; nums[pos] = hold; ans[k][0] = i; ans[k][1] = pos; k++; } } printf("%d\n",k); for(i = 0; i < k; i++) printf("%d %d\n",ans[i][0],ans[i][1]); }
In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.Note that in this problem you do not have to minimize the number of swaps β€” your task is to find any sequence that is no longer than n.
In the first line print k (0 ≀ k ≀ n) β€” the number of swaps. Next k lines must contain the descriptions of the k swaps, one per line. Each swap should be printed as a pair of integers i, j (0 ≀ i, j ≀ n - 1), representing the swap of elements ai and aj. You can print indices in the pairs in any order. The swaps are performed in the order they appear in the output, from the first to the last. It is allowed to print i = j and swap the same pair of elements multiple times. If there are multiple answers, print any of them. It is guaranteed that at least one answer exists.
C
b3c6058893f935d88196113fab581cf8
901b80653821245f21cc57b24ae22f88
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "sortings", "greedy" ]
1416238500
["5\n5 2 5 1 4", "6\n10 20 20 40 60 60", "2\n101 100"]
null
PASSED
1,200
standard input
1 second
The first line of the input contains integer n (1 ≀ n ≀ 3000) β€” the number of array elements. The second line contains elements of array: a0, a1, ..., an - 1 ( - 109 ≀ ai ≀ 109), where ai is the i-th element of the array. The elements are numerated from 0 to n - 1 from left to right. Some integers may appear in the array more than once.
["2\n0 3\n4 2", "0", "1\n0 1"]
#include<stdio.h> int main() { int n,c=0,d; scanf("%d",&n); long long a[n],m[n],r[n-1],s[n]; int p[n]; for(int i=0;i<n;i++) { scanf("%lld",&a[i]); } for(int i=0;i<n;i++) { m[i]=a[i]; d=i; for(int j=i+1;j<=n-1;j++) { r[j-1]=m[i]; if(a[j]<r[j-1]) { d=j; s[i]=j; m[i]=a[j]; } } if(d>i) { a[d]=a[i]; a[i]=m[i]; p[i]=1;} else { p[i]=0; } c=c+p[i]; } printf("%d\n",c); for(int i=0;i<n;i++) { if(p[i]==1) printf("%d %d\n",i,s[i]); } }
In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.Note that in this problem you do not have to minimize the number of swaps β€” your task is to find any sequence that is no longer than n.
In the first line print k (0 ≀ k ≀ n) β€” the number of swaps. Next k lines must contain the descriptions of the k swaps, one per line. Each swap should be printed as a pair of integers i, j (0 ≀ i, j ≀ n - 1), representing the swap of elements ai and aj. You can print indices in the pairs in any order. The swaps are performed in the order they appear in the output, from the first to the last. It is allowed to print i = j and swap the same pair of elements multiple times. If there are multiple answers, print any of them. It is guaranteed that at least one answer exists.
C
b3c6058893f935d88196113fab581cf8
f73048465f9a331c776f8d99f4f88172
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "sortings", "greedy" ]
1416238500
["5\n5 2 5 1 4", "6\n10 20 20 40 60 60", "2\n101 100"]
null
PASSED
1,200
standard input
1 second
The first line of the input contains integer n (1 ≀ n ≀ 3000) β€” the number of array elements. The second line contains elements of array: a0, a1, ..., an - 1 ( - 109 ≀ ai ≀ 109), where ai is the i-th element of the array. The elements are numerated from 0 to n - 1 from left to right. Some integers may appear in the array more than once.
["2\n0 3\n4 2", "0", "1\n0 1"]
#include<stdio.h> #define int long long int int arr[3100]; int store1[3100]; int store2[3100]; int main(void) { int n; scanf("%lld",&n); for(int q=0;q<n;q++) scanf("%lld",&arr[q]); int temp=0;int ind=0;int ctr1=0; int ctr=0;int temp2=0;int tempo=0; int swap=0; int flag=0; for(int w=0;w<n;w++) { tempo=arr[w]; flag=0; for(int f=w;f<n;f++) { if(arr[f]<tempo) {tempo=arr[f]; // printf("here\n"); temp=arr[f]; ind=f; flag=-1; } } if(flag==-1) { //printf("HERE\n"); store1[swap]=w; store2[swap]=ind; swap++; temp2=arr[w]; arr[w]=temp; arr[ind]=temp2; } /* temp2=arr[w]; arr[w]=temp; arr[ind]=temp2; */ while(1) { // printf("loop\n"); if(arr[w+1]==arr[w]) w++; else break; } } printf("%lld\n",swap); for(int e=0;e<swap;e++) { printf("%lld %lld\n",store1[e],store2[e]); } return 0; }
In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.Note that in this problem you do not have to minimize the number of swaps β€” your task is to find any sequence that is no longer than n.
In the first line print k (0 ≀ k ≀ n) β€” the number of swaps. Next k lines must contain the descriptions of the k swaps, one per line. Each swap should be printed as a pair of integers i, j (0 ≀ i, j ≀ n - 1), representing the swap of elements ai and aj. You can print indices in the pairs in any order. The swaps are performed in the order they appear in the output, from the first to the last. It is allowed to print i = j and swap the same pair of elements multiple times. If there are multiple answers, print any of them. It is guaranteed that at least one answer exists.
C
b3c6058893f935d88196113fab581cf8
f658e5dcfc8301d2815a9df6801fc6b6
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "sortings", "greedy" ]
1416238500
["5\n5 2 5 1 4", "6\n10 20 20 40 60 60", "2\n101 100"]
null
PASSED
1,200
standard input
1 second
The first line of the input contains integer n (1 ≀ n ≀ 3000) β€” the number of array elements. The second line contains elements of array: a0, a1, ..., an - 1 ( - 109 ≀ ai ≀ 109), where ai is the i-th element of the array. The elements are numerated from 0 to n - 1 from left to right. Some integers may appear in the array more than once.
["2\n0 3\n4 2", "0", "1\n0 1"]
#include<stdio.h> /*void swap(int a,int b) { a=a+b; b=a-b; a=a-b; }*/ int main() { int n,idx,temp,k=0; scanf("%d",&n); int ar[n],a[n]; for(int i=0;i<n;i++) { scanf("%d",&ar[i]); } for(int j=0;j<n;j++) { int min_length=1000000001; for(int i=j;i<n;i++) { if(min_length>ar[i]) { idx=i; min_length=ar[i]; } } temp=ar[idx]; ar[idx]=ar[j]; ar[j]=temp; a[k]=idx;a[k+1]=j; k=k+2; } printf("%d\n",k/2); for(int i=0;i<k;i=i+2) { printf("%d %d\n",a[i],a[i+1]); } return 0; }
In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.Note that in this problem you do not have to minimize the number of swaps β€” your task is to find any sequence that is no longer than n.
In the first line print k (0 ≀ k ≀ n) β€” the number of swaps. Next k lines must contain the descriptions of the k swaps, one per line. Each swap should be printed as a pair of integers i, j (0 ≀ i, j ≀ n - 1), representing the swap of elements ai and aj. You can print indices in the pairs in any order. The swaps are performed in the order they appear in the output, from the first to the last. It is allowed to print i = j and swap the same pair of elements multiple times. If there are multiple answers, print any of them. It is guaranteed that at least one answer exists.
C
b3c6058893f935d88196113fab581cf8
d0a550abe81badd3ac6340e0ed217e1d
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "sortings", "greedy" ]
1416238500
["5\n5 2 5 1 4", "6\n10 20 20 40 60 60", "2\n101 100"]
null
PASSED
1,200
standard input
1 second
The first line of the input contains integer n (1 ≀ n ≀ 3000) β€” the number of array elements. The second line contains elements of array: a0, a1, ..., an - 1 ( - 109 ≀ ai ≀ 109), where ai is the i-th element of the array. The elements are numerated from 0 to n - 1 from left to right. Some integers may appear in the array more than once.
["2\n0 3\n4 2", "0", "1\n0 1"]
/* https://codeforces.com/contest/489/submission/19697507 (rainboy) */ #include <stdio.h> #define N 3000 #define INF 1000000001 int main() { static int aa[N]; int n, i; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &aa[i]); printf("%d\n", n); for (i = 0; i < n; i++) { int j, j_, min, tmp; min = INF; j_ = -1; for (j = i; j < n; j++) if (min > aa[j]) { min = aa[j]; j_ = j; } printf("%d %d\n", i, j_); tmp = aa[i], aa[i] = aa[j_], aa[j_] = tmp; } return 0; }
In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.Note that in this problem you do not have to minimize the number of swaps β€” your task is to find any sequence that is no longer than n.
In the first line print k (0 ≀ k ≀ n) β€” the number of swaps. Next k lines must contain the descriptions of the k swaps, one per line. Each swap should be printed as a pair of integers i, j (0 ≀ i, j ≀ n - 1), representing the swap of elements ai and aj. You can print indices in the pairs in any order. The swaps are performed in the order they appear in the output, from the first to the last. It is allowed to print i = j and swap the same pair of elements multiple times. If there are multiple answers, print any of them. It is guaranteed that at least one answer exists.
C
b3c6058893f935d88196113fab581cf8
c53cab4458737162373ae80515900ffc
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "sortings", "greedy" ]
1416238500
["5\n5 2 5 1 4", "6\n10 20 20 40 60 60", "2\n101 100"]
null
PASSED
1,200
standard input
1 second
The first line of the input contains integer n (1 ≀ n ≀ 3000) β€” the number of array elements. The second line contains elements of array: a0, a1, ..., an - 1 ( - 109 ≀ ai ≀ 109), where ai is the i-th element of the array. The elements are numerated from 0 to n - 1 from left to right. Some integers may appear in the array more than once.
["2\n0 3\n4 2", "0", "1\n0 1"]
#include <stdio.h> #include <stdlib.h> #define N 3000 int compare(const void *a, const void *b) { int ia = *(int *) a; int ib = *(int *) b; return ia - ib; } int main() { static int aa[N], bb[N], swaps[N][2]; int n, i, j, tmp, k; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &aa[i]); bb[i] = aa[i]; } qsort(bb, n, sizeof *bb, compare); k = 0; for (i = 0; i < n; i++) for (j = i; j < n; j++) if (aa[j] == bb[i]) { if (i != j) { swaps[k][0] = i; swaps[k][1] = j; tmp = aa[i]; aa[i] = aa[j]; aa[j] = tmp; k++; } break; } printf("%d\n", k); for (i = 0; i < k; i++) printf("%d %d\n", swaps[i][0], swaps[i][1]); return 0; }
In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.Note that in this problem you do not have to minimize the number of swaps β€” your task is to find any sequence that is no longer than n.
In the first line print k (0 ≀ k ≀ n) β€” the number of swaps. Next k lines must contain the descriptions of the k swaps, one per line. Each swap should be printed as a pair of integers i, j (0 ≀ i, j ≀ n - 1), representing the swap of elements ai and aj. You can print indices in the pairs in any order. The swaps are performed in the order they appear in the output, from the first to the last. It is allowed to print i = j and swap the same pair of elements multiple times. If there are multiple answers, print any of them. It is guaranteed that at least one answer exists.
C
b3c6058893f935d88196113fab581cf8
1e103e35ae7894d5456764a69875c566
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "sortings", "greedy" ]
1416238500
["5\n5 2 5 1 4", "6\n10 20 20 40 60 60", "2\n101 100"]
null
PASSED
1,200
standard input
1 second
The first line of the input contains integer n (1 ≀ n ≀ 3000) β€” the number of array elements. The second line contains elements of array: a0, a1, ..., an - 1 ( - 109 ≀ ai ≀ 109), where ai is the i-th element of the array. The elements are numerated from 0 to n - 1 from left to right. Some integers may appear in the array more than once.
["2\n0 3\n4 2", "0", "1\n0 1"]
#include<stdio.h> int main() { int n, a[3010],i,j,m,temp; scanf("%d", &n); for (i = 0; i < n; ++i) scanf("%d", &a[i]); printf("%d\n", n); for (i = 0; i < n; ++i) { m = i; temp = a[i]; for (j = i + 1; j < n; ++j) { if (a[j] < temp) { temp = a[j]; m = j; } } a[m] = a[i]; a[i] = temp; printf("%d %d\n", i, m); } return 0; }
In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.Note that in this problem you do not have to minimize the number of swaps β€” your task is to find any sequence that is no longer than n.
In the first line print k (0 ≀ k ≀ n) β€” the number of swaps. Next k lines must contain the descriptions of the k swaps, one per line. Each swap should be printed as a pair of integers i, j (0 ≀ i, j ≀ n - 1), representing the swap of elements ai and aj. You can print indices in the pairs in any order. The swaps are performed in the order they appear in the output, from the first to the last. It is allowed to print i = j and swap the same pair of elements multiple times. If there are multiple answers, print any of them. It is guaranteed that at least one answer exists.
C
b3c6058893f935d88196113fab581cf8
ad319149fd99053e01111ab7a0a3061f
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "sortings", "greedy" ]
1416238500
["5\n5 2 5 1 4", "6\n10 20 20 40 60 60", "2\n101 100"]
null
PASSED
1,200
standard input
1 second
The first line of the input contains integer n (1 ≀ n ≀ 3000) β€” the number of array elements. The second line contains elements of array: a0, a1, ..., an - 1 ( - 109 ≀ ai ≀ 109), where ai is the i-th element of the array. The elements are numerated from 0 to n - 1 from left to right. Some integers may appear in the array more than once.
["2\n0 3\n4 2", "0", "1\n0 1"]
#include<stdio.h> int main() { int n,i,j,k,min,a=0; scanf("%d",&n); int x[n]; int y[n][2]; for(i=0;i<n;i++) scanf("%d",&x[i]); for(j=0;j<n;j++) { min=j; for(i=j+1;i<n;i++) { if(x[i]<x[min]) { min=i; } } if(min!=j) {k=x[min]; x[min]=x[j]; x[j]=k; y[a][0]=j; y[a][1]=min; a++;} } printf("%d\n",a); for(i=0;i<a;i++) printf("%d %d\n",y[i][0],y[i][1]); }
In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.Note that in this problem you do not have to minimize the number of swaps β€” your task is to find any sequence that is no longer than n.
In the first line print k (0 ≀ k ≀ n) β€” the number of swaps. Next k lines must contain the descriptions of the k swaps, one per line. Each swap should be printed as a pair of integers i, j (0 ≀ i, j ≀ n - 1), representing the swap of elements ai and aj. You can print indices in the pairs in any order. The swaps are performed in the order they appear in the output, from the first to the last. It is allowed to print i = j and swap the same pair of elements multiple times. If there are multiple answers, print any of them. It is guaranteed that at least one answer exists.
C
b3c6058893f935d88196113fab581cf8
5dedf0f71e76c925bc0c7e0b2f7157ad
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "sortings", "greedy" ]
1416238500
["5\n5 2 5 1 4", "6\n10 20 20 40 60 60", "2\n101 100"]
null
PASSED
1,200
standard input
1 second
The first line of the input contains integer n (1 ≀ n ≀ 3000) β€” the number of array elements. The second line contains elements of array: a0, a1, ..., an - 1 ( - 109 ≀ ai ≀ 109), where ai is the i-th element of the array. The elements are numerated from 0 to n - 1 from left to right. Some integers may appear in the array more than once.
["2\n0 3\n4 2", "0", "1\n0 1"]
#include<stdio.h> int i,j,temp,swapi[3002],swapj[3002],cnt,min; int main() { int n,min_index,j; scanf("%d",&n); int a[n]; for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=0;i<n-1;i++) { min_index=i; for(j=i+1;j<n;j++) {if(a[j]<a[min_index]) { min_index=j; } } if(min_index!=i) { temp=a[i]; a[i]=a[min_index]; a[min_index]=temp; swapi[cnt]=i; swapj[cnt++]= min_index; } } printf("%d\n",cnt); for(i=0;i<cnt;i++) { printf("%d %d\n",swapi[i],swapj[i]); } return 0; }
In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.Note that in this problem you do not have to minimize the number of swaps β€” your task is to find any sequence that is no longer than n.
In the first line print k (0 ≀ k ≀ n) β€” the number of swaps. Next k lines must contain the descriptions of the k swaps, one per line. Each swap should be printed as a pair of integers i, j (0 ≀ i, j ≀ n - 1), representing the swap of elements ai and aj. You can print indices in the pairs in any order. The swaps are performed in the order they appear in the output, from the first to the last. It is allowed to print i = j and swap the same pair of elements multiple times. If there are multiple answers, print any of them. It is guaranteed that at least one answer exists.
C
b3c6058893f935d88196113fab581cf8
a74c738e45b3fb041d57febe45291d7f
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "sortings", "greedy" ]
1416238500
["5\n5 2 5 1 4", "6\n10 20 20 40 60 60", "2\n101 100"]
null
PASSED
1,200
standard input
1 second
The first line of the input contains integer n (1 ≀ n ≀ 3000) β€” the number of array elements. The second line contains elements of array: a0, a1, ..., an - 1 ( - 109 ≀ ai ≀ 109), where ai is the i-th element of the array. The elements are numerated from 0 to n - 1 from left to right. Some integers may appear in the array more than once.
["2\n0 3\n4 2", "0", "1\n0 1"]
#include<stdio.h> int main() { int n,x=0,idx; scanf("%d",&n); int in[n],ou[n]; long long ara[n]; long long min; for(int i=0;i<n;i++) { scanf("%I64d",&ara[i]); in[i]=-1; ou[i]=-1; } for(int i=0;i<n;i++) { min=ara[i]; idx=i; for(int j=i+1;j<n;j++) { if(min>ara[j]) { min=ara[j]; idx=j; ou[i]=j; } } if(idx!=i) { long long temp; temp=ara[i]; ara[i]=ara[idx]; ara[idx]=temp; x++; in[i]=i; } } printf("%d\n",x); for(int i=0;i<n;i++) { if(in[i]!=-1) { printf("%d %d\n",in[i],ou[i]); } } return 0; }
In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.Note that in this problem you do not have to minimize the number of swaps β€” your task is to find any sequence that is no longer than n.
In the first line print k (0 ≀ k ≀ n) β€” the number of swaps. Next k lines must contain the descriptions of the k swaps, one per line. Each swap should be printed as a pair of integers i, j (0 ≀ i, j ≀ n - 1), representing the swap of elements ai and aj. You can print indices in the pairs in any order. The swaps are performed in the order they appear in the output, from the first to the last. It is allowed to print i = j and swap the same pair of elements multiple times. If there are multiple answers, print any of them. It is guaranteed that at least one answer exists.
C
b3c6058893f935d88196113fab581cf8
1604299f45c13aaab53348973e0dbaae
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "sortings", "greedy" ]
1416238500
["5\n5 2 5 1 4", "6\n10 20 20 40 60 60", "2\n101 100"]
null
PASSED
1,200
standard input
1 second
The first line of the input contains integer n (1 ≀ n ≀ 3000) β€” the number of array elements. The second line contains elements of array: a0, a1, ..., an - 1 ( - 109 ≀ ai ≀ 109), where ai is the i-th element of the array. The elements are numerated from 0 to n - 1 from left to right. Some integers may appear in the array more than once.
["2\n0 3\n4 2", "0", "1\n0 1"]
#include <stdio.h> int min(int* a,int i,int n) { int j=0,mini=i; for(j=i;j<n;j++) { if(a[mini]>a[j]) mini=j; } return mini; } int main() { int n,i; scanf("%d",&n); int a[n]; int b[2*n]; int k,count=0,p=0,j; for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) { k=min(a,i,n); if(k!=i) { b[p]=i; b[p+1]=k; j=a[i]; a[i]=a[k]; a[k]=j; count++; p=p+2; } } printf("%d",count); for(i=0;i<p;i=i+2) { printf("\n%d %d",b[i],b[i+1]); } }
In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.Note that in this problem you do not have to minimize the number of swaps β€” your task is to find any sequence that is no longer than n.
In the first line print k (0 ≀ k ≀ n) β€” the number of swaps. Next k lines must contain the descriptions of the k swaps, one per line. Each swap should be printed as a pair of integers i, j (0 ≀ i, j ≀ n - 1), representing the swap of elements ai and aj. You can print indices in the pairs in any order. The swaps are performed in the order they appear in the output, from the first to the last. It is allowed to print i = j and swap the same pair of elements multiple times. If there are multiple answers, print any of them. It is guaranteed that at least one answer exists.
C
b3c6058893f935d88196113fab581cf8
fcf4516bcc7151bcbea7b4b940b9e75b
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "sortings", "greedy" ]
1416238500
["5\n5 2 5 1 4", "6\n10 20 20 40 60 60", "2\n101 100"]
null
PASSED
1,200
standard input
1 second
The first line of the input contains integer n (1 ≀ n ≀ 3000) β€” the number of array elements. The second line contains elements of array: a0, a1, ..., an - 1 ( - 109 ≀ ai ≀ 109), where ai is the i-th element of the array. The elements are numerated from 0 to n - 1 from left to right. Some integers may appear in the array more than once.
["2\n0 3\n4 2", "0", "1\n0 1"]
#include <stdio.h> #include <string.h> #include <stdlib.h> int main() { int n,i,j,sel; scanf("%d",&n); int *arr=malloc(sizeof(int)*n); for (i=0;i<n;i++) scanf("%d",&arr[i]); printf("%d\n",n); for (i=0;i<n;i++){ sel=i; for (j=i+1;j<n;j++){ if (arr[sel]>arr[j]) sel=j; } printf("%d %d\n",i,sel); arr[sel]+=arr[i]; arr[i]=arr[sel]-arr[i]; arr[sel]=arr[sel]-arr[i]; } return 0; }
In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.Note that in this problem you do not have to minimize the number of swaps β€” your task is to find any sequence that is no longer than n.
In the first line print k (0 ≀ k ≀ n) β€” the number of swaps. Next k lines must contain the descriptions of the k swaps, one per line. Each swap should be printed as a pair of integers i, j (0 ≀ i, j ≀ n - 1), representing the swap of elements ai and aj. You can print indices in the pairs in any order. The swaps are performed in the order they appear in the output, from the first to the last. It is allowed to print i = j and swap the same pair of elements multiple times. If there are multiple answers, print any of them. It is guaranteed that at least one answer exists.
C
b3c6058893f935d88196113fab581cf8
6c8ad54d512ce629a74d9cb53ab5885c
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "sortings", "greedy" ]
1416238500
["5\n5 2 5 1 4", "6\n10 20 20 40 60 60", "2\n101 100"]
null
PASSED
1,200
standard input
1 second
The first line of the input contains integer n (1 ≀ n ≀ 3000) β€” the number of array elements. The second line contains elements of array: a0, a1, ..., an - 1 ( - 109 ≀ ai ≀ 109), where ai is the i-th element of the array. The elements are numerated from 0 to n - 1 from left to right. Some integers may appear in the array more than once.
["2\n0 3\n4 2", "0", "1\n0 1"]
#include<stdio.h> int main() { int n, a[3001], b[3001], t, i, j, c = 0, x[3001], y[3001]; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &a[i]), b[i] = a[i]; for (i = 1; i < n; i++) for (j = 0; j < n - 1; j++) if (a[j] > a[j + 1]) t = a[j], a[j] = a[j + 1], a[j + 1] = t; for (j = 0; j < n; j++) if (a[j] != b[j]) for (i = j + 1; i < n; i++) if (a[j] == b[i]) { b[i] = b[j]; x[c] = j; y[c] = i; c++; break; } printf("%d\n", c); for (i = 0; i < c; i++) printf("%d %d\n", x[i], y[i]); return 0; }
In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.Note that in this problem you do not have to minimize the number of swaps β€” your task is to find any sequence that is no longer than n.
In the first line print k (0 ≀ k ≀ n) β€” the number of swaps. Next k lines must contain the descriptions of the k swaps, one per line. Each swap should be printed as a pair of integers i, j (0 ≀ i, j ≀ n - 1), representing the swap of elements ai and aj. You can print indices in the pairs in any order. The swaps are performed in the order they appear in the output, from the first to the last. It is allowed to print i = j and swap the same pair of elements multiple times. If there are multiple answers, print any of them. It is guaranteed that at least one answer exists.
C
b3c6058893f935d88196113fab581cf8
53a348170747f1b4cda4c01714038a93
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "sortings", "greedy" ]
1416238500
["5\n5 2 5 1 4", "6\n10 20 20 40 60 60", "2\n101 100"]
null
PASSED
1,200
standard input
1 second
The first line of the input contains integer n (1 ≀ n ≀ 3000) β€” the number of array elements. The second line contains elements of array: a0, a1, ..., an - 1 ( - 109 ≀ ai ≀ 109), where ai is the i-th element of the array. The elements are numerated from 0 to n - 1 from left to right. Some integers may appear in the array more than once.
["2\n0 3\n4 2", "0", "1\n0 1"]
#include<stdio.h> main() { int n,i,j,li,temp,swap=0,c=0; scanf("%d",&n); int a[n],x[n],y[n]; for(i=0;i<n;i++){ scanf("%d",&a[i]); } for(i=0;i<n-1;i++){ li=i; for(j=i+1;j<n;j++){ if(a[j]<a[li]){ li=j; } } if(li!=i){ x[c]=i; y[c]=li; temp=a[i]; a[i]=a[li]; a[li]=temp; swap++; c++; } } printf("%d\n",swap); for(i=0;i<c;i++){ printf("%d %d\n",x[i],y[i]); } }
In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.Note that in this problem you do not have to minimize the number of swaps β€” your task is to find any sequence that is no longer than n.
In the first line print k (0 ≀ k ≀ n) β€” the number of swaps. Next k lines must contain the descriptions of the k swaps, one per line. Each swap should be printed as a pair of integers i, j (0 ≀ i, j ≀ n - 1), representing the swap of elements ai and aj. You can print indices in the pairs in any order. The swaps are performed in the order they appear in the output, from the first to the last. It is allowed to print i = j and swap the same pair of elements multiple times. If there are multiple answers, print any of them. It is guaranteed that at least one answer exists.
C
b3c6058893f935d88196113fab581cf8
f25d99c3d026a50929169404f7c23a3e
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "sortings", "greedy" ]
1416238500
["5\n5 2 5 1 4", "6\n10 20 20 40 60 60", "2\n101 100"]
null
PASSED
1,200
standard input
1 second
The first line of the input contains integer n (1 ≀ n ≀ 3000) β€” the number of array elements. The second line contains elements of array: a0, a1, ..., an - 1 ( - 109 ≀ ai ≀ 109), where ai is the i-th element of the array. The elements are numerated from 0 to n - 1 from left to right. Some integers may appear in the array more than once.
["2\n0 3\n4 2", "0", "1\n0 1"]
#include<stdio.h> int main() { int n,z=0,res[3000][2],cnt=0; scanf("%d",&n); int ar[n]; for(int i=0;i<n;i++) scanf("%d",&ar[i]); for(int i=0;i<n;i++) { int j=i; for(int t=i;t<n;t++) { if(ar[j]>ar[t]) j=t; } if(i!=j) { cnt++; res[z][0]=i; res[z++][1]=j; // } int temp=ar[i]; ar[i]=ar[j]; ar[j]=temp; } printf("%d\n",cnt); for(int i=0;i<z;i++) printf("%d %d\n",res[i][0],res[i][1]); return 0; }
In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.Note that in this problem you do not have to minimize the number of swaps β€” your task is to find any sequence that is no longer than n.
In the first line print k (0 ≀ k ≀ n) β€” the number of swaps. Next k lines must contain the descriptions of the k swaps, one per line. Each swap should be printed as a pair of integers i, j (0 ≀ i, j ≀ n - 1), representing the swap of elements ai and aj. You can print indices in the pairs in any order. The swaps are performed in the order they appear in the output, from the first to the last. It is allowed to print i = j and swap the same pair of elements multiple times. If there are multiple answers, print any of them. It is guaranteed that at least one answer exists.
C
b3c6058893f935d88196113fab581cf8
6e045771d3274aa7de354516716c1f6c
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "sortings", "greedy" ]
1416238500
["5\n5 2 5 1 4", "6\n10 20 20 40 60 60", "2\n101 100"]
null
PASSED
1,200
standard input
1 second
The first line of the input contains integer n (1 ≀ n ≀ 3000) β€” the number of array elements. The second line contains elements of array: a0, a1, ..., an - 1 ( - 109 ≀ ai ≀ 109), where ai is the i-th element of the array. The elements are numerated from 0 to n - 1 from left to right. Some integers may appear in the array more than once.
["2\n0 3\n4 2", "0", "1\n0 1"]
#include<stdio.h> int main() { int ara[4000],fara[4000]; int n,i,j,k,a,b,c; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&ara[i]); fara[i]=ara[i]; } for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(fara[j]<fara[i]) { k=fara[j]; fara[j]=fara[i]; fara[i]=k; } } } int count=0,f=0,loop[3000]; for(i=0;i<n;i++) { if(fara[i]!=ara[i]) { count++; for(j=i+1;j<n;j++) { if(fara[i]==ara[j]) { k=j; break; } } c=ara[i]; ara[i]=ara[j]; ara[j]=c; loop[f]=i; loop[f+1]=k; f+=2; } } printf("%d\n",count); for(i=0;i<f-1;i+=2) { printf("%d %d\n",loop[i],loop[i+1]); } return 0; }
You are given two integers $$$a$$$ and $$$b$$$. Moreover, you are given a sequence $$$s_0, s_1, \dots, s_{n}$$$. All values in $$$s$$$ are integers $$$1$$$ or $$$-1$$$. It's known that sequence is $$$k$$$-periodic and $$$k$$$ divides $$$n+1$$$. In other words, for each $$$k \leq i \leq n$$$ it's satisfied that $$$s_{i} = s_{i - k}$$$.Find out the non-negative remainder of division of $$$\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i}$$$ by $$$10^{9} + 9$$$.Note that the modulo is unusual!
Output a single integerΒ β€” value of given expression modulo $$$10^{9} + 9$$$.
C
607e670403a40e4fddf389caba79607e
10e2ade1b7f605840a2b4965f28abe6e
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "number theory", "math" ]
1523973900
["2 2 3 3\n+-+", "4 1 5 1\n-"]
NoteIn the first example:$$$(\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i})$$$ = $$$2^{2} 3^{0} - 2^{1} 3^{1} + 2^{0} 3^{2}$$$ = 7In the second example:$$$(\sum \limits_{i=0}^{n} s_{i} a^{n - i} b^{i}) = -1^{4} 5^{0} - 1^{3} 5^{1} - 1^{2} 5^{2} - 1^{1} 5^{3} - 1^{0} 5^{4} = -781 \equiv 999999228 \pmod{10^{9} + 9}$$$.
PASSED
1,800
standard input
1 second
The first line contains four integers $$$n, a, b$$$ and $$$k$$$ $$$(1 \leq n \leq 10^{9}, 1 \leq a, b \leq 10^{9}, 1 \leq k \leq 10^{5})$$$. The second line contains a sequence of length $$$k$$$ consisting of characters '+' and '-'. If the $$$i$$$-th character (0-indexed) is '+', then $$$s_{i} = 1$$$, otherwise $$$s_{i} = -1$$$. Note that only the first $$$k$$$ members of the sequence are given, the rest can be obtained using the periodicity property.
["7", "999999228"]
#include <stdio.h> typedef long long ll; #define LEN 100005 #define MOD 1000000009 ll invMOD(ll x) { if (x==1) return 1; return (ll)(MOD-MOD/x)* invMOD(MOD % x)%MOD; } ll fastPOWMOD(ll a, ll x) { ll ret=1; while (x) { if (x&1) ret=(ll)ret*a%MOD; a=(ll)a*a%MOD; x>>=1; } return ret; } int main() { int n,a,b,k; scanf("%i %i %i %i",&n,&a,&b,&k); char op[LEN]; scanf("%s",op); ll sum=0; for (int i=0;i<k;i++) { sum=(sum+(op[i]=='+'?1:-1)* fastPOWMOD(a, n - i)* fastPOWMOD(b, i)%MOD+MOD)%MOD; } ll q= invMOD(fastPOWMOD(a, k))* fastPOWMOD(b, k)%MOD,p=(n+1)/k; if (q==1) printf("%I64d ",sum*p%MOD); else printf("%I64d ",sum*(fastPOWMOD(q, p)-1)%MOD* invMOD(q - 1)%MOD); return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
50c1788302877ae71ac940821ab69c78
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
#include <stdio.h> #include <stdlib.h> long long v[100002]; int main() { int n,d,i,j; long long nr=0; //freopen("p.in","r",stdin); //freopen("p.out","w",stdout); scanf("%d%d",&n,&d); v[n+1]=10000000000LL; for(i=1; i<=n; i++) scanf("%I64d",&v[i]); for(i=1; i<=n && v[i]-v[1]<d; i++) if(i>2) nr+=(long long)(i-2)*(i-1)/2; if(i>1 && v[i]-v[1]<=d) nr+=(long long)(i-2)*(i-1)/2; while(i<=n && v[i]-v[1]<=d) i++; j=1; for(; i<=n; i++) { while(j<=i && v[i]-v[j]>d) j++; if(j<i) nr+=(long long)(i-j)*(i-j-1)/2; } printf("%I64d",nr); return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
68a459cc9d4c4db9fc4c09f6a5765ff2
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
#include <stdio.h> int main(void) { long long int N,d,pleft,pright,sum=0,pinakas[100005],count; scanf("%I64d%I64d",&N,&d); for(count=0;count<N;count++) scanf("%I64d",&pinakas[count]); for(pleft=0,pright=2;pleft<=N-3;){ while(llabs(pinakas[pleft]-pinakas[pright])<=d){ if(pright<N-1) pright++; else { //printf("pleft=%d pright=%d\n",pleft,pright); sum+=(pright-pleft+1)*(pright-pleft)*(pright-pleft-1)/6; goto end; } } pright--; //printf("##pleft=%d pright=%d\n",pleft,pright); if(llabs(pinakas[pleft]-pinakas[pright])<=d) sum+=(pright-pleft)*(pright-pleft-1)/2; pleft++; if(pright-pleft<2) if(pleft+2<=N-1) pright=pleft+2; else goto end; } end: printf("%I64d",sum); return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
adee6b37823b259c2a264563da2908f3
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
#include <stdio.h> int n,d; long long ans,num[100010]; int main() { int i,j; scanf("%d%d",&n,&d); for(i=1;i<=n;i++) scanf("%I64d",&num[i]); num[n+1] = 2100000000; for(i=j=1;i<=n;i++) { while(num[j]-num[i]<=d) j++; ans += (long long)(j-i-1)*(j-i-2)>>1; } printf("%I64d",ans); return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
9860576d77442db1310254b4e8809c8e
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
#include<stdio.h> int main() { int n,d,i=0,r=0; scanf("%d %d",&n,&d); int a[n]; for(i=0;i<n;i++) scanf("%d",&a[i]); long long c=0,p=0; for(i=0,r=0;i<n;i++) { while(r<n&&a[r]<=a[i]+d) r++; p=r-i-1; c=c+(p*(p-1))/2; } printf("%I64d",c); return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
64338fa2a1309b2e87a22cc29e16cbe5
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
#include <stdio.h> typedef long long ll; int x[100000]; void solve(int n, int d) { int l, r, m, i, p; ll ans; ans = 0; for (i = 0; i < n - 2; i ++) { l = i; r = n - 1; p = -1; while (l <= r) { m = (l + r) >> 1; if (x[m] - x[i] <= d) { p = m; l = m + 1; } else { r = m - 1; } } if (p - i >= 2) { ans += (ll)(p - i) * (p - i - 1) / 2; } } printf("%I64d\n", ans); } int main() { int n, d, i; while (scanf("%d%d", &n, &d) == 2) { for (i = 0; i < n; i ++) { scanf("%d", &x[i]); } solve(n, d); } return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
1ccc4c96c6ccbb7948fedebae4a977da
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
#include<stdio.h> int main() { int i,j,n,k,p; __int64 t=0,t1=0,a[100001]={1}; scanf("%d %d",&n,&p); scanf("%I64d",&a[1]); for(i=2;i<=n;i++) { scanf("%I64d",&a[i]); while((a[i]-a[a[0]])>p)a[0]++; t+=((i-a[0])*(i-a[0]-1))/2; } printf("%I64d",t); return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
8e12e77f15e26c8ed2a97280b9f5a75f
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
#include<stdio.h> long long int result=0;int find_it_man(long long int key,long long int n,long long int positions[]){long long int low=0,high=n-1,medium=(low+high)/2,i,yes=0,s;for(i=0;i<n;i++){low=i+1,high=n-1,medium=(high+low)/2;for(;low<=high;){medium=(high+low)/2;if(positions[medium]==positions[i]+key){yes=1;break;}else if(positions[medium]>positions[i]+key){high=medium-1;}else{low=medium+1;}}if(yes==1){s=medium-i-1;if(s>=1){result=result+(s*(s+1))/2;}}else{s=low-i-2;if(s>=1){result=result+(s*(s+1))/2;}}yes=0;}return 0;}int main (){long long int i,n,m,r,d,positions[100000];scanf("%lld %lld",&n,&d);for(i=0;i<n;i++)scanf("%lld",&positions[i]);find_it_man(d,n,positions);printf("%lld\n",result);return 0;}
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
5aa5a2ca71a23294da1c6e43b454f655
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
#include <stdio.h> long long s[100005]; int main() { long long n, d,start=0,ans=0,i,j; scanf("%I64d%I64d", &n, &d); for(i=0; i < n; ++i) { scanf("%I64d",&s[i]); } for(j=2; j <n; ++j) { while(s[j]-s[start] > d) { ++start; } if(j-start-1 > 0) { ans=ans+ ((j-start-1)*(j-start))/2; } } printf("%I64d", ans); return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
b8ba53eede93e861e95a1a50b8e9804a
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
#include <stdio.h> typedef __int64 LL; int A[100001]; int N,D; int BinSearch(int i) { int Left=i,Right=N,Mid; LL temp; while(Right>Left) { Mid=(Left+Right)/2; temp=A[Mid]-A[i]; if(temp>D) { Right=Mid-1; } else if(temp==D) { return Mid; } else { Left=Mid+1; } } if(A[Left]-A[i]>D) { --Left; } return Left; } int main() { int i,j; LL M,Sum; scanf("%d %d",&N,&D); for(i=1; i<=N; ++i) { scanf("%d",&A[i]); } for(Sum=0,i=1; i<N; ++i) { j=BinSearch(i); M=j-i; Sum+=M*(M-1)/2; } printf("%I64d\n",Sum); return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
f05e0c0ba8d64e6c6dee1637469d544b
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
#include <stdio.h> typedef __int64 LL; LL A[100001]; LL N,D; int BinSearch(int i) { int Left=i,Right=N,Mid; LL temp; while(Right>Left) { Mid=(Left+Right)/2; temp=A[Mid]-A[i]; if(temp>D) { Right=Mid-1; } else if(temp==D) { return Mid; } else { Left=Mid+1; } } if(A[Left]-A[i]>D) { --Left; } return Left; } int main() { int i,j; LL M,Sum; scanf("%I64d %I64d",&N,&D); for(i=1; i<=N; ++i) { scanf("%I64d",&A[i]); } for(Sum=0,i=1; i<N; ++i) { j=BinSearch(i); M=j-i; Sum+=M*(M-1)/2; } printf("%I64d\n",Sum); return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
e8a2a0ba24a6575d91b0bb75c475a4d6
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
#include<stdio.h> #define N 100000 int main() { int n,d; scanf("%d%d",&n,&d); int i; int x[N]; for(i=0;i<n;i++){ scanf("%d",&x[i]); } if(n<3){ printf("0\n"); }else{ long long way=0; for(i=2;i<n;i++){ //printf("i=%d\n",i); //θΏ™ι‡Œε―ΉδΊŒεˆ†ζ³•ηš„δ½Ώη”¨ζ₯θ‡ͺ int target=x[i]-d; int left=0; int right=i; while(left<right){ //printf("left=%d,right=%d\n",left,right); int middle=(left+right)/2; if(target<=x[middle]){ right=middle; }else{ left=middle+1; } } //printf("********\nleft=%d,right=%d\n",left,right); //printf("elements=%d\n",i-left); long long elements=i-left; //printf("ways=%lld\n",elements*(elements-1)/2); way+=elements*(elements-1)/2; } printf("%lld\n",way); } return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
a51e6dfaeb9e70615fd24546ea176ae5
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
#include<stdio.h> #include<stdlib.h> #include<ctype.h> #include<math.h> #define max(a,b) a>b?a:b #define min(a,b) a<b?a:b int binaryL(int h,int n,int *a){ int beg=0,end=n-1,mid=(end+beg)/2; while (beg<=end) { if(a[mid]==h) return mid; if(a[mid]<h){ beg=mid+1; } else end=mid-1; mid=(end+beg)/2; } return mid; } int cmpfunc (const void * a, const void * b) { return ( *(int*)a - *(int*)b ); } int main(){ int n,d; scanf("%d %d",&n,&d); long long int i=0; int a[n]; while (i<n) { scanf("%d",&a[i]); i++; } //qsort(a, n, sizeof(int), cmpfunc);tt i=0;long long int sum=0; while(i<n){ long long int hh=binaryL(a[i]+d, n, a); if(a[hh]-a[i]<=d && hh-i>1) sum+=((hh-i-1)*(hh-i))/2; //printf("%d\n",); i++; }printf("%lld\n",sum); return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
1a1fc00e3fb1a81d7ec21e14c7f15297
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
#include<stdio.h> #include<stdlib.h> #include<ctype.h> #include<math.h> #define max(a,b) a>b?a:b #define min(a,b) a<b?a:b int binaryL(int h,int n,int *a){ int beg=0,end=n-1,mid=(end+beg)/2; while (beg<=end) { if(a[mid]==h) return mid; if(a[mid]<h){ beg=mid+1; } else end=mid-1; mid=(end+beg)/2; } return mid; } int cmpfunc (const void * a, const void * b) { return ( *(int*)a - *(int*)b ); } int main(){ int n,d; scanf("%d %d",&n,&d); long long int i=0; int a[n]; while (i<n) { scanf("%d",&a[i]); i++; } //qsort(a, n, sizeof(int), cmpfunc); i=0;long long int sum=0; while(i<n){ long long int hh=binaryL(a[i]+d, n, a); if(a[hh]-a[i]<=d && hh-i>1) sum+=((hh-i-1)*(hh-i))/2; //printf("%d\n",);; i++; }printf("%lld\n",sum); return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
4b76a159213c53971aaba87ccbb73127
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
#include<stdio.h> #include<math.h> long long int a[100001]; int ncr[100000][4]={0}; int bsearch(long long int x,int left,int right,long long d) { int mid; while(left<right) { //printf("yes\n"); mid=(left+right+1)/2; if((a[mid]-x)==d) return mid; if((a[mid]-x)<d) left=mid; if((a[mid]-x)>d) right=mid-1; } if((a[left]-x)<=d) return left; else return -1; } main() { long long int i,j,k,n,d,count,last,m; scanf("%lld %lld",&n,&d); for(i=0;i<n;i++) scanf("%lld",&a[i]); count=0; last=0; for(i=0;i<=n-3;i++) { k=bsearch(a[i],0,n-1,d); j=k-i+1; m=last-i+1; //printf("%lld\n",m); if(k!=-1) count=count+(j-2)*(j-1)*j/6; if(m>=3) { count-=(m-2)*(m-1)*m/6; } last=k; } printf("%lld\n",count); return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
61abe488d10162b32930db2595a52525
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
#include <stdio.h> int binary(int l, int r, int target, int arr[]) { if ( l <= r ) { int mid = (l+r)/2; if ( arr[mid] <= target && arr[mid+1] > target ) return mid; else if ( arr[mid] > target ) return binary(l, mid-1, target, arr); else return binary(mid+1, r, target, arr); } return -1; } int main() { int i; long long ans; int n, d; int arr[100005]; scanf("%d%d", &n, &d); for ( i = 0; i < n; i++ ) scanf("%d", &arr[i]); arr[n] = 2147483647; ans = 0; for ( i = 0; i < n-2; i++ ) { int index = binary(0, n, arr[i]+d, arr); if ( index > i+1 ) ans += (long long)(index-i)*(index-i-1)/2; } printf("%I64d\n", ans); return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
4a7f248f3f468b4db873790a1fe78ffb
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
#include <stdio.h> int binary(int l, int r, int target, int arr[]) { if ( l <= r ) { int mid = (l+r)/2; if ( arr[mid] <= target && arr[mid+1] > target ) return mid; else if ( arr[mid] > target ) return binary(l, mid-1, target, arr); else return binary(mid+1, r, target, arr); } return -1; } int main() { int i; int n, d; int arr[100005]; scanf("%d%d", &n, &d); for ( i = 0; i < n; i++ ) scanf("%d", &arr[i]); arr[n] = 2147483647; long long ans = 0; for ( i = 0; i < n-2; i++ ) { int index = binary(0, n, arr[i]+d, arr); if ( index > i+1 ) ans += (long long)(index-i)*(index-i-1)/2; } printf("%I64d\n", ans); return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
c787cbe0efb8012ffd0c0d516db63e91
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
#include <stdio.h> int binary(int l, int r, long long target, long long arr[]) { if ( l <= r ) { int mid = (l+r)/2; if ( arr[mid] <= target && arr[mid+1] > target ) return mid; else if ( arr[mid] > target ) return binary(l, mid-1, target, arr); else return binary(mid+1, r, target, arr); } return -1; } int main() { int i; long long ans; long long n, d; long long arr[100005]; scanf("%I64d%I64d", &n, &d); for ( i = 0; i < n; i++ ) scanf("%I64d", &arr[i]); arr[n] = 2147483647; ans = 0; for ( i = 0; i < n-2; i++ ) { int index = binary(0, n, arr[i]+d, arr); if ( index > i+1 ) ans += (long long)(index-i)*(index-i-1)/2; } printf("%I64d\n", ans); return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
31a1930baaf6193a23463ea680be92b6
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
#include <stdio.h> #include <string.h> long long n, d; long long i, j; long long num[100005]; long long ans = 0; long long find(long long start, long long i, long long j) { long long mid; while (i < j) { mid = (i + j) / 2; if (num[mid] - num[start] <= d) { i = mid + 1; } else { j = mid; } } mid = (i + j) / 2; if (num[mid] - num[start] > d) mid --; return mid; } int main() { scanf("%lld%lld", &n, &d); for (i = 0; i < n; i ++) scanf("%lld", &num[i]); for (i = 0; i < n - 2 ; i ++) { int j = find(i, i + 2, n - 1); if (j - i < 2) continue; ans += (j - i) * (j - i - 1) / 2; } printf("%lld\n", ans); return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
4fb39e3dc3e30d5c2be8997039f03b32
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
#include<stdio.h> #define SIZE 100010 int main() { long long int n; long long int d,a[SIZE]; scanf("%lld %lld",&n,&d); long long int i,p1,p2; long long int count1=0; for(i=0;i<n;i++) { scanf("%lld",&a[i]); } p1=0; p2=0; while(p2<n) { if(a[p2]-a[p1]<=d) { count1+=(p2-p1)*(p2-p1-1)/2; p2++; } else { p1++; } } printf("%lld",count1); return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
911da6b9fcbb7c0d16ad005807f50cf3
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
#include <stdio.h> int po[100001]; int main(void) { int n, d, i, j; long long w, tmp; scanf("%d%d", &n, &d); for(i = 0; i < n; i++) scanf("%d", &po[i]); w = 0; i = 0; j = i + 3; for(; i <= n - 3; i++){ if(po[i+2] - po[i] > d){ j = i + 3; continue; } for(; j < n && po[j] - po[i] <= d; j++) ; tmp = j -i - 1; w += tmp * (tmp-1) / 2; } printf("%I64d\n", w); return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
3c8316abbc42d1dc43baa20fd01da939
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
#include <stdio.h> #define sc(d) scanf("%I64d",&d); long long nc2(long long n) { if(n<2) return 0ll; return (n*(n-1))/(2ll); } int main() { long long n,d; sc(n);sc(d); long long a[n]; long long ans=0ll,i,j = 0ll; for(i=0ll;i<n;i++) sc(a[i]); for(i=0ll;i<n;i++) { while(a[j+1]-a[i] <=d && j+1<n) j++; //printf("%lld %lld\n",i,j ); ans += nc2(j-i); } printf("%I64d\n",ans); return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
3ffd3b791bc4113022b1a40e9dd78dca
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef long long int lint; typedef unsigned long long int ulint; #define N 100010 int a[N], seen[N]; int main() { int n, i, d; scanf("%d %d", &n, &d); for(i=0; i<n; i++) scanf("%d", &a[i]); memset(seen, 0, sizeof(seen)); lint ans = 0; int x = 0, y = 0; lint c = 0; while(y < n) { if(((lint)a[y] - a[x]) <= d) { y++; c++; } else { if(!seen[y-1]) { seen[y-1] = 1; lint t = y - x; lint _c = t - c; ans = ans + (c * (c - 1) * (c - 2)) / 6; ans = ans + (_c * c * (c - 1)) / 2; ans = ans + (_c * (_c - 1) * c) / 2; c = 0; } x++; } } lint t = y - x; lint _c = t - c; ans = ans + (c * (c - 1) * (c - 2)) / 6; ans = ans + (_c * c * (c - 1)) / 2; ans = ans + (_c * (_c - 1) * c) / 2; printf("%lld\n", ans); return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
cd7ca068b63f51707d31112dcaa54407
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
#include<stdio.h> typedef long long int lld; int arr[100005],d; lld sum=0; int main() { int j=1,n,i,start; scanf("%d%d",&n,&d); for(i=0;i<n;i++) scanf("%d",&arr[i]); for(start=0;start<n-2;start++)//find last number satisfying the condition { while(j<n&&arr[j]-arr[start]<=d) j++; sum=sum+(lld)(lld)(j-1LL-start)*(lld)(j-start-2LL)/2LL; } printf("%I64d ",sum); return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
e318a4fadafcf78d037074f86f0d161b
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef unsigned long long int lli; lli solve(int a[], int n, int d, int idx) { int st = idx; int end = n - 1; int key = a[idx]+d; int mid, last; int ct = 0; // find ct such that a[ct]<=key && a[ct+1]>key while (st <= end) { mid = (st+end)/2; if (a[mid] > key) { end = mid - 1; } else if (a[mid] <= key) { if (mid == end || a[mid+1]>key) { ct = mid; break; } else { st = mid + 1; } } } last = ct - idx; lli ans = (lli) last; ans = (ans*(ans-1))/2; return ans; } int main(void) { int n,d; scanf("%d %d",&n,&d); int a[n]; for (int i=0;i<n;++i) { scanf("%d",&a[i]); } lli ans = 0; for (int i=0;i<n;++i) { ans += solve(a,n,d,i); } printf("%llu",ans); return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
6f42fe49c5570ca962d39f9a5c3ae3ef
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
#include <stdio.h> long long s[100005]; int main() { long long n, d,start=0,ans=0,i,j; scanf("%I64d\t%I64d\n", &n, &d); for(i=0; i < n; ++i) { scanf("%I64d",&s[i]); } for(j=2; j <n; ++j) { while(s[j]-s[start] > d) { ++start; } if(j-start-1 > 0) { ans=ans+ ((j-start-1)*(j-start))/2; } } printf("\n%I64d", ans); return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
953a560a3c47799f459937b9b69ece1c
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
long long num[100005]; main() { long long int resp=0,l=0,val,i,n,d; scanf("%I64d %I64d",&n,&d); for(i=0;i<n;i++) scanf("%I64d",&num[i]); for(i=0;i<n;i++) { val=num[i]+d; for(;num[l]<=val && l<n;l++); if(l-i>1) resp+=(l-i-2)*(l-i-1)/2; } printf("%I64d",resp); return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
feb283e043a3eb17a343e71fafd3a35c
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
long long num[100005]; main() { long long int resp=0,l=0,val,i,n,d; scanf("%I64d %I64d",&n,&d); for(i=0;i<n;i++) scanf("%I64d",&num[i]); for(i=0;i<n;i++) { val=num[i]+d; for(;num[l]<=val && l<n;l++); if(l-i>1) resp+=(l-i-2)*(l-i-1)/2; } printf("%I64d",resp); return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
eaa6d892bb6891d3181d425a6e1f6d64
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
#include<stdio.h> int main() { long long int n,ar[100009],x,d,tmp; scanf("%lld%lld",&n,&d); for(x=0;x<n;x++) { scanf("%lld",&ar[x]); } if(n<2) { printf("0\n"); return 0; } long long int st = 0,end = 0,ans = 0; for(st=0;st<n-2;st++) { while(ar[end]-ar[st]<=d && end<n) end++; if(end == n) end--; if(ar[end]-ar[st] > d) end --; if(end-st>0) { tmp = end-st; tmp = (tmp*(tmp-1))/2; ans += tmp; } } printf("%lld\n",ans); return 0; }
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.
Print a single integer β€” the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier.
C
1f6491999bec55cb8d960181e830f4c8
91f8b821f71afb4958ed5359120e581c
GNU C
standard output
256 megabytes
train_001.jsonl
[ "combinatorics", "binary search", "two pointers" ]
1354807800
["4 3\n1 2 3 4", "4 2\n-3 -2 -1 0", "5 19\n1 10 20 30 50"]
NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.
PASSED
1,300
standard input
2 seconds
The first line contains two integers: n and d (1 ≀ n ≀ 105;Β 1 ≀ d ≀ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 β€” the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.
["4", "2", "1"]
#include<stdio.h> #include<stdlib.h> #include<string.h> int main() { int n, d, x[100005]; long long int ans=0; scanf("%d%d", &n, &d); for(int i=0; i<n; i++) scanf("%d", x+i); for(int i=0, j=0; i<n; i++) { while(x[i]-x[j]>d) j++; ans+=(long long)(i-j)*(i-j-1)/2; } printf("%I64d", ans); }
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are n inflorescences, numbered from 1 to n. Inflorescence number 1 is situated near base of tree and any other inflorescence with number i (i &gt; 1) is situated at the top of branch, which bottom is pi-th inflorescence and pi &lt; i.Once tree starts fruiting, there appears exactly one apple in each inflorescence. The same moment as apples appear, they start to roll down along branches to the very base of tree. Each second all apples, except ones in first inflorescence simultaneously roll down one branch closer to tree base, e.g. apple in a-th inflorescence gets to pa-th inflorescence. Apples that end up in first inflorescence are gathered by Arcady in exactly the same moment. Second peculiarity of this tree is that once two apples are in same inflorescence they annihilate. This happens with each pair of apples, e.g. if there are 5 apples in same inflorescence in same time, only one will not be annihilated and if there are 8 apples, all apples will be annihilated. Thus, there can be no more than one apple in each inflorescence in each moment of time.Help Arcady with counting number of apples he will be able to collect from first inflorescence during one harvest.
Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest.
C
a4563e6aea9126e20e7a33df664e3171
b06f218e114bd9153a62952e7471ba45
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "dfs and similar", "trees", "graphs" ]
1520177700
["3\n1 1", "5\n1 2 2 2", "18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4"]
NoteIn first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them.In the second example Arcady will be able to collect 3 apples. First one is one initially situated in first inflorescence. In a second apple from 2nd inflorescence will roll down to 1st (Arcady will collect it) and apples from 3rd, 4th, 5th inflorescences will roll down to 2nd. Two of them will annihilate and one not annihilated will roll down from 2-nd inflorescence to 1st one in the next second and Arcady will collect it.
PASSED
1,500
standard input
1 second
First line of input contains single integer number n (2 ≀ n ≀ 100 000) Β β€” number of inflorescences. Second line of input contains sequence of n - 1 integer numbers p2, p3, ..., pn (1 ≀ pi &lt; i), where pi is number of inflorescence into which the apple from i-th inflorescence rolls down.
["1", "3", "4"]
#define e(n) for(i=1;i<=n;i++) n,p[1<<17],d[1<<17],s[1<<17],ans,i; main(){ scanf("%d", &n); e(n-1)scanf("%d",&p[i+1]); e(n)s[d[i] = d[p[i]]+1]^=1; e(n)ans += s[i]; printf("%d\n", ans); }
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are n inflorescences, numbered from 1 to n. Inflorescence number 1 is situated near base of tree and any other inflorescence with number i (i &gt; 1) is situated at the top of branch, which bottom is pi-th inflorescence and pi &lt; i.Once tree starts fruiting, there appears exactly one apple in each inflorescence. The same moment as apples appear, they start to roll down along branches to the very base of tree. Each second all apples, except ones in first inflorescence simultaneously roll down one branch closer to tree base, e.g. apple in a-th inflorescence gets to pa-th inflorescence. Apples that end up in first inflorescence are gathered by Arcady in exactly the same moment. Second peculiarity of this tree is that once two apples are in same inflorescence they annihilate. This happens with each pair of apples, e.g. if there are 5 apples in same inflorescence in same time, only one will not be annihilated and if there are 8 apples, all apples will be annihilated. Thus, there can be no more than one apple in each inflorescence in each moment of time.Help Arcady with counting number of apples he will be able to collect from first inflorescence during one harvest.
Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest.
C
a4563e6aea9126e20e7a33df664e3171
de8902f433a145134a4fa8aa0950102a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "dfs and similar", "trees", "graphs" ]
1520177700
["3\n1 1", "5\n1 2 2 2", "18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4"]
NoteIn first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them.In the second example Arcady will be able to collect 3 apples. First one is one initially situated in first inflorescence. In a second apple from 2nd inflorescence will roll down to 1st (Arcady will collect it) and apples from 3rd, 4th, 5th inflorescences will roll down to 2nd. Two of them will annihilate and one not annihilated will roll down from 2-nd inflorescence to 1st one in the next second and Arcady will collect it.
PASSED
1,500
standard input
1 second
First line of input contains single integer number n (2 ≀ n ≀ 100 000) Β β€” number of inflorescences. Second line of input contains sequence of n - 1 integer numbers p2, p3, ..., pn (1 ≀ pi &lt; i), where pi is number of inflorescence into which the apple from i-th inflorescence rolls down.
["1", "3", "4"]
#define e(n) for(i=0;++i<=n;) n,p[1<<17],d[1<<17],s[1<<17],a,i; main(){ scanf("%d", &n); e(n-1)scanf("%d",&p[i+1]); e(n)s[d[i]=d[p[i]]+1]++; e(n)a+=s[i]&1; printf("%d",a); }
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are n inflorescences, numbered from 1 to n. Inflorescence number 1 is situated near base of tree and any other inflorescence with number i (i &gt; 1) is situated at the top of branch, which bottom is pi-th inflorescence and pi &lt; i.Once tree starts fruiting, there appears exactly one apple in each inflorescence. The same moment as apples appear, they start to roll down along branches to the very base of tree. Each second all apples, except ones in first inflorescence simultaneously roll down one branch closer to tree base, e.g. apple in a-th inflorescence gets to pa-th inflorescence. Apples that end up in first inflorescence are gathered by Arcady in exactly the same moment. Second peculiarity of this tree is that once two apples are in same inflorescence they annihilate. This happens with each pair of apples, e.g. if there are 5 apples in same inflorescence in same time, only one will not be annihilated and if there are 8 apples, all apples will be annihilated. Thus, there can be no more than one apple in each inflorescence in each moment of time.Help Arcady with counting number of apples he will be able to collect from first inflorescence during one harvest.
Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest.
C
a4563e6aea9126e20e7a33df664e3171
c980324cdc72d45ab07ceb81a7fb8c44
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "dfs and similar", "trees", "graphs" ]
1520177700
["3\n1 1", "5\n1 2 2 2", "18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4"]
NoteIn first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them.In the second example Arcady will be able to collect 3 apples. First one is one initially situated in first inflorescence. In a second apple from 2nd inflorescence will roll down to 1st (Arcady will collect it) and apples from 3rd, 4th, 5th inflorescences will roll down to 2nd. Two of them will annihilate and one not annihilated will roll down from 2-nd inflorescence to 1st one in the next second and Arcady will collect it.
PASSED
1,500
standard input
1 second
First line of input contains single integer number n (2 ≀ n ≀ 100 000) Β β€” number of inflorescences. Second line of input contains sequence of n - 1 integer numbers p2, p3, ..., pn (1 ≀ pi &lt; i), where pi is number of inflorescence into which the apple from i-th inflorescence rolls down.
["1", "3", "4"]
#define e(x) for(i=x;i<=n;i++) n,p[1<<17],d[1<<17],s[1<<17],a,i; main(){ scanf("%d", &n); e(2)scanf("%d",&p[i]); e(1)s[d[i]=d[p[i]]+1]^=1; e(1)a+=s[i]; printf("%d",a); }