Submission #817415

# Submission time Handle Problem Language Result Execution time Memory
817415 2023-08-09T12:21:47 Z vjudge1 Feast (NOI19_feast) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

void main_program();

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	main_program();
}

#define int long long

using ii = pair<int, int>;

int n, k;
vector<int> v, pfx;

ii better(ii a, ii b){
	if (a.first != b.first){
		return (a.first > b.first) ? a : b;
	}
	return (a.second < b.second) ? a : b;
}

ii f(int lambda){
	vector<ii> dp_closed(n), dp_open(n);
	dp_closed[0] = {0, 0};
	dp_open[0] = {max(0LL, -pfx[0]), 0};

	for (int i = 1; i < n; i++){
		dp_closed[i] = better(dp_closed[i-1],
			{dp_open[i-1].first + pfx[i] - lambda, dp_open[i-1].second + 1});
		dp_open[i] = better(dp_open[i-1],
			{dp_closed[i-1].first - pfx[i], dp_closed[i-1].second});
	}

	return dp_closed[n-1];
}

void main_program(){
	cin >> n >> k;

	v.resize(n);
	for (int i = 0; i < n; i++) cin >> v[i];
	pfx = v;
	for (int i = 1; i < n; i++) pfx[i] += pfx[i-1];

	int l = 0, r = 3e14;
	auto final = {(int)-1e18, 0LL};
	while (l <= r){
		int mid = (l + r) >> 1;
		auto res = f(mid);
		if (res.second <= k){
			r = mid - 1;
			final = res;
		}
		else l = mid + 1;
	}

	cout << final.first + l * final.second << "\n";
}

Compilation message

feast.cpp: In function 'void main_program()':
feast.cpp:55:12: error: no match for 'operator=' (operand types are 'std::initializer_list<long long int>' and 'std::pair<long long int, long long int>')
   55 |    final = res;
      |            ^~~
In file included from /usr/include/c++/10/bits/range_access.h:36,
                 from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from feast.cpp:1:
/usr/include/c++/10/initializer_list:47:11: note: candidate: 'constexpr std::initializer_list<long long int>& std::initializer_list<long long int>::operator=(const std::initializer_list<long long int>&)'
   47 |     class initializer_list
      |           ^~~~~~~~~~~~~~~~
/usr/include/c++/10/initializer_list:47:11: note:   no known conversion for argument 1 from 'std::pair<long long int, long long int>' to 'const std::initializer_list<long long int>&'
/usr/include/c++/10/initializer_list:47:11: note: candidate: 'constexpr std::initializer_list<long long int>& std::initializer_list<long long int>::operator=(std::initializer_list<long long int>&&)'
/usr/include/c++/10/initializer_list:47:11: note:   no known conversion for argument 1 from 'std::pair<long long int, long long int>' to 'std::initializer_list<long long int>&&'
feast.cpp:60:16: error: 'class std::initializer_list<long long int>' has no member named 'first'
   60 |  cout << final.first + l * final.second << "\n";
      |                ^~~~~
feast.cpp:60:34: error: 'class std::initializer_list<long long int>' has no member named 'second'
   60 |  cout << final.first + l * final.second << "\n";
      |                                  ^~~~~~