Submission #114183

# Submission time Handle Problem Language Result Execution time Memory
114183 2019-05-31T08:22:34 Z zubec Sails (IOI07_sails) C++14
40 / 100
1000 ms 1660 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

vector <pair<int, int> > vec;

int n;

set<pair<int, int> > q;

void add(int x, int kol){
    auto it = q.lower_bound({x, 0});
    if (it != q.end() && it->first == x){
        int kolpr = it->second;
        q.erase(it);
        q.insert({x, kolpr+kol});
    } else {
        q.insert({x, kol});
    }
}

void otn(int x, int kol){
    auto it = q.lower_bound({x, 0});
    int kolpr = it->second;
    kolpr -= kol;
    q.erase(it);
    if (kolpr != 0)
        q.insert({x, kolpr});
}

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

    cin >> n;
    for (int i = 1; i <= n; i++){
        int h, k;
        cin >> h >> k;
        vec.push_back({h, k});
    }
    sort(vec.begin(), vec.end());
    int mxh = 0;
    for (int i = 0; i < vec.size(); i++){
        if (mxh < vec[i].first){
            add(0, vec[i].first-mxh);
            mxh = vec[i].first;
        }
        vector <pair<int, int> > vec2;
        while(vec[i].second > 0){
            auto it = q.begin();
            int mn = min(it->second, vec[i].second);
            vec[i].second -= mn;
            vec2.push_back({it->first, mn});
            otn(it->first, mn);
        }
        for (int j = 0; j < vec2.size(); j++){
            add(vec2[j].first+1, vec2[j].second);
        }
    }
    ll ans = 0;
    while(!q.empty()){
        pair<int, int> pr = *q.begin();
        q.erase(q.begin());
        ans += pr.second*1ll*pr.first*(pr.first-1)/2;
    }
    cout << ans;

}

Compilation message

sails.cpp: In function 'int main()':
sails.cpp:43:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < vec.size(); i++){
                     ~~^~~~~~~~~~~~
sails.cpp:56:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < vec2.size(); j++){
                         ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 504 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1061 ms 752 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1066 ms 1004 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1077 ms 1152 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1070 ms 1652 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1064 ms 1660 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1074 ms 1660 KB Time limit exceeded
2 Halted 0 ms 0 KB -