Untitled

mail@pastecode.io avatar
unknown
c_cpp
7 months ago
664 B
0
Indexable
Never
#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
	int n{}, a{}, maxUsers{}, storage,clonStorage, maxStorage{};

	std::vector<int> memory;
	
	std::cin >> storage >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> a;
		memory.push_back(a);
	}
	std::sort(memory.begin(),memory.end());
	clonStorage = storage;
	for (int i = 0; i < n; i++) {
		if (storage - memory[i] >= 0) {
			maxUsers += 1;
			storage -= memory[i];
		}
		else {
			break;
		}
	}
	for (int i = 0; i < n; i++) {
		if (clonStorage - (memory[i] * maxUsers) >= 0) {
			maxStorage = memory[i];
		}
	}
	std::cout << maxUsers << " " << maxStorage;
}

Leave a Comment