Submission #486655

# Submission time Handle Problem Language Result Execution time Memory
486655 2021-11-12T09:25:00 Z PoPularPlusPlus Snowball (JOI21_ho_t2) C++17
0 / 100
1 ms 460 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long 
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007; 
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
bool remender(ll a , ll b){return a%b;}

void solve(){
	int n;
	cin >> n;
	int q;
	cin >> q;
	ll arr[n];
	for(int i = 0; i < n; i++){
		cin >> arr[i];
	}
	vector<ll> v;
	ll mx[q] , mn[q] , cur;
	mx[0] = mn[0] = 0;
	for(int i = 0; i < q; i++){
		ll x;
		cin >> x;
		cur += x;
		if(i != 0){
			mn[i] = min(mn[i-1] , cur);
			mx[i] = max(mx[i-1] , cur);
		}
		else {
			mx[i] = max(mx[i] , cur);
			mn[i] = min(mn[i] , cur);
		}
		v.pb(mx[i] - mn[i]);
	}
	ll l[n] , r[n];
	l[0] = abs(mn[q-1]) , r[n-1] = mx[q-1];
	for(int i = 0; i < n-1; i++){
		int p = upper_bound(all(v) , arr[i + 1] - arr[i]) - v.begin();
		if(p == (int)v.size()){
			p--;
			r[i] = mx[i];
			l[i + 1] = abs(mn[i]);
		}
		else if(p == 0){
			r[i] = l[i + 1] = 0;
			if(mx[p] > 0){
				r[i] = arr[i + 1] - arr[i];
			}
			else {
				l[i + 1] = arr[i + 1] - arr[i];
			}
		}
		else {
			r[i] = mx[p-1];
			l[i + 1] = abs(mn[p-1]);
			ll rem = arr[i + 1] - arr[i];
			rem -= mx[p-1] + abs(mn[p-1]);
			if(mx[p] > mx[p-1]){
				r[i] += rem;
			}
			else l[i + 1] += rem;
		}
	}
	for(int i = 0; i < n; i++){
		//cout << l[i] << ' ' << r[i] << ' ';
		cout << l[i] + r[i] << '\n';
	}
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
	//int t;cin >> t;while(t--)
	solve();
	return 0;
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:33:7: warning: 'cur' may be used uninitialized in this function [-Wmaybe-uninitialized]
   33 |   cur += x;
      |   ~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 1 ms 460 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 1 ms 460 KB Output isn't correct
5 Halted 0 ms 0 KB -