A. Ehab and another construction problem
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Given an integer xx, find 2 integers aa and bb such that:
- 1≤a,b≤x1≤a,b≤x
- bb divides aa (aa is divisible by bb).
- a⋅b>xa⋅b>x.
- ab<xab<x.
Input
The only line contains the integer xx (1≤x≤100)(1≤x≤100).
Output
You should output two integers aa and bb, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print "-1" (without quotes).
Examples
input
10
output
6 3
input
1
output
-1
int main(){
int n,i,j,f=0;
scanf("%d",&n);
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
if((i*j<=n)&&(j*i*i>n)){
f=1;
printf("%d %d\n",i*j,i);
return 0;
}
}
}
printf("-1\n");
}
B. Ehab and subtraction
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
You're given an array aa. You should repeat the following operation kk times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0.
Input
The first line contains integers nn and kk (1≤n,k≤105)(1≤n,k≤105), the length of the array and the number of operations you should perform.
The second line contains nn space-separated integers a1,a2,…,ana1,a2,…,an (1≤ai≤109)(1≤ai≤109), the elements of the array.
Output
Print the minimum non-zero element before each operation in a new line.
Examples
input
3 5 1 2 3
output
1 1 1 0 0
input
4 2 10 3 5 3
output
3 2
Note
In the first sample:
In the first step: the array is [1,2,3][1,2,3], so the minimum non-zero element is 1.
In the second step: the array is [0,1,2][0,1,2], so the minimum non-zero element is 1.
In the third step: the array is [0,0,1][0,0,1], so the minimum non-zero element is 1.
In the fourth and fifth step: the array is [0,0,0][0,0,0], so we printed 0.
In the second sample:
In the first step: the array is [10,3,5,3][10,3,5,3], so the minimum non-zero element is 3.
In the second step: the array is [7,0,2,0][7,0,2,0], so the minimum non-zero element is 2.
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+5;
long long a[maxn];
int main(){
int n,k,c=1;
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++)
scanf("%lld",&a[i]);
sort(a,a+n);
printf("%lld\n",a[0]);
long long t=a[0];
for(int i=1;;i++){
if(c==k)
break;
if(a[i]-t>=0){
if((a[i]-t)!=0){
printf("%lld\n",a[i]-t);
c++;
}
t+=a[i]-t;
}
if(i>=n){
printf("0\n");
c++;
}
}
}
C. Ehab and a 2-operation task
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
You're given an array aa of length nn. You can perform the following operations on it:
- choose an index ii (1≤i≤n)(1≤i≤n), an integer xx (0≤x≤106)(0≤x≤106), and replace ajaj with aj+xaj+x for all (1≤j≤i)(1≤j≤i), which means add xx to all the elements in the prefix ending at ii.
- choose an index ii (1≤i≤n)(1≤i≤n), an integer xx (1≤x≤106)(1≤x≤106), and replace ajaj with aj%xaj%x for all (1≤j≤i)(1≤j≤i), which means replace every element in the prefix ending at ii with the remainder after dividing it by xx.
Can you make the array strictly increasing in no more than n+1n+1 operations?
Input
The first line contains an integer nn (1≤n≤2000)(1≤n≤2000), the number of elements in the array aa.
The second line contains nn space-separated integers a1a1, a2a2, ……, anan (0≤ai≤105)(0≤ai≤105), the elements of the array aa.
Output
On the first line, print the number of operations you wish to perform. On the next lines, you should print the operations.
To print an adding operation, use the format "11 ii xx"; to print a modding operation, use the format "22 ii xx". If ii or xx don't satisfy the limitations above, or you use more than n+1n+1 operations, you'll get wrong answer verdict.
Examples
input
Copy
3 1 2 3
output
Copy
0
input
Copy
3 7 6 3
output
Copy
2 1 1 1 2 2 4
Note
In the first sample, the array is already increasing so we don't need any operations.
In the second sample:
In the first step: the array becomes [8,6,3][8,6,3].
In the second step: the array becomes [0,2,3][0,2,3].
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,x;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&x);
printf("%d\n",n+1);
printf("2 %d 1\n",n);
printf("1 %d 1000000\n",n);
for(int i=1;i<=n-1;i++)
printf("2 %d %d\n",i,1000000-i);
}