Submission #915875

# Submission time Handle Problem Language Result Execution time Memory
915875 2024-01-24T20:17:00 Z Matjaz Sails (IOI07_sails) C++14
90 / 100
1000 ms 3516 KB
//
//  IOI2007Sails.cpp
//  
//
//  Created by Matjaz Leonardis on 04/12/2023.
//

#include <stdio.h>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

int INF = 100001;

int main(){
    
    int N;
    scanf("%d",&N);
    vector<int> H(N),K(N);
    for (int i=0;i<N;i++) scanf("%d %d",&H[i], &K[i]);
    
    vector<pair<int,int> > p(N);
    for (int i=0;i<N;i++) p[i] = make_pair(H[i],K[i]);
    sort(p.begin(), p.end());
    
    vector<int> S(100005);
    
    int prev = 0;
    
    for (int i=0;i<N;i++){
        S[0] +=  p[i].first - prev;
        int k = p[i].second;
        int delayed_update = 0;
        for (int j=0;;j++){
            if (k == 0) break;
            if (S[j] >= k){
                S[j] -= k;
                S[j + 1] += k;
                k = 0;
                S[j] += delayed_update;
            } else {
                k -= S[j];
                int tmp = S[j];
                S[j] = delayed_update;
                delayed_update = tmp;
            }
        }
        prev = p[i].first;
        /*cout << p[i].first<< " " << p[i].second << endl;
        for (int j=0;j<5;j++) cout << S[j] << endl;
        cout << endl;*/
    }
    
    long long total=0;
    
    for (int i=0;i<S.size();i++){
        total += (((long long)i * (i - 1)) / 2) * S[i];
    }
    
    printf("%lld\n", total);
    
    
    return 0;
}

Compilation message

sails.cpp: In function 'int main()':
sails.cpp:58:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for (int i=0;i<S.size();i++){
      |                  ~^~~~~~~~~
sails.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     scanf("%d",&N);
      |     ~~~~~^~~~~~~~~
sails.cpp:22:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     for (int i=0;i<N;i++) scanf("%d %d",&H[i], &K[i]);
      |                           ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 760 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 860 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 856 KB Output is correct
2 Correct 207 ms 1592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 280 ms 1624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 225 ms 2136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 846 ms 2896 KB Output is correct
2 Correct 449 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1010 ms 3152 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 775 ms 3516 KB Output is correct
2 Correct 171 ms 3376 KB Output is correct