답안 #200380

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
200380 2020-02-06T13:50:38 Z wilwxk Safety (NOI18_safety) C++14
0 / 100
59 ms 3592 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int n, x;
priority_queue<ll> l;
priority_queue<ll, vector<ll>, greater<ll> > r;
ll llz, rlz;
ll ans;

int main() {
	scanf("%d %d", &n, &x);
	for(int i = 1; i <= n; i++) {
		ll val; scanf("%lld", &val);

		if(i == 1) {
			l.push(val);
			r.push(val);
			continue;
		}

		llz -= x;
		rlz += x;

		if(val <= l.top()+llz) {
			l.push(val-llz);
			l.push(val-llz);
			r.push(l.top()+llz-rlz);
			l.pop();
		}
		else {
			r.push(val-rlz);
			r.push(val-rlz);
			l.push(r.top()+rlz-llz);
			r.pop();
		}
		ans += r.top()+rlz-l.top()-llz;
		// printf("%d >> %d %d >> %d %d >> %lld\n", i, l.top(), r.top(), llz, rlz, ans);
	}

	printf("%lld\n", ans);
}

Compilation message

safety.cpp: In function 'int main()':
safety.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &x);
  ~~~~~^~~~~~~~~~~~~~~~~
safety.cpp:14:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   ll val; scanf("%lld", &val);
           ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 248 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Incorrect 5 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 59 ms 3592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 248 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Incorrect 5 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 248 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Incorrect 5 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 248 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Incorrect 5 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 248 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Incorrect 5 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 248 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Incorrect 5 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -