답안 #477730

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
477730 2021-10-03T10:31:45 Z Zhora_004 쌀 창고 (IOI11_ricehub) C++17
컴파일 오류
0 ms 0 KB
#include "ricehub.h"
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#include <cstring>
#include <numeric>
#include <functional>
#include <chrono>
#include <cassert>
#include <bitset>
using namespace std;

int besthub(int n, int l, int x[], long long tmp_b)
{
	multiset<int> tmp;
	for (int i = 0; i < n; i++) tmp.insert(x[i]);
	int mx = 0;
	for (int& i : x)
	{
		int ans = 0;
		multiset<int> ms = tmp;
		long long b = tmp_b;
		while (b)
		{
			auto it1 = ms.lower_bound(i);
			int num1 = -1, num2 = -1;
			if (it1 != ms.end()) num1 = *it1;
			if (it1 != ms.begin()) it1--, num2 = *it1;
			if (num1 == -1 && num2 == -1) continue;
			if (num1 == -1)
			{
				if (i - num2 <= b) b -= i - num2, ans++, ms.erase(ms.find(num2));
				else break;
			}
			else if (num2 == -1)
			{
				if (num1 - i <= b) b -= num1 - i, ans++, ms.erase(ms.find(num1));
				else break;
			}
			else
			{
				if (min(num1 - i, i - num2) <= b)
				{
					if (num1 - i <= i - num2) b -= num1 - i, ans++, ms.erase(ms.find(num1));
					else b -= i - num2, ans++, ms.erase(ms.find(num2));
				}
				else break;
			}
		}
		mx = max(mx, ans);
	}
	return mx;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:33:16: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
   33 |  for (int& i : x)
      |                ^
      |                std::begin
In file included 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/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from ricehub.cpp:2:
/usr/include/c++/10/bits/range_access.h:108:37: note: 'std::begin' declared here
  108 |   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&);
      |                                     ^~~~~
ricehub.cpp:33:16: error: 'end' was not declared in this scope; did you mean 'std::end'?
   33 |  for (int& i : x)
      |                ^
      |                std::end
In file included 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/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from ricehub.cpp:2:
/usr/include/c++/10/bits/range_access.h:110:37: note: 'std::end' declared here
  110 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&);
      |                                     ^~~