98032024-03-07 00:42:22SleepyOverlordMaximális szorzat (50 pont)cpp17Hibás válasz 36/50100ms14824 KiB
#include <vector>
#include <string> 
#include <set> 
#include <map> 
#include <unordered_set>
#include <unordered_map>
#include <queue> 
#include <bitset> 
#include <stack>
#include <list>

#include <numeric> 
#include <algorithm> 
#include <random>
#include <chrono>

#include <cstdio>
#include <fstream>
#include <iostream> 
#include <sstream> 
#include <iomanip>
#include <climits>

#include <cctype>
#include <cmath> 
#include <ctime>
#include <cassert>

using namespace std;

#define ULL unsigned long long
#define LL long long
#define PII pair <int, int>
#define VB vector <bool>
#define VI vector <int>
#define VLL vector <LL>
#define VD vector <double>
#define VS vector <string>
#define VPII vector <pair <int, int> >
#define VVI vector < VI >
#define VVB vector < VB >
#define SI set < int >
#define USI unordered_set <int>
#define MII map <int, int>
#define UMII unordered_map <int, int>
#define MS multiset
#define US unordered_set
#define UM unordered_map
#define UMS unordered_multiset
#define UMM unordered_multimap

#define FORN(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define MX(x, y) x = max(x, y);
#define MN(x, y) x = min(x, y);

#define SZ size()
#define BG begin() 
#define EN end() 
#define CL clear()
#define X first
#define Y second
#define RS resize
#define PB push_back
#define MP make_pair
#define ALL(x) x.begin(), x.end()
#define INS insert
#define ER erase
#define CNT count

template <class T> ostream& operator <<(ostream & os, const vector<T> &vec)
{
	for (int i = 0; i < vec.size() - 1; ++i) os << vec[i] << ' ';
	return os << vec[vec.size() - 1];
}

template <class T1, class T2> ostream& operator <<(ostream & os, const pair<T1, T2> &p)
{
	return os << p.X << " " << p.Y;
}

template <typename T>
void pr(T var1)
{
	cout << var1 << '\n';
}
template <typename T, typename... Types>
void pr(T var1, Types... var2)
{
	cout << var1;
	pr(var2...);
}

void in(int &n, VI &a) //array of ints
{
	cin >> n;
	a.CL, a.RS(n + 1);
	FOR(i, 1, n) cin >> a[i];
}

void in(int &n, VS &a) //array of strings
{
	cin >> n;
	a.CL, a.RS(n + 1);
	FOR(i, 1, n) cin >> a[i];
}

void in(int &n, VPII &a) //array of pairs
{
	cin >> n;
	a.CL, a.RS(n + 1);
	FOR(i, 1, n) cin >> a[i].X >> a[i].Y;
}

void in(int &n, int &m, VVI &g) //unweighted graph
{
	cin >> n >> m;
	g.CL, g.RS(n + 1);
	FOR(i, 1, n)
	{
		int x, y;
		cin >> x >> y;
		g[x].PB(y);
		g[y].PB(x);
	}
}

void in(int &n, VVI &g) //unweighted tree
{
	cin >> n;
	g.CL, g.RS(n + 1);
	FOR(i, 1, n - 1)
	{
		int x, y;
		cin >> x >> y;
		g[x].PB(y);
		g[y].PB(x);
	}
}

void in(int &n, int &m, vector <VPII> &g) //weighted graph
{
	cin >> n >> m;
	g.CL, g.RS(n + 1);
	FOR(i, 1, n)
	{
		int x, y, z;
		cin >> x >> y >> z;
		g[x].PB({y, z});
		g[y].PB({x, z});
	}
}

void in(int &n, vector <VPII> &g) //weighted tree
{
	cin >> n;
	g.CL, g.RS(n + 1);
	FOR(i, 1, n - 1)
	{
		int x, y, z;
		cin >> x >> y >> z;
		g[x].PB({y, z});
		g[y].PB({x, z});
	}
}

const int MOD = 1e9 + 7;

int n, m, k;
VI a;
multiset<int> neg, poz;

int main()
{
	#ifdef AT_HOME
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	cin >> n >> m >> k;
	a.RS(n + 1);
	FOR(i, 1, n)
	{
		cin >> a[i];
		if (a[i] < 0) neg.INS(-a[i]);
		else poz.INS(a[i]);
	}
	if (neg.SZ < k)
	{
		pr(-1);
		return 0;
	}
	while (neg.SZ > k)
	{
		int mn = *neg.begin();
		m -= mn;
		if (m < 0)
		{
			pr(-1);
			return 0;
		}
		neg.erase(neg.begin());
		poz.INS(0);
	}
	while (m)
	{
		--m;
		if (!poz.empty())
		{
			int mn = *poz.begin();
			poz.ER(poz.begin());
			poz.INS(mn + 1);
		}
		else
		{
			int mn = *neg.rbegin();
			neg.ER(neg.find(mn));
			neg.INS(mn - 1);
		}
	}
	if (*neg.begin() <= 0)
	{
		pr(-1);
		return 0;
	}
	int sol = 1;
	for (int x : neg) sol = (LL)sol * x % MOD;
	for (int x : poz) sol = (LL)sol * x % MOD;
	pr(sol);

	return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base36/50
1Hibás válasz0/03ms1700 KiB
2Hibás válasz0/03ms1928 KiB
3Elfogadva0/03ms2152 KiB
4Elfogadva0/03ms2328 KiB
5Elfogadva0/06ms3536 KiB
6Hibás válasz0/23ms2748 KiB
7Hibás válasz0/23ms2816 KiB
8Hibás válasz0/23ms2924 KiB
9Hibás válasz0/23ms3064 KiB
10Hibás válasz0/28ms4200 KiB
11Hibás válasz0/268ms13296 KiB
12Hibás válasz0/167ms13352 KiB
13Elfogadva1/13ms3748 KiB
14Elfogadva1/110ms4772 KiB
15Elfogadva1/123ms8704 KiB
16Elfogadva1/150ms8712 KiB
17Elfogadva1/124ms8808 KiB
18Hibás válasz0/119ms8840 KiB
19Elfogadva1/193ms14168 KiB
20Elfogadva1/1100ms14080 KiB
21Elfogadva1/179ms14108 KiB
22Elfogadva1/186ms14252 KiB
23Elfogadva1/171ms14008 KiB
24Elfogadva1/171ms14252 KiB
25Elfogadva2/24ms4408 KiB
26Elfogadva2/27ms5384 KiB
27Elfogadva2/246ms9464 KiB
28Elfogadva1/146ms9564 KiB
29Elfogadva2/223ms9640 KiB
30Elfogadva1/163ms14576 KiB
31Elfogadva1/148ms14464 KiB
32Elfogadva2/212ms4712 KiB
33Elfogadva2/264ms14464 KiB
34Elfogadva1/165ms14460 KiB
35Elfogadva2/265ms14588 KiB
36Elfogadva2/264ms14704 KiB
37Elfogadva2/264ms14824 KiB
38Elfogadva2/264ms14824 KiB
39Elfogadva1/110ms4768 KiB