Submission #54355

# Submission time Handle Problem Language Result Execution time Memory
54355 2018-07-03T08:10:29 Z 강태규(#1471) Sails (IOI07_sails) C++11
100 / 100
120 ms 6124 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

int n;
pii hk[100000];
int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        int h, k;
        scanf("%d%d", &h, &k);
        hk[i] = pii(h, k);
    }
    sort(hk, hk + n);
    int mh = hk[n - 1].first;
    
    multiset<int> mp;
    multiset<int>::iterator it, it2;
    for (int i = 0; i <= n; ++i) mp.insert(mh + 1);
    for (int i = 0; i < n; ++i) {
        int h = mh - hk[i].first + 1;
        int x = h + hk[i].second;
        mp.insert(h);
        it = mp.lower_bound(x);
        it2 = it--;
        int a = *it;
        int b = *it2;
        mp.erase(it);
        mp.erase(it2);
        mp.insert(b - (x - a));
    }
    llong ans = 0;
    it = mp.begin();
    for (int i = 0, pr = 0; it != mp.end(); ++i, pr = *it, ++it) {
        ans += (llong)i * (i - 1) * (*it - pr);
    }
    printf("%lld\n", ans / 2);
    
	return 0;
}

Compilation message

sails.cpp: In function 'int main()':
sails.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
sails.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &h, &k);
         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 412 KB Output is correct
2 Correct 3 ms 552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 552 KB Output is correct
2 Correct 2 ms 552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 552 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 596 KB Output is correct
2 Correct 3 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 876 KB Output is correct
2 Correct 28 ms 2160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 3308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 4716 KB Output is correct
2 Correct 70 ms 4720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 5484 KB Output is correct
2 Correct 83 ms 5612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 120 ms 5996 KB Output is correct
2 Correct 89 ms 6124 KB Output is correct