248882026-02-16 14:26:34ubormaciLádapakolás raktárban (50)cpp17Elfogadva 50/5034ms2500 KiB
#include <iostream>
#include <algorithm> // for sort, mainly
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <array>
#include <string>
#include <cstdio>
#include <iterator>
#include <unordered_set>
#include <cstdint> // for int64_t, int32_t, etc
#include <queue>
#include <stack>
#include <deque>
#include <numeric> // gcd, lcm
#include <fstream>
#include <bitset> // for bitset
#include <iomanip>
#include <cassert> // for set with custom ordering
#include <type_traits> // for set with custom ordering
#include <utility> // for swap, forward, etc
using namespace std;

#pragma GCC optimize("O2")
// #pragma GCC optimize("O1","O2","O3","Ofast","unroll-loops")
// #pragma GCC target("sse","sse2","sse3","sse4.1","sse4.2","avx","avx2","fma")

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#ifdef LOCAL
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

/*

notes:

int64_t
stoi(string s) -> string to int
to_string() -> int (or else) to string

vector declaration:
vector<ll> v(n, 0)
vector<vector<ll>> v(n, vector<ll>(n, 0));

{if statement} ? {truth value} : {false value}

#ifdef LOCAL
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif

std::lcm(ll a, ll b), std::gcd(int a, int b)

cout << fixed << setprecision(n);

set with custom ordering
set<ll, decltype(&cmp)> qu(cmp);

*/

/*

. . . I just realized that my current solution
is incorrect, due to the height limit
(if it didn't exist, it would work)
. . . maybe
either way, it's a greedy held together by hopes and dreams

*/

typedef int32_t ll;

void solve() {

	ll n, lim;
	cin >> n >> lim;

	vector<ll> v(n, 0);
	for(ll i = 0; i < n; i++) {
		cin >> v[i];
	}

	ll towers = 0;

	for(ll i = 0; i < n; i++) {

		// egy two pointers

		//cerr << "\nstarting from " << i;

		ll sum = 0;

		// eloszor csokken, aztan no

		set<ll> curr;
		bool dec = true;

		for(ll j = i; j < n; j++) {

			//cerr << "\nj=" << j << "; v[j]=" << v[j];

			if(sum + v[j] > lim || curr.count(v[j])) {
				//cerr << "\nsum becomes too much, or repeat";
				towers++;
				i = j-1;
				break;
			}

			sum += v[j];
			curr.insert(v[j]);
			
			if(j > i) {
				bool prev = (v[j] - v[j-1] > 0);
				//cerr << "\ndec=" << dec << "; prev=" << prev;
				if(prev != dec) {
					if(dec == true) {
						dec = false;
					}else{
						// uh-oh, another switch
						// end of tower
						towers++;
						i = j-1;
						break;
					}
				}
			}

			if(j == n-1) {
				towers++;
				i = n+1;
				break;
			}
		}
	}

	//cerr << "\ntowers=" << towers;

	cout << n - towers;

}

int main()
{
	std::ios_base::sync_with_stdio(false);
	//cin.tie(nullptr);
	//cout.tie(nullptr);

	solve();

	return 0;
}

/*

erre a feladatra nem jottem ra magamtol

UVince submission-je nagyon szep es ertheto volt, sokat segitett

https://njudge.hu/submission/15591

*/
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/01ms316 KiB
2Elfogadva0/03ms316 KiB
3Elfogadva2/21ms316 KiB
4Elfogadva2/21ms316 KiB
5Elfogadva2/21ms316 KiB
6Elfogadva2/21ms316 KiB
7Elfogadva2/21ms316 KiB
8Elfogadva2/21ms316 KiB
9Elfogadva3/31ms316 KiB
10Elfogadva2/21ms316 KiB
11Elfogadva2/21ms316 KiB
12Elfogadva2/21ms500 KiB
13Elfogadva3/32ms416 KiB
14Elfogadva3/32ms316 KiB
15Elfogadva3/33ms332 KiB
16Elfogadva2/218ms1064 KiB
17Elfogadva3/320ms820 KiB
18Elfogadva3/323ms820 KiB
19Elfogadva3/319ms764 KiB
20Elfogadva3/334ms2328 KiB
21Elfogadva3/328ms2356 KiB
22Elfogadva3/329ms2500 KiB