이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <bits/stdc++.h>
#include <map>
#include <vector>
#include <cmath>
#include <algorithm>
#include <unistd.h>
#include <cstdio>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef pair<ll, int> pil;
typedef vector<int> vi;
typedef long long ll;
typedef pair<ll,ll> pll;
const int SS = 3e5 + 8;
class Solution{
public:
ll N, S, xi, pi, newS;
vector<ll> profit = {0},
childs[SS];
priority_queue< pll > maxPq;
ll profitProfit(){
cin >> N >> S;
newS = S;
for (int i = 1; i <= N; i++){
cin >> xi >> pi;
childs[pi].push_back(i);
profit.push_back( xi );
if (pi == 0){maxPq.push( make_pair(xi, i) );}
}
while (!maxPq.empty()){
auto [money, currNode] = maxPq.top(); maxPq.pop();
if (-money > newS) continue;
if (money > 0) newS += money, money = 0;
if (!childs[currNode].empty()){
maxPq.push( make_pair( money + profit[ childs[currNode][0] ], childs[currNode][0]));
}
}
return newS - S;
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
Solution p;
cout << p.profitProfit();
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In member function 'll Solution::profitProfit()':
Main.cpp:37:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
37 | auto [money, currNode] = maxPq.top(); maxPq.pop();
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |