Submission #313993

#TimeUsernameProblemLanguageResultExecution timeMemory
313993kaplanbarUnija (COCI17_unija)C++14
100 / 100
181 ms23288 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int readInt() { int x=0; char ch=getchar_unlocked(); bool s=1; while(ch<'0'||ch>'9'){if(ch=='-')s=0;ch=getchar_unlocked();} while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar_unlocked();} return s?x:-x; } constexpr int N = 1e6+5; pair<int,int> a[N]; int main() { // ios_base::sync_with_stdio(false); // cin.tie(0); int n = readInt(); for(int i = 0; i < n; i++) { a[i].first = readInt(); a[i].second = readInt(); } a[n].first = 0; a[n].second = 0; sort(a, a+n+1); long long ans = 0; for(int i = n - 1; i >= 0; i--) { a[i].second=max(a[i].second, a[i+1].second); ans += 1ll*(a[i+1].first-a[i].first)*a[i+1].second; } printf("%lld", ans); return 0; }
#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...
#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...