Submission #121751

# Submission time Handle Problem Language Result Execution time Memory
121751 2019-06-27T04:16:47 Z turbat Sails (IOI07_sails) C++14
0 / 100
24 ms 2672 KB
#include <bits/stdc++.h>
using namespace std;
#define N 100005

int n, mh;
long long  sum, cnt[N], s[N], ans, p, uld, avr;
pair <int, int> mast[N];

void solve (int l){
	if (l > mh) return;
	p = l;
	// cout << l<< endl;
	for (int i = l;i <= mh;i++){
		if((s[i] - s[l - 1]) * (p - l + 1) >= (s[p] - s[l - 1]) * (i - l + 1))
			p = i;
		if ((s[mh] - s[l - 1]) * (p - l + 1) >= (s[p] - s[l - 1]) * (i - l + 2))
			break;
	}
		
	sum = s[p] - s[l - 1];
	avr = sum / (p - l + 1);
	uld = sum % (p - l + 1);
	ans += uld * avr;
	ans += (p - l + 1) * avr * (avr - 1) / 2;
	solve (p + 1);
}

int main (){
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	cin >> n;
	for (int i = 0;i < n;i++){
		cin >> mast[i].first>> mast[i].second;
		mh = max(mh, mast[i].first);
		cnt[mast[i].first]++;
		cnt[mast[i].first - mast[i].second]--;
	}
	for (int i = mh;i > 0;i--) cnt[i] += cnt[i + 1];
	for (int i = 1;i <= mh;i++) { 
		s[i] = s[i - 1] + cnt[i];
		// cout << s[i] << endl;
	}
	solve (1);
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 1152 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 1536 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 2432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 2560 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 2672 KB Output isn't correct
2 Halted 0 ms 0 KB -