제출 #1278136

#제출 시각아이디문제언어결과실행 시간메모리
1278136lmquanPotatoes and fertilizers (LMIO19_bulves)C++20
100 / 100
103 ms10444 KiB
#define taskname "" #include <bits/stdc++.h> using namespace std; int main() { if (fopen(taskname".inp", "r")) { freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; long long x = 0; vector<pair<int, int>> a(n + 1); vector<long long> b(n + 1, 0); for (int i = 1; i <= n; i++) { cin >> a[i].first >> a[i].second; x += a[i].first - a[i].second; b[i] = b[i - 1] + a[i].first - a[i].second; } long long result = 0; for (int i = 1; i <= n; i++) { if (b[i] < 0) { result += -b[i]; b[i] = 0; } if (b[i] > x) { result += b[i] - x; b[i] = x; } } result += x - b[n]; b[n] = x; priority_queue<int> pq; for (int i = 1; i <= n; i++) { pq.push(b[i]); if (b[i] < pq.top()) { result += pq.top() - b[i]; pq.pop(); pq.push(b[i]); } } cout << result << '\n'; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

bulves.cpp: In function 'int main()':
bulves.cpp:7:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |     freopen(taskname".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
bulves.cpp:8:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |     freopen(taskname".out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...