답안 #334322

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
334322 2020-12-09T02:54:02 Z limabeans Potatoes and fertilizers (LMIO19_bulves) C++17
24 / 100
103 ms 11244 KB
#include <bits/stdc++.h>
using namespace std;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;


const int maxn = 1e6 + 5;


int n;
ll a[maxn];
ll b[maxn];

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

    cin>>n;
    ll A = 0;
    ll B = 0;
    for (int i=0; i<n; i++) {
	cin>>a[i]>>b[i];
	A += a[i];
	B += b[i];
    }

    assert(A==B);

    ll res = 0;
    int ptr = 0;
    for (int i=0; i<n; i++) {
	while (b[i]>0) {
	    while (a[ptr]==0) ++ptr;
	    ll cur = min(b[i],a[ptr]);
	    res += 1ll*abs(ptr-i)*cur;
	    a[ptr] -= cur;
	    b[i] -= cur;
	}
    }

    cout<<res<<endl;    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 9 ms 1516 KB Output is correct
5 Correct 18 ms 2540 KB Output is correct
6 Correct 52 ms 7276 KB Output is correct
7 Correct 103 ms 11244 KB Output is correct
8 Correct 84 ms 11244 KB Output is correct
9 Correct 84 ms 11244 KB Output is correct
10 Correct 65 ms 10092 KB Output is correct
11 Correct 65 ms 10092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 9 ms 1516 KB Output is correct
5 Correct 18 ms 2540 KB Output is correct
6 Correct 52 ms 7276 KB Output is correct
7 Correct 103 ms 11244 KB Output is correct
8 Correct 84 ms 11244 KB Output is correct
9 Correct 84 ms 11244 KB Output is correct
10 Correct 65 ms 10092 KB Output is correct
11 Correct 65 ms 10092 KB Output is correct
12 Runtime error 29 ms 6124 KB Execution killed with signal 6 (could be triggered by violating memory limits)
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Runtime error 2 ms 492 KB Execution killed with signal 6 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Runtime error 2 ms 492 KB Execution killed with signal 6 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Runtime error 2 ms 492 KB Execution killed with signal 6 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -