Submission #915946

# Submission time Handle Problem Language Result Execution time Memory
915946 2024-01-25T01:19:43 Z Matjaz Potatoes and fertilizers (LMIO19_bulves) C++14
24 / 100
257 ms 14988 KB

#include<vector>
#include<iostream>
#include <stdlib.h> 
#include <algorithm>
#include <stack>
#include <queue>

using namespace std;

int N;

int main(){
	cin >> N;
	vector<int> a(N), b(N);
    queue<int> QA;
    queue<int> QB;
    for (int i=0;i<N;i++){
        cin >> a[i] >> b[i];
        QA.push(a[i]);
        QB.push(b[i]);
    }
    
    long long cost = 0;
    long long overflow = 0;
    long long overflow_location = 0;
    
    while (!QA.empty() || !QB.empty()){
        if (overflow == 0 && QA.empty()) break;
        if (overflow == 0){
            overflow = QA.front();
            overflow_location = N - QA.size();
            QA.pop();
            continue;
        }
        if (overflow > 0){
            long long current_location = N - QB.size();
            long long fixed = min(overflow, (long long)QB.front());
            overflow -= QB.front();
            QB.pop();
            cost += abs(current_location - overflow_location) * fixed;
            if (overflow < 0) overflow_location = current_location;
        } else {
            long long current_location = N - QA.size();
            long long fixed = min(-overflow, (long long) QA.front());
            overflow += QA.front();
            QA.pop();
            cost += abs(current_location - overflow_location) * fixed;
            if (overflow > 0) overflow_location = current_location;
            
        }
    }
    
    

    cout << cost << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 20 ms 1424 KB Output is correct
5 Correct 34 ms 2564 KB Output is correct
6 Correct 127 ms 7764 KB Output is correct
7 Correct 257 ms 14988 KB Output is correct
8 Correct 204 ms 13140 KB Output is correct
9 Correct 182 ms 12628 KB Output is correct
10 Correct 118 ms 10328 KB Output is correct
11 Correct 118 ms 10324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 20 ms 1424 KB Output is correct
5 Correct 34 ms 2564 KB Output is correct
6 Correct 127 ms 7764 KB Output is correct
7 Correct 257 ms 14988 KB Output is correct
8 Correct 204 ms 13140 KB Output is correct
9 Correct 182 ms 12628 KB Output is correct
10 Correct 118 ms 10328 KB Output is correct
11 Correct 118 ms 10324 KB Output is correct
12 Incorrect 63 ms 3924 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Runtime error 1 ms 348 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Runtime error 1 ms 348 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Runtime error 1 ms 348 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -