답안 #385783

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
385783 2021-04-05T00:24:49 Z LucaDantas Safety (NOI18_safety) C++17
18 / 100
253 ms 20468 KB
#include <cstdio>
#include <set>

int difl, difr; // lazy

std::multiset<int> l, r;

long long ans = 0;

void sl(int i) {
	int passar = *r.begin() + difr;
	r.erase(r.begin());
	ans += (passar - (*l.rbegin() + difl)) * (-i + (int)l.size());
	l.insert(passar - difl);
}

void sr(int i) {
	int passar = *l.rbegin() + difl;
	l.erase(--l.end());
	ans -= (passar - (*l.rbegin() + difl)) * (-i + (int)l.size());
	r.insert(passar - difr);
}

int abs(int a) { return a < 0 ? -a : a; }

int main() {
	int n, k; scanf("%d %d", &n, &k);
	int center = 0;
	for(int i = 1; i <= n; i++) {
		int a; scanf("%d", &a);
		if(l.size()) ans += abs(a - *l.rbegin() - difl);
		if(!l.size() || a <= *l.rbegin() + difl) l.insert(a - difl), l.insert(a - difl);
		else r.insert(a - difr), r.insert(a - difr);
		while((int)l.size() > i) sr(i);
		while((int)r.size() > i) sl(i);
		difr += k;
		difl -= k;
	}
	printf("%lld\n", ans);
}

Compilation message

safety.cpp: In function 'int main()':
safety.cpp:28:6: warning: unused variable 'center' [-Wunused-variable]
   28 |  int center = 0;
      |      ^~~~~~
safety.cpp:27:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   27 |  int n, k; scanf("%d %d", &n, &k);
      |            ~~~~~^~~~~~~~~~~~~~~~~
safety.cpp:30:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |   int a; scanf("%d", &a);
      |          ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 165 ms 13932 KB Output is correct
2 Correct 249 ms 19692 KB Output is correct
3 Correct 253 ms 20468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Halted 0 ms 0 KB -