Submission #440056

# Submission time Handle Problem Language Result Execution time Memory
440056 2021-07-01T14:26:55 Z gromperen Unija (COCI17_unija) C++14
60 / 100
372 ms 31464 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long


int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);

	int n; cin >> n;
	vector<pair<int,int>> v(n), a;
	ll ans = 0;
	for (int i = 0; i < n; ++i) cin >> v[i].first >> v[i].second;
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	int prev = 0, prevy = 0;
	for (int i = 0; i < n; ++i) {
		if (v[i].first == prev ) continue;
		if (v[i].second <= prevy) continue;
		a.push_back(v[i]);
		prev = v[i].first;
		prevy = v[i].second;
	}
	for (int i = 0; i < a.size(); ++i) {
		ans += a[i].second * (a[i].first - ((i < a.size() - 1) ? a[i+1].first : 0));
	}
	cout << ans << "\n";


	return 0;
}

Compilation message

unija.cpp: In function 'int main()':
unija.cpp:25:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |  for (int i = 0; i < a.size(); ++i) {
      |                  ~~^~~~~~~~~~
unija.cpp:26:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |   ans += a[i].second * (a[i].first - ((i < a.size() - 1) ? a[i+1].first : 0));
      |                                        ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 244 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 452 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 358 ms 31464 KB Output is correct
2 Correct 372 ms 31408 KB Output is correct
3 Correct 371 ms 31436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 2380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 95 ms 6616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 365 ms 23124 KB Output isn't correct
2 Halted 0 ms 0 KB -