답안 #246062

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
246062 2020-07-08T06:28:07 Z Vladikus004 Unija (COCI17_unija) C++14
100 / 100
407 ms 31096 KB
#include <bits/stdc++.h>
#define inf 2e9
#define int long long
#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);
}

int32_t 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;
}
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 407 ms 16080 KB Output is correct
2 Correct 397 ms 15992 KB Output is correct
3 Correct 383 ms 15940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 896 KB Output is correct
2 Correct 14 ms 1152 KB Output is correct
3 Correct 14 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 1920 KB Output is correct
2 Correct 41 ms 3200 KB Output is correct
3 Correct 43 ms 3320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 127 ms 5112 KB Output is correct
2 Correct 113 ms 9080 KB Output is correct
3 Correct 117 ms 9128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 394 ms 16012 KB Output is correct
2 Correct 388 ms 31080 KB Output is correct
3 Correct 403 ms 31096 KB Output is correct