prompt
string
response
string
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
n, m = map(int, input().split()) b = list(map(int, input().split())) g = list(map(int, input().split())) if max(b) > min(g): print(-1) else: total = m*sum(b) b.sort() g.sort() while len(g) > 0: current = 0 count = 1 if len(b) > 0: current = b.pop() while ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
from collections import Counter def sum_counter(cnt): return sum((cnt[k] * k for k in cnt.keys())) def main(): n, m = map(int, input().split()) b = Counter(map(int, input().split())) g = Counter(map(int, input().split())) ba = max(b.keys()) gi = min(g.keys()) if ba > gi: print('-...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
import java.util.Arrays; import java.util.HashSet; import java.util.Scanner; public class que3 { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int n = scn.nextInt(); int m = scn.nextInt(); long[] arr = new long[n]; long[] arr2 = new long[m]; for (int i = 0; i < n; i++) { ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; int main() { int64_t n, m; cin >> n >> m; int64_t a[n]; int64_t b[m]; int64_t mi = 0; int64_t ma = 0; for (int64_t i = 0; i < n; i++) cin >> a[i]; for (int64_t i = 0; i < m; i++) cin >> b[i]; int64_t mii = 1e18; for (int64_t i = 0; i < n; i++) { ma =...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; long long int mo = 1000000007; int a[100005]; int main() { int n, m; cin >> n >> m; vector<int> v1(n), v2(m); long long int ans = 0; for (int i = 0; i < n; i++) { cin >> v1[i]; ans += v1[i]; } for (int i = 0; i < m; i++) { cin >> v2[i]; } ans *...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Scanner; /** * Built using CHelper plug-in * Actual solution is at the top * * @author aryssoncf */ public class Main { public static void main(String[] args) { InputStream...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using ll = long long; using namespace std; ll boys[100001]; ll girls[100001]; bool cmp1(ll a, ll b) { return a > b; } int main() { ll N, M; cin >> N >> M; ll summin = 0; for (ll n = 0; n < N; n++) { ll x; cin >> x; summin += x; boys[n] = x; } for (ll m = 0; m < M; m+...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve() { int n, m; cin >> n >> m; vector<ll> b(n), g(m); for (int i = 0; i < n; i++) cin >> b[i]; for (int j = 0; j < m; j++) cin >> g[j]; sort(b.begin(), b.end()), sort(g.begin(), g.end()); if (b[n - 1] <= g[0]) { ll sum = 0; ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; template <class... Args> istream& read_args(Args&... args) { return (cin >> ... >> args); } template <typename T> istream& operator>>(istream& is, vector<T>& v) { for (auto& i : v) is >> i; return is; } template <typename T> ostream& operat...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; void run_case() { int n, m; cin >> n >> m; std::vector<int> a(n), b(m); for (auto &i : a) { cin >> i; } for (auto &i : b) { cin >> i; } long long mn = 0; sort(a.rbegin(), a.rend()); sort(b.begin(), b.end()); if (a[0] > b[0]) { cout << -1; ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
from sys import exit N, M = map(int, input().split()) B = list(map(int, input().split())) G = list(map(int, input().split())) B.sort() mB = B[-1] m2B = B[-2] mG = min(G) if mB > mG: print(-1) exit() if mB == mG: print(sum(B)*M + sum(G) - mB * M) exit() print(sum(B)*M + sum(G) - mB * M + mB - m2B)
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; bool func(const pair<long long, int> &a, const pair<long long, int> &b) { return a.first < b.first || a.first == b.first && a.second < b.second; } int main() { int n, m; int i; long long input; vector<long long> arr1, arr2; vector<pair<long long, int>> tot; ve...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } int N, M; long long b[1...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; long long mark[5010]; int main() { ios::sync_with_stdio(false); cin.tie(), cout.tie(); long long n, m; cin >> n >> m; long long a, b, c = 0, d, e, s = 0; multiset<long long> s1, s2; for (long long i = 0; i < n; i++) { cin >> a; c += (a * m); s1.ins...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#------------------------------warmup---------------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10; int n[2]; int a[2][N]; long long solve() { if (a[0][n[0]] > a[1][1]) return -1; long long ans = 0; for (int i = 1; i <= n[1]; i++) ans += a[1][i]; for (int i = 1; i < n[0]; i++) ans += 1LL * n[1] * a[0][i]; if (a[0][n[0]] < a[1][1]) ans += ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; template <class T, class U> inline void add_self(T &a, U b) { a += b; if (a >= mod) a -= mod; if (a < 0) a += mod; } template <class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; } template <class T, class U> inline void ma...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e5 + 5; const long long MOD = 1e9 + 7; const double EPS = 1e-8; bool cmp(int x, int y) { return x > y; } int a[MAX_N], b[MAX_N]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= m;...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
n, m = map(int, input().split()) b = list(map(int, input().split())) g = list(map(int, input().split())) b.sort() g.sort() ans = sum(g) + sum(b[:-1]) * m if b[-1] > g[0]: print(-1) elif b[-1] in g: print(ans) else: print(ans + b[-1] - b[-2])
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; void autoinput() { freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); } const long long mod = (1e9 + 7); long long b[100005], g[100005]; bool comp(long long a, long long c) { return a > c; } int main() { long long i, j, k, l, m, n; cin >> n >> m; for ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
import java.io.*; import java.nio.CharBuffer; import java.util.NoSuchElementException; public class P1159C { public static void main(String[] args) { SimpleScanner scanner = new SimpleScanner(System.in); PrintWriter writer = new PrintWriter(System.out); int n = scanner.nextInt(); ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
""" Author : raj1307 - Raj Singh Institute : Jalpaiguri Government Engineering College Date : 12.05.19 """ from __future__ import division, print_function import itertools,os,sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins imp...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
from fractions import gcd from math import factorial, ceil, sqrt, atan2, log, pi, e, asin,acos, cos, sin, floor, atan from itertools import * from fractions import Fraction import string import copy import random import bisect from decimal import * from collections import deque from sys import * digs = string.digits + ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
import java.util.*; public class TestClass { public static void main(String args[] ) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int[] boy = new int[n]; int[] girl =new int[m]; long b...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
''' CODED WITH LOVE BY SATYAM KUMAR ''' from sys import stdin, stdout import cProfile, math from collections import Counter,defaultdict,deque from bisect import bisect_left,bisect,bisect_right import itertools from copy import deepcopy from fractions import Fraction import sys, threading import operator as op from fun...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
import java.util.*; public class ThePartyAndTheSweets { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int m = in.nextInt(); long[] b = new long[n]; long[] g = new long[m]; for (int i = 0; i < n; i++) { ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
n, m = map(int, input().split()) B = list(map(int, input().split())) G = list(map(int, input().split())) if min(G) < max(B): print(-1) exit(0) cnt = 0 z = max(B) y = 0 f = 1 f2 = 0 for i in B: if i != z or f2: y = max(y, i) else: f2 = 1 for i in G: if i == z: f = 0 cnt +=...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, m; cin >> n >> m; vector<long long> b(n); vector<long long> g(m); long long sum = 0; long long u = 0; for (long long i = 0; i < n; i++) { cin >> b[i]; sum += b[i]; } ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
n, m = map( int, input().split() ) b = list(map(int, input().split())) g = list(map(int, input().split())) b.sort() g.sort() if b[-1] > g[ 0 ]: print( -1 ) else: ans = sum(b)*m if g[ 0 ] != b[ -1 ]: ans += g[ 0 ] - b[ -2 ] for i in range( 1, m): ans += g[ i ] - b[ -1 ] print( ans )
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> int compare(const void *a, const void *b) { int ia = *(int *)a; int ib = *(int *)b; return ia - ib; } int main() { static int aa[100000], bb[100000]; int n, m, i, j; long long ans; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) scanf("%d", &aa[i]); for (j = 0; j < m; j++) scan...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; int64_t n, m, i, sb, sg, b[179000], g[179000]; int main() { cin >> n >> m; for (i = 0; i < n; i++) cin >> b[i], sb += b[i]; for (i = 0; i < m; i++) cin >> g[i], sg += g[i]; sort(b, b + n); sort(g, g + m); cout << (g[0] < b[n - 1] ? -1 ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.Charset; import java.util.*; public class CF1158 { public static void main(String[] args) throws Exception { boolean local = System.getProperty("ONLINE_JUDGE") == nu...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n, m; cin >> n >> m; vector<long long int> b(n); vector<long long int> g(m); for (long long int i = 0; i < n; i++) cin >> b[i]; for (long long int i = 0; i < m; i++) cin >> g[i]; ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
import math import re import sys from collections import defaultdict from heapq import heappush, heappop from fractions import gcd NaN = float('NaN') inf = float('inf') range = xrange def read(type = int): return type(raw_input()) def read_list(type = int, split = ' ', F = None): if F: return map(lambda x:...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class A { InputStream is; PrintWriter out; String INPUT = ""; void solve() { int n = ni(), m = ni(); int[] a = na(...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { if (a >= b) return a; else return b; } long long min(long long a, long long b) { if (a >= b) return b; else return a; } int main() { long long n, m; cin >> n >> m; long long b[n]; long long g[m]; fo...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
/*Author: Satyajeet Singh, Delhi Technological University*/ import java.io.*; import java.util.*; import java.text.*; import java.lang.*; import java.math.*; public class Main{ /*********************************************Constants******************************************/ static PrintWriter...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3c3c3c3c; const long long LINF = 1ll * INF * INF * 2; const int N = 1000001; int n, m; int a[N]; int b[N]; int main(void) { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", a + i); for (int i = 0; i < m; i++) scanf("%d", b + i); sort(...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> int main() { long long n, m; std::cin >> n >> m; std::map<long long, int> count; std::set<long long> bs; long long bsum = 0; long long maxb = -1; for (int i = 0; i < n; i++) { long long num; std::cin >> num; bs.insert(num); if (count.find(num) == count.end()) count...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
import java.io.*; import java.util.*; /******************************\ * The solution is at the top * * * * Created by : azhar556 * \******************************/ public class Solution { static void solve() { int n = ni(); int m = ni(); long sumG = 0L; ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
import java.util.*; import java.io.*; import java.math.*; public class A{ public static void main(String[] args)throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); StringTokenizer st = new StringTokeniz...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2e5 + 10, oo = 1e9 + 10; void solve() { ll n, m; cin >> n >> m; ll a[n + 1], b[m + 1]; ll sumA = 0, sumB = 0; for (int i = 1; i <= n; ++i) { cin >> a[i]; sumA += a[i]; } for (int i = 1; i <= m; ++i) { cin >> b[i]...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n, m; scanf("%d %d", &n, &m); vector<ll> boys(n), girls(m); for (int i = 0; i < n; ++i) scanf("%lld", &boys[i]); for (int i = 0; i < m; ++i) scanf("%lld", &girls[i]); sort(boys.begin(), boys.end()); sort(girls.begin(), gi...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
// Created by Whiplash99 import java.io.*; import java.util.*; public class C { private static void shuffleArray(int[] arr) { int n = arr.length; Random rnd = new Random(); for(int i=0; i<n; ++i) { int tmp = arr[i]; int randomPos = ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.math.BigInteger; import jav...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
from collections import * from math import * n,m = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) a.sort() b.sort() j = m-1 ans = 0 if a[-1] > b[0]: print(-1) else: for i in range(n-1,-1,-1): ct = 0 if(j >= 0): while(j >= 0 and a[i] <= ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int[] brr=new int[m]; TreeMap<Integer,Integer> map=new TreeMap(); int max=-1; long sum=0; HashMap<Integer,Integer> map2=new...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.IOException; import java.util.TreeMap; import java.util.Map; impor...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> int main() { long long int n, m, i, boy[100000], girl[100000], bmax = INT_MIN, bmax2 = INT_MIN, gmin = INT_MAX, bsum = 0, gsum = 0, ans; scanf("%I64d %I64d", &n, &m); for (i = 1; i <= n; i++) { scanf("%I64d", &boy[i]); if (boy[i] > bmax) { bmax2 = bmax; bmax = bo...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; bool cmp(long long int x, long long int y) { return x > y; } long long int a[200005], b[200005]; int main() { long long int i, j, m, n, s, w, k, v, sum, sum1; while (~scanf("%lld %lld", &n, &m)) { v = 0; sum = 0; sum1 = 0; s = 0; for (i = 0; i < n; i...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
from decimal import Decimal n,m=input().split(" ") n=int(n) m=int(m) # n=4 # s="821 500 479 717" s=input() b=[int(x) for x in s.split(" ")] s=input() g=[int(x) for x in s.split(" ")] b=sorted(b) g=sorted(g) value=0 d=Decimal() bad=False presents=set() p=m-1 if g[0]<b[-1]: print(-1) else: for i in reversed(...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
n, m = (int(x) for x in input().split()) boys_out = sorted([int(x) for x in input().split()], reverse=True) girls_in = sorted([int(x) for x in input().split()]) max_boy = max(boys_out) ans = 0 for boy in boys_out: ans += boy * m count = 0 i = 0 for girl in girls_in: if girl < max_boy: print(-1) ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; int main() { long long int t = 1; while (t--) { long long int n, sum = 0, ct = 0, l, r, m, k, ans = 0; cin >> n >> m; long long int a[n]; for (long long int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } long long int b[m]; for ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); cin.sync_with_stdio(0); int n, m; cin >> n >> m; long long a[n]; long long b[m]; long long ans = 0; for (int i = 0; i < n; i++) { cin >> a[i]; ans += a[i] * m; } for (int i = 0; i < m; i++) { cin >> b[i]; } sort(a...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m; cin >> n >> m; long long int arr[n]; long long int brr[m]; bool crr[m]; long long int res = 0, sumo = 0; long long int maxi = INT32_MIN; long long int mini = INT32_MAX; for (long long int i = 0; i < n; i++) { cin >> arr...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int b[n]; int g[m]; for (int i = 0; i < n; i++) cin >> b[i]; for (int i = 0; i < m; i++) cin >> g[i]; sort(b, b + n); sort(g, g + m); if (b[n - 1] > g[0]) { cout << -1; return 0; } long long ans = 0; for ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
import math n, m = map(int, input().split()) b = list(map(int, input().split())) g = list(map(int, input().split())) first_max = 0 second_max = 0 for i in range(n): if b[i] < first_max and b[i] > second_max: second_max = b[i] if b[i] >= first_max: second_max = first_max first_max = b[i] # print(first_max, ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
import java.io.*; import java.util.*; public class Main { static Scanner in = new Scanner(System.in); static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) { int n = in.nextInt(); int m = in.nextInt(); long boyMax = 0; int NBoyMax = 0; long sweets = ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } const double EPS = 1e-10; const double...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
I=lambda:map(int,input().split()) n,m=I() a,b=sorted(I(),reverse=1),sorted(I()) s=sum(b) for i in range(1,n):s+=a[i]*m if a[0]>min(b):s=-1 elif a[0]!=b[0]:s+=a[0]-a[1] print(s)
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
from collections import Counter,deque as dq from sys import stdin input=stdin.readline ''' agar b[i]>g[j] for any i,j return -1 if max(b)>min(g) retunr-1 ''' def f(a,b): cnt=Counter(b) B=len(b) if max(a)>min(b): return -1 a=sorted(a) b=sorted(b) t=0 for i in a: t+=i*B for i in b[1:]: t+=i-a[-1] if b[0]>a...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
n, m = map(int, input().split()) b, g = sorted(map(int, input().split())), sorted(map(int, input().split())) print(-1 if b[-1] > g[0] else m * sum(b) + sum(gj - b[-1] for gj in g) + (b[-1] < g[0]) * (b[-1] - b[-2]))
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
mx1 = 0 mx2 = 0 sum = 0 def parsare(s, lista): number = "" for l in s: if l != " ": number += l else: lista.append(int(number)) number = "" lista.append(int(number)) row1 = [] row2 = [] row3 = [] sir = input() parsare(sir, row1) sir = input() parsare(...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
n,m = map(int,input().split() ) b = list(map(int,input().split())) g = list(map(int,input().split())) b.sort() g.sort() if b[len(b) - 1] <= g[0]: c = sum(b) * m if g[0] != b[len(b) - 1]: c = c + g[0] - b[len(b) - 2] for i in range(1,m): c = c + g[i] - b[len(b) - 1] else: c = -1 print(c)
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
n,m = map(int,input().split()) Boys = [int(x) for x in input().split()] Girls = [int(x) for x in input().split()] if(min(Girls)<max(Boys)): print(-1) else: Boys.sort(reverse = True) Girls.sort(reverse = True) Ans = 0 for i in range(n): Ans += Boys[i] * m g = 0 b = 0 bins = 1 ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; long long b[n + 1]; long long g[m + 1]; long long bma = 0; long long bsma = 0; long long bsum = 0; for (long long i = 1; i <= n; i++) { cin >> b[i]; if (b[i] > bma) { bsma = bma; bma = b[i]; ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
n, m = [int(i) for i in input().split()] mins = [int(i) for i in input().split()] maxs = [int(i) for i in input().split()] temp = mins[:] temp.sort() pivot = temp[-1] pivot2 = temp[-2] ans = sum(mins)*m ans += sum(maxs) ans -= pivot*(m-1) + pivot2 bad = False # for a in maxs: # if a < pivot: # bad = True...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
t=1 def solve(): l=0 ans=0 #print(l1,l2) if max(l1)>min(l2): return -1 for i in range(n): y=0 for j in range(l,m): if j==m-1 and y==m-1: if l1[i]==l2[j]: y+=1 ans+=l2[j] else: ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 10; long long n, m, ans, b[N], g[N]; int32_t main() { cin >> n >> m; for (long long i = 0; i < n; i++) cin >> b[i]; for (long long i = 0; i < m; i++) cin >> g[i]; sort(b, b + n); sort(g, g + m); if (b[n - 1] > g[0]) return cout << -1, 0...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; import java.lang.invoke.MethodHandles; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Pri...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
import java.io.*; import java.util.Collections; import java.util.PriorityQueue; import java.util.StringTokenizer; public class Main { static final int INF = (int) 1e9; public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintW...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; template <class c> struct rge { c h, n; }; template <class c> rge<c> range(c h, c n) { return rge<c>{h, n}; } template <class c, class F> struct rgm { c h, n; F f; }; template <class c, class F> rgm<c, F> map_range(c b, c e, F f) { retur...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
import java.util.*; import java.io.*; public class c { public static void main(String[] args) throws IOException { FastScanner sc = new FastScanner(System.in); int b = sc.nextInt(), g = sc.nextInt(); int[] boys = new int[b], girls = new int[g]; long boyTally = 0; for (int i = 0 ; i < b ; i++) { boys[i]...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double pi = 3.1415926535897932384626; inline long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; const int64_t M = 1e5 + 5; int64_t n, m, ans, b[M], g[M]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int64_t i = 0; i < n; i++) { cin >> b[i]; ans += (m * b[i]); } for (int64_t i = 0; i < m; i++) cin >> ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); ; long long int n, m; cin >> n >> m; vector<long long int> vn(n), vm(m); for (long long int i = 0; i < n; i++) cin >> vn[i]; sort(vn.begin(), vn.end()); for (long long int i = 0; i...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; vector<int> b(n); for (int i = 0; i < n; i++) { cin >> b[i]; } vector<int> g(m); for (int i = 0; i < m; i++) { cin >> g[i]; } sort(b.rbegin(), b.rend()); s...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; using ll = long long; int n, m; int mn[100007], mx[100007]; int main() { scanf("%d%d", &n, &m); int a = 0, b = 1e9, a2 = 0; for (int i = 0; i < n; i++) { scanf("%d", &mn[i]); if (mn[i] > a) { a2 = a; a = mn[i]; } else if (mn[i] > a2) a2 =...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
import java.util.Arrays; import java.util.Scanner; import java.util.*; public class Main { public static void main(String[] args) { Scanner stdin = new Scanner(System.in); /*int n = stdin.nextInt(); for(int i = 0; i < n; i++) { test(stdin); }*/ test(stdin...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.stream.IntStream; import java.util.stream.LongStream; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.UncheckedIOException; impor...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; bool check(vector<long long> a, long long m, long long n) { vector<long long> v(n + 1, 0); for (long long i = 0; i < n; i++) { v[a[i]] += 1; } set<pair<long long, long long>, greater<pair<long long, long long>>> s; for (long long i = 1; i < n + 1; i++) { i...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7; const long long mod = 998244353; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); long long binpow(long long a, long long b, long long m) { long long res = 1; while (b > 0) { if (b & 1) res = res * a % m; a = a...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; long long b[100005], g[100005]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%lld", &b[i]); for (int i = 0; i < m; i++) scanf("%lld", &g[i]); sort(b, b + n); sort(g, g + m); if (b[n - 1] > g[0]) puts("-1"); else { ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; const int maxn = 111111; int a[maxn]; int b[maxn]; int n, m; int main() { while (cin >> n >> m) { long long ans = 0; int mx = 0; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; long long s1 = 0; for (int i = 0; i <...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
/* roses are red memes are neat all my test cases time out lmao yeet */ import java.util.*; import java.io.*; public class C2 { public static void main(String args[]) throws Exception { BufferedReader infile = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
import java.util.*; public class qc{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=sc.nextInt(); int a[]=new int[n]; int b[]=new int[m]; for(int i=0;i<n;i++){ a[i]=sc.nextInt(); } for(i...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; int readint() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } long long n, m, ans; long l...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; ll total = 0; map<int, int, greater<int>> b; for (int i = 0; i < n; ++i) { int tmp; cin >> tmp; ++b[tmp]; total += 1LL * m ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
from sys import exit n, m = map(int, input().split()) b = list(map(int, input().split())) g = list(map(int, input().split())) if max(b) > min(g): print(-1) exit(0) b.sort() res = sum(g) + sum(b[:-1]) * m if b[-1] in g: print(res) else: print(res + b[-1] - b[-2])
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
/* 3 2 1 2 1 3 4 Sort boys from least to greatest, girls from least to greatest: 1: 3 1 2: 1 4 3: 2 2 Total sweets given: 3 + 1 + 1 + 4 + 2 + 2 = 13 Sort boys from greatest to least, girls from least to greatest: 1: 3 2 2: 1 4 3: 1 1 Total sweets given: 3 + 2 + 1 + 4 + 1 + 1 = 12 Sort boys from greatest to least, gi...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
import java.io.*; import java.util.*; public class ThePartyandSweets { public static void main(String[] args) { FastScanner in = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(), m = in.nextInt(); int a[] = in.readArray(n); int b[] = in.re...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
n,m=map(int,input().split()) l1=list(map(int,input().split())) l2=list(map(int,input().split())) l1.sort() l2.sort() l2=l2[::-1] if n==1: if l1[0]!=min(l2): print(-1) else : print(sum(l2)) elif max(l1)>min(l2): print(-1) else : ans=0 l1=l1[::-1] if min(l2)==l1[0]: print(s...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
//I AM THE CREED /* //I AM THE CREED /* package codechef; // don't place package name! */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.*; import java.awt.Point; public class Main{ static final Random random=new Ra...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; int n, m, num[maxn]; long long a[maxn], b[maxn], ans; map<int, int> f; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), ans += m * a[i], f[a[i]] = 1, num[i] = m; for (int i = 1; i <= m; i++) scanf("%...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
import java.util.*; public class r559c { public static void main(String[] args) { Scanner scan=new Scanner(System.in); int n=scan.nextInt(), m=scan.nextInt(); int[] b=new int[n], g=new int[m]; long cur=0L,max=0; for(int i=0;i<n;i++) { b[i]=scan.nextInt(); cur+=(long)m*b[i]; max=Math.max(max,b[i]); ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; template <class T> std::istream& operator>>(std::istream& in, std::vector<T>& data) { for (auto& item : data) { in >> item; } return in; } template <class T> std::ostream& operator<<(std::ostream& out, const std::vector<T>& data) { bool first = true; for (cons...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
n,m=map(int,input().split()) b=list(map(int,input().split())) g=list(map(int,input().split())) if max(b)>min(g): print(-1) else: maxi=0 maxi2=0 for guy in b: if guy>maxi: maxi2,maxi=maxi,guy elif guy>maxi2: maxi2=guy sumi=m*sum(b)+sum(g)-m*maxi+maxi-maxi2 ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; long long INF = 1e18; int INFi = 2e9; double eps = 1e-6; long long mod = 1e9 + 7; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); long long n, m; cin >> n >> m; vector<long long> a(n); vector<long long> b(m); for (int i = 0; i < n; i+...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; int N, M; long long b[100005], g[100005]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> M; for (int i = 1; i <= N; i++) { cin >> b[i]; } for (int j = 1; j <= M; j++) { cin >> g[j]; } int mxb = *max_element(b + 1, b + 1 ...
Problem: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; long long b[n + 1], g[m + 1]; b[0] = g[0] = 0; for (int i = 1; i <= n; i++) cin >> b[i]; for (int i = 1; i <= m; i++) cin >> g[i]; sort(b + 1, b + n + 1); sort(g + 1, g + m + 1); if (b[n] > g[1]) cout << -1; ...