Submission #35188

#TimeUsernameProblemLanguageResultExecution timeMemory
35188ulnaMoney (IZhO17_money)C++11
45 / 100
1500 ms52784 KiB
#include <bits/stdc++.h>
using namespace std;

// why am I so weak

int n;
int a[1000055];

inline void read(int &x) {
	x = 0;
	char ch = 0;

	while (ch < '0' || ch > '9') ch = getchar();

	while (ch >= '0' && ch <= '9') {
		x = x * 10 + (ch - '0');
		ch = getchar();
	}
}
int main() {
	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		read(a[i]);
	}

	set<int> s;

	s.insert(0), s.insert((int)1e7);

	int lb = 0, ub = (int)1e7;
	int res = 1;

	for (int i = 0; i < n; i++) {
		if (lb <= a[i] && a[i] <= ub) {
			s.insert(a[i]);
			lb = a[i];
			continue;
		}

		lb = a[i];
		ub = *s.upper_bound(a[i]);

		res++;
		s.insert(a[i]);
	}

	printf("%d\n", res);

	return 0;
}

Compilation message (stderr)

money.cpp: In function 'int main()':
money.cpp:21:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...