Submission #988065

# Submission time Handle Problem Language Result Execution time Memory
988065 2024-05-24T02:51:09 Z vjudge1 Feast (NOI19_feast) C++17
100 / 100
236 ms 25776 KB
//Code by Patcas Csaba aka SleepyOverlord
#include <vector>
#include <array>
#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 PLL pair <LL, LL>
#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 VVLL vector < VLL >
#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 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 LL INF = 1e18;

int n, k;
VI a;
vector < vector <PLL> > dp;

PLL solve(LL lambda)
{
	dp[0][0] = {0, 0};
	FOR(i, 1, n)
	{
		dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
		dp[i][1] = max(
			MP(dp[i - 1][0].X + a[i] - lambda, dp[i - 1][0].Y + 1),
			MP(dp[i - 1][1].X + a[i], dp[i - 1][1].Y));
	}
	return max(dp[n][0], dp[n][1]);
}

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

	cin >> n >> k;
	dp.RS(n + 1, vector <PLL> (2, {-INF, 0}));
	a.RS(n + 1);
	FOR(i, 1, n) cin >> a[i];

	LL l = 0, r = 3e14;
	while (r - l > 1)
	{
		LL m = (l + r) / 2;
		auto aux = solve(m);
		if (aux.Y > k) l = m;
		else r = m;
	}
	auto aux = solve(r);
	pr(aux.X + aux.Y * r);

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 207 ms 22096 KB Output is correct
2 Correct 189 ms 22456 KB Output is correct
3 Correct 209 ms 22620 KB Output is correct
4 Correct 210 ms 22540 KB Output is correct
5 Correct 190 ms 22360 KB Output is correct
6 Correct 205 ms 22068 KB Output is correct
7 Correct 198 ms 22044 KB Output is correct
8 Correct 194 ms 22360 KB Output is correct
9 Correct 186 ms 22108 KB Output is correct
10 Correct 205 ms 22108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 150 ms 22108 KB Output is correct
2 Correct 158 ms 22868 KB Output is correct
3 Correct 165 ms 22160 KB Output is correct
4 Correct 141 ms 22364 KB Output is correct
5 Correct 203 ms 21852 KB Output is correct
6 Correct 166 ms 22136 KB Output is correct
7 Correct 158 ms 22620 KB Output is correct
8 Correct 215 ms 22364 KB Output is correct
9 Correct 208 ms 21848 KB Output is correct
10 Correct 160 ms 22364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 206 ms 22360 KB Output is correct
2 Correct 229 ms 22192 KB Output is correct
3 Correct 201 ms 22364 KB Output is correct
4 Correct 202 ms 22160 KB Output is correct
5 Correct 218 ms 22412 KB Output is correct
6 Correct 204 ms 22360 KB Output is correct
7 Correct 228 ms 22628 KB Output is correct
8 Correct 218 ms 25424 KB Output is correct
9 Correct 222 ms 25740 KB Output is correct
10 Correct 212 ms 25556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 544 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 544 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 544 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 344 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 2 ms 344 KB Output is correct
28 Correct 2 ms 344 KB Output is correct
29 Correct 2 ms 348 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 207 ms 22096 KB Output is correct
2 Correct 189 ms 22456 KB Output is correct
3 Correct 209 ms 22620 KB Output is correct
4 Correct 210 ms 22540 KB Output is correct
5 Correct 190 ms 22360 KB Output is correct
6 Correct 205 ms 22068 KB Output is correct
7 Correct 198 ms 22044 KB Output is correct
8 Correct 194 ms 22360 KB Output is correct
9 Correct 186 ms 22108 KB Output is correct
10 Correct 205 ms 22108 KB Output is correct
11 Correct 150 ms 22108 KB Output is correct
12 Correct 158 ms 22868 KB Output is correct
13 Correct 165 ms 22160 KB Output is correct
14 Correct 141 ms 22364 KB Output is correct
15 Correct 203 ms 21852 KB Output is correct
16 Correct 166 ms 22136 KB Output is correct
17 Correct 158 ms 22620 KB Output is correct
18 Correct 215 ms 22364 KB Output is correct
19 Correct 208 ms 21848 KB Output is correct
20 Correct 160 ms 22364 KB Output is correct
21 Correct 206 ms 22360 KB Output is correct
22 Correct 229 ms 22192 KB Output is correct
23 Correct 201 ms 22364 KB Output is correct
24 Correct 202 ms 22160 KB Output is correct
25 Correct 218 ms 22412 KB Output is correct
26 Correct 204 ms 22360 KB Output is correct
27 Correct 228 ms 22628 KB Output is correct
28 Correct 218 ms 25424 KB Output is correct
29 Correct 222 ms 25740 KB Output is correct
30 Correct 212 ms 25556 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 544 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 1 ms 344 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 2 ms 348 KB Output is correct
52 Correct 2 ms 348 KB Output is correct
53 Correct 2 ms 348 KB Output is correct
54 Correct 2 ms 344 KB Output is correct
55 Correct 2 ms 348 KB Output is correct
56 Correct 2 ms 348 KB Output is correct
57 Correct 2 ms 344 KB Output is correct
58 Correct 2 ms 344 KB Output is correct
59 Correct 2 ms 348 KB Output is correct
60 Correct 2 ms 348 KB Output is correct
61 Correct 231 ms 25144 KB Output is correct
62 Correct 235 ms 25776 KB Output is correct
63 Correct 231 ms 25080 KB Output is correct
64 Correct 235 ms 25424 KB Output is correct
65 Correct 231 ms 25460 KB Output is correct
66 Correct 226 ms 25432 KB Output is correct
67 Correct 233 ms 24944 KB Output is correct
68 Correct 236 ms 25600 KB Output is correct
69 Correct 211 ms 24912 KB Output is correct
70 Correct 213 ms 24980 KB Output is correct