Submission #477712

# Submission time Handle Problem Language Result Execution time Memory
477712 2021-10-03T10:09:09 Z Zhora_004 Rice Hub (IOI11_ricehub) C++17
Compilation error
0 ms 0 KB
#define _CRT_SECURE_NO_WARNINGS
#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>
#define itn int
#define sacnf scanf
// printf("%.10f\n", ans);
using ll = long long;
using namespace std;
const ll mod = 1e9 + 7;
const int N = 1e5 + 5;


int main()
{
	/*ios_base::sync_with_stdio(false);
	cin.tie(NULL);*/
	int n, l;
	scanf("%d%d", &n, &l);
	vector<int> x(n);
	multiset<int> tmp;
	for (int i = 0; i < n; i++) scanf("%d", &x[i]), tmp.insert(x[i]);
	int tmp_b;
	scanf("%d", &tmp_b);
	int mx = 0;
	for (int i = 1; i <= l; i++)
	{
		int ans = 0;
		multiset<int> ms = tmp;
		int 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);
	}
	printf("%d", mx);
	return 0;
}



Compilation message

ricehub.cpp: In function 'int main()':
ricehub.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |  scanf("%d%d", &n, &l);
      |  ~~~~~^~~~~~~~~~~~~~~~
ricehub.cpp:43:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |  for (int i = 0; i < n; i++) scanf("%d", &x[i]), tmp.insert(x[i]);
      |                              ~~~~~^~~~~~~~~~~~~
ricehub.cpp:45:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |  scanf("%d", &tmp_b);
      |  ~~~~~^~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccGZAiVK.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccPLboJM.o:ricehub.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccGZAiVK.o: in function `main':
grader.cpp:(.text.startup+0xae): undefined reference to `besthub(int, int, int*, long long)'
collect2: error: ld returned 1 exit status