답안 #912325

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
912325 2024-01-19T10:01:38 Z vjudge1 Potatoes and fertilizers (LMIO19_bulves) C++17
0 / 100
447 ms 940 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    int a[n], b[n];
    map <int, int> mp;
    map <int, int> mp1;
    map <int, int> mp2;
    map <int, int> mp3;
    int ok = 0;
    int okk = 0;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        if (a[i] > 0 && b[i] > 0) {
            if (a[i] >= b[i]) {
                a[i] -= b[i];
                b[i] = 0;
            }
            else {
                b[i] -= a[i];
                a[i] = 0;
            }
        }
        if (a[i] > 0) {
            mp2[ok] = a[i];
            mp3[ok] = i;
            okk++;
        }
        if (b[i] > 0) {
            mp[ok] = b[i];
            mp1[ok] = i;
            ok++;
        }
    }
    for (int j = 0; j < ok; j++) {
        for (int i = 0; i < okk; i++) {
            if (mp[j] <= mp2[i]) {
                cnt += mp[j]*abs(mp1[j]-mp3[i]);
                mp2[i] -= mp[j];
                mp[j] = 0;
                break;
            }
            else {
                cnt += abs(mp2[i]-mp[j])*abs(mp1[j]-mp3[i]);
                mp[j] -= mp2[i];
                mp2[i] = 0;
            }
        }
    }
    cout << cnt;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 447 ms 940 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 447 ms 940 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 447 ms 940 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 447 ms 940 KB Output isn't correct
4 Halted 0 ms 0 KB -