Submission #246061

# Submission time Handle Problem Language Result Execution time Memory
246061 2020-07-08T06:27:43 Z Vladikus004 Unija (COCI17_unija) C++14
60 / 100
426 ms 23288 KB
#include <bits/stdc++.h>
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

const int N = 1000010;
int n;
pii a[N];

bool cmp(pii a, pii b){
    return a.first > b.first || (a.first == b.first && a.second > b.second);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif // LOCAL
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i].first >> a[i].second;
    sort(a, a + n, cmp);
    ll ans = a[0].first * a[0].second;
    int mx = a[0].second;
    for (int i = 1; i < n; i++){
        if (a[i].first == a[i - 1].first) continue;
        if (a[i].second <= mx) continue;
        ans += a[i].first * (a[i].second - mx);
        mx = a[i].second;
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 419 ms 23272 KB Output is correct
2 Correct 426 ms 23288 KB Output is correct
3 Correct 418 ms 23160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 2424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 130 ms 6836 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 418 ms 23288 KB Output isn't correct
2 Halted 0 ms 0 KB -