Submission #981173

# Submission time Handle Problem Language Result Execution time Memory
981173 2024-05-13T01:11:23 Z beaboss Feast (NOI19_feast) C++14
Compilation error
0 ms 0 KB
// Source: https://oj.uz/problem/view/NOI19_feast
// 

#include "bits/stdc++.h"

using namespace std;
#define FOR(i, a, b) for (ll i = a; i < b; i++)
typedef pair<ll, ll> pii;
typedef long long ll;
#define s second
#define f first

const ll N = 1e5 + 10;
ll a[N];
pii dp[N][2];
ll n, k;

pii solve(ll l) {
	dp[0][0] = {0, 0};
	dp[0][1] = {a[0] - l, 1};

	FOR(i, 1, n) {
		dp[i][0] = max(dp[i-1][0], dp[i-1][1]);
		dp[i][1] = max(make_pair(dp[i-1][0].f + a[i] - l, dp[i-1][0].s + 1), make_pair(dp[i-1][1].f + a[i], dp[i-1][1].s));
	}
	return max(dp[n-1][1], dp[n-1][0]);

}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	cin >> n >> k;

	FOR(i, 0 ,n) cin >> a[i];

	ll lo = 0;
	ll hi = 1e18;

	while (lo < hi) {
		ll m = (lo + hi + 1)/2;
		pii res = solve(m);
		if (res.s >= k) lo = m;
		else hi = m -1;
	}
	// cout << lo << solve(lo).f << endl;
	cout << solve(lo).f + k * lo << endl;

}












Compilation message

feast.cpp:8:14: error: 'll' was not declared in this scope
    8 | typedef pair<ll, ll> pii;
      |              ^~
feast.cpp:8:18: error: 'll' was not declared in this scope
    8 | typedef pair<ll, ll> pii;
      |                  ^~
feast.cpp:8:20: error: template argument 1 is invalid
    8 | typedef pair<ll, ll> pii;
      |                    ^
feast.cpp:8:20: error: template argument 2 is invalid
feast.cpp: In function 'pii solve(ll)':
feast.cpp:19:18: error: cannot convert '<brace-enclosed initializer list>' to 'pii' {aka 'int'} in assignment
   19 |  dp[0][0] = {0, 0};
      |                  ^
feast.cpp:20:25: error: cannot convert '<brace-enclosed initializer list>' to 'pii' {aka 'int'} in assignment
   20 |  dp[0][1] = {a[0] - l, 1};
      |                         ^
feast.cpp:11:11: error: request for member 'first' in 'dp[(i - 1)][0]', which is of non-class type 'pii' {aka 'int'}
   11 | #define f first
      |           ^~~~~
feast.cpp:24:39: note: in expansion of macro 'f'
   24 |   dp[i][1] = max(make_pair(dp[i-1][0].f + a[i] - l, dp[i-1][0].s + 1), make_pair(dp[i-1][1].f + a[i], dp[i-1][1].s));
      |                                       ^
feast.cpp:10:11: error: request for member 'second' in 'dp[(i - 1)][0]', which is of non-class type 'pii' {aka 'int'}
   10 | #define s second
      |           ^~~~~~
feast.cpp:24:64: note: in expansion of macro 's'
   24 |   dp[i][1] = max(make_pair(dp[i-1][0].f + a[i] - l, dp[i-1][0].s + 1), make_pair(dp[i-1][1].f + a[i], dp[i-1][1].s));
      |                                                                ^
feast.cpp:11:11: error: request for member 'first' in 'dp[(i - 1)][1]', which is of non-class type 'pii' {aka 'int'}
   11 | #define f first
      |           ^~~~~
feast.cpp:24:93: note: in expansion of macro 'f'
   24 |   dp[i][1] = max(make_pair(dp[i-1][0].f + a[i] - l, dp[i-1][0].s + 1), make_pair(dp[i-1][1].f + a[i], dp[i-1][1].s));
      |                                                                                             ^
feast.cpp:10:11: error: request for member 'second' in 'dp[(i - 1)][1]', which is of non-class type 'pii' {aka 'int'}
   10 | #define s second
      |           ^~~~~~
feast.cpp:24:114: note: in expansion of macro 's'
   24 |   dp[i][1] = max(make_pair(dp[i-1][0].f + a[i] - l, dp[i-1][0].s + 1), make_pair(dp[i-1][1].f + a[i], dp[i-1][1].s));
      |                                                                                                                  ^
feast.cpp: In function 'int main()':
feast.cpp:10:11: error: request for member 'second' in 'res', which is of non-class type 'pii' {aka 'int'}
   10 | #define s second
      |           ^~~~~~
feast.cpp:44:11: note: in expansion of macro 's'
   44 |   if (res.s >= k) lo = m;
      |           ^
feast.cpp:11:11: error: request for member 'first' in 'solve(lo)', which is of non-class type 'pii' {aka 'int'}
   11 | #define f first
      |           ^~~~~
feast.cpp:48:20: note: in expansion of macro 'f'
   48 |  cout << solve(lo).f + k * lo << endl;
      |                    ^