304 North Cardinal St.
Dorchester Center, MA 02124

# Array Swaps CodeChef Solution

## Array Swaps CodeChef Solution in C++17

``````#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 998244353;

signed main() {
int n,m;
cin >> n >> m;
vector<int> a(n),b(m);
for(int i=0; i<n; i++)
cin >> a[i];
for(int i=0; i<m; i++)
cin >> b[i];
int ans = 0;
sort(a.begin(),a.end());
sort(b.begin(),b.end());
for(int i=0; i<m; i++)
{
if(b[i] < a[0])
ans += n;
else
break;
}
cout << ans;
}``````

## Array Swaps CodeChef Solution in C++14

``````#include<bits/stdc++.h>
#define ll long long int
#define llu unsigned long long int
#define FOR(i, t) for(int i = 0;i < (t);i++)
#define PI 3.14159265359
#define MOD 1000000007
using namespace std;
//
//
int main()
{
int n, m;
cin >> n >> m;
vector<int> a;
vector<int> b;
vector<int> :: iterator itr;
for(int i = 0;i < n;i++)
{
int x;
cin >> x;
a.push_back(x);
}
for(int i = 0;i < m;i++)
{
int x;
cin >> x;
b.push_back(x);
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
ll ans = 0;
for(int i = 0;i < m;i++)
{
if(b[i] < a[0])
{
ans+=n;
}
}
cout << ans << endl;
return 0;
}``````

## Array Swaps CodeChef Solution in PYTH 3

``````# cook your dish here
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ma = min(A)
x = 0
for i in B:
if i < ma:
x += N
print(x)``````

## Array Swaps CodeChef Solution in C

``````#include <stdio.h>

int main()
{
long n,m;
scanf("%lu %lu",&n,&m);
long a[n],b[m];
long i=1,j=1,z=0,min;
while(i<=n)
{
scanf("%lu",&a[i]);
if(i==1)
min=a[1];
else
if(a[i]<min)
min=a[i];
i++;
}
while(j<=m)
{
scanf("%lu",&b[j]);
if(b[j]>=min)
z++;
j++;
}
if(z)
printf("%lu",(m-z)*n);
else
printf("%lu",m*n);
return 0;
}``````

## Array Swaps CodeChef Solution in JAVA

``````/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static long M = 1000000007;

public static void main (String[] args) throws java.lang.Exception
{
BufferedWriter output = new BufferedWriter(
new OutputStreamWriter(System.out));

int N = s.nextInt();
int M = s.nextInt();

int min = Integer.MAX_VALUE;

for(int i = 0; i < N; i++) {
min = Math.min(min, s.nextInt());
}

long ans = 0;

for (int i = 0; i < M; i++) {
int val = s.nextInt();

if (val < min) {
ans += N;
}
}

output.write(ans + "\n");

output.flush();
}

private static int[] takeArrInput(FastReader fr, int N) {
int[] arr = new int[N];

for (int i = 0; i < N; i++) {
arr[i] = fr.nextInt();
}

return arr;
}

}

StringTokenizer st;

}

String next() {
while (st == null || !st.hasMoreElements()) {
try {
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}

int nextInt() {
return Integer.parseInt(next());
}

long nextLong() {
return Long.parseLong(next());
}

double nextDouble() {
return Double.parseDouble(next());
}

String nextLine() {
String str = "";
try {
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}

``````

## Array Swaps CodeChef Solution in PYPY 3

``````#Created by Pradeep
def solve():
n,m=map(int, input().split())
arr=list(map(int, input().split()))
brr=list(map(int, input().split()))
mi=min(arr)
brr.sort()
ans=0
for i in brr:
if i<mi:
ans+=n
print(ans)

solve()``````

## Array Swaps CodeChef Solution in PYTH

``````st = raw_input().split()
N = int(st[0])
M = int(st[1])
st = raw_input().split()
sm = int(st[0])
for x in st:
n = int(x)
if n < sm:
sm = n
# endif
# endfor x
st = raw_input().split()
tot = 0
for x in st:
n = int(x)
if n < sm:
tot += 1
# endif
# endfor x
r = tot*N
print r
``````

## Array Swaps CodeChef Solution in C#

``````using System;
using System.Collections.Generic;

public class Test
{

private static void Fill(IList<long> list, ref string str)
{
checked
{
list.Clear();
var strIdx = 0;
long sign = 1;
long curr = 0;

while (strIdx < str.Length)
{
if (str[strIdx] == ' ')
{
curr = 0;
sign = 1;
}
else if (str[strIdx] == '-')
{
sign = -1;
curr = 0;
}
else
{
curr *= 10;
curr += (long)(str[strIdx] - '0');
}

strIdx++;
}

}
}

{
}

{
}

public static void Main()
{
checked
{

List<long> nm = new List<long>(2);
List<long> a = new List<long>();
List<long> b = new List<long>();

//for (int test = 0; test < tests; test++)
{
Fill(nm, ref str);
var n = (int) nm[0];
var m = (int) nm[1];

Fill(a, ref str);
Fill(b, ref str);

b.Sort();
a.Sort();

long res = 0;

var min = a[0];

for (int i = 0; i < m; i++)
{
if (b[i] < min)
{
res += n;
}
else
{
min = b[i];
}
}

Console.WriteLine(res);
}
}
}
}``````

## Array Swaps CodeChef Solution in GO

``````package main

import (
"bufio"
"fmt"
"os"
)

func main() {
fmt.Println(solve(A, B))
}

func readInt(bytes []byte, from int, val *int) int {
i := from
sign := 1
if bytes[i] == '-' {
sign = -1
i++
}
tmp := 0
for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
tmp = tmp*10 + int(bytes[i]-'0')
i++
}
*val = tmp * sign
return i
}

return
}

a, b = res[0], res[1]
return
}

a, b, c = res[0], res[1], res[2]
return
}

res := make([]int, n)
x := 0
for i := 0; i < n; i++ {
for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
x++
}
}
return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
i := from

var tmp uint64
for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
tmp = tmp*10 + uint64(bytes[i]-'0')
i++
}
*val = tmp

return i
}

func solve(A []int, B []int) int64 {
var num = A[0]
for i := 1; i < len(A); i++ {
if A[i] < num {
num = A[i]
}
}
var res int64
n := int64(len(A))
for i := 0; i < len(B); i++ {
if B[i] < num {
res += n
}
}

return res
}

func search(n int, fn func(int) bool) int {
left, right := 0, n
for left < right {
mid := (left + right) / 2
if fn(mid) {
right = mid
} else {
left = mid + 1
}
}
return right
}

func reverse(arr []int) {
for i, j := 0, len(arr)-1; i < j; i, j = i+1, j-1 {
arr[i], arr[j] = arr[j], arr[i]
}
}``````
##### Array Swaps CodeChef Solution Review:

In our experience, we suggest you solve this Array Swaps CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Array Swaps CodeChef Solution.

Find on CodeChef

##### Conclusion:

I hope this Array Swaps CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.

Keep Learning!