Submission #556975

# Submission time Handle Problem Language Result Execution time Memory
556975 2022-05-04T13:33:12 Z 1ne Safety (NOI18_safety) C++14
0 / 100
122 ms 14916 KB
#include<bits/stdc++.h>
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n,k;cin>>n>>k;
	vector<long long>arr(n);
	for (int i = 0;i<n;++i)cin>>arr[i];
	multiset<long long,greater<long long>>maxxy;
	multiset<long long>minny;
	long long ans = 0,ans2 = 0;
	for (int i = 0;i<n;++i){
		if (!maxxy.empty()){
			auto x = *maxxy.begin();
			auto y = *minny.begin();
			if (abs(y - arr[i])>k){
				ans+=abs(y - arr[i]) - k;
				minny.erase(minny.begin());
				minny.insert(min(y + k,arr[i]));
				
			}	
		}
		maxxy.insert(arr[i]);
		minny.insert(arr[i]);
	}
	cout<<ans<<'\n';
	return 0;
}

Compilation message

safety.cpp: In function 'int main()':
safety.cpp:15:9: warning: unused variable 'x' [-Wunused-variable]
   15 |    auto x = *maxxy.begin();
      |         ^
safety.cpp:12:20: warning: unused variable 'ans2' [-Wunused-variable]
   12 |  long long ans = 0,ans2 = 0;
      |                    ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 122 ms 14916 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -