Submission #519799

# Submission time Handle Problem Language Result Execution time Memory
519799 2022-01-27T10:48:42 Z sofapuden Sails (IOI07_sails) C++14
100 / 100
76 ms 7484 KB
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int n; cin >> n;
  vector<pair<int,int>> v(n);
  for(auto &x : v)cin >> x.first >> x.second;
  set<pair<int,int>> S;
  S.insert({1,1});S.insert({1,2});
  int cn = 3;
  sort(v.begin(),v.end());
  for(int i = 0; i < n; ++i){
    int mx = (*S.rbegin()).first, am = min(v[i].first+1,mx+v[i].second)-mx;
    if(v[i].second == am){
      S.erase(prev(S.end()));
      S.insert({mx+am,cn++});
      continue;
    }
    S.insert({mx+am,cn++});
    auto it = S.lower_bound({v[i].first-v[i].second+1,0});
    if(it == S.begin())it = next(it);
    auto it2 = prev(it);
    S.insert({(*it2).first+v[i].second-(v[i].first-(*it).first+1),cn++});
    S.erase(it);
    S.erase(it2);
    S.insert({1,cn++}); // Just to be sure
  }
  vector<int> v2;
  for(auto x : S)v2.push_back(x.first);
  reverse(v2.begin(),v2.end());
  ll ans = 0;
  for(int i = 0; i < v2.size(); ++i){
    ans += 1ll * i * (v2[i]-1);
  }
  cout << ans << '\n';
}

Compilation message

sails.cpp: In function 'int main()':
sails.cpp:35:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   for(int i = 0; i < v2.size(); ++i){
      |                  ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 292 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 836 KB Output is correct
2 Correct 18 ms 2460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 2412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 3900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 5800 KB Output is correct
2 Correct 48 ms 5868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 6824 KB Output is correct
2 Correct 35 ms 3264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 7468 KB Output is correct
2 Correct 57 ms 7484 KB Output is correct