Submission #777574

# Submission time Handle Problem Language Result Execution time Memory
777574 2023-07-09T10:53:33 Z a_aguilo Sails (IOI07_sails) C++14
40 / 100
1000 ms 2524 KB
#include<bits/stdc++.h>

using namespace std;

int N;
long long ans;
const int maxN = 100002;
const int maxH = 100002;
pair<int, int> masts[maxN];
int res[maxH];

void merge(int a1[], int l1, int a2[], int l2){
	int pos1 = 0;
	int pos2 = 0;
	for(int i = 0; i < (l1 + l2); ++i){
		if(pos1 <l1 && pos2 < l2){
			if(a1[pos1] > a2[pos2]){
				res[i] = (a1[pos1]);
				pos1++;
			}else{
				res[i] = a2[pos2];
				pos2++;
			}
		}else if(pos1 < l1){
			res[i] = a1[pos1];
			pos1++;
		}else{
			res[i] = a2[pos2];
			pos2++;
		}
		//cout << res[i] << " ";
	}
	//cout << endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ans = 0;
	cin >> N;
	for(int i = 0; i < N; ++i) cin >> masts[i].first >> masts[i].second;
	int occupation[maxH];
	int lim = 0;
	sort(masts, masts+N);
	for(int i = 0; i < N; ++i){
		int h = masts[i].first;
		int k = masts[i].second;
		int prov[k];
		while(lim < h){
			occupation[lim] = 0;
			lim++;
		}
		for(int j = 0; j < k; ++j){
			prov[k - j - 1] = occupation[lim-1] + 1;
			ans += occupation[lim-1];
			lim--;
		}
		merge(occupation, lim, prov, k);
		swap(occupation, res);
		lim += k;
	}
	cout << ans << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1092 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1048 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1108 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 980 KB Output is correct
2 Correct 36 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 1108 KB Output is correct
2 Correct 131 ms 1124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 660 ms 1304 KB Output is correct
2 Execution timed out 1044 ms 1620 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1064 ms 1820 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1061 ms 2000 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1055 ms 2524 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1067 ms 2352 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1049 ms 2440 KB Time limit exceeded
2 Halted 0 ms 0 KB -