Submission #440550

#TimeUsernameProblemLanguageResultExecution timeMemory
440550zarifPod starim krovovima (COCI20_psk)C++17
40 / 50
2 ms204 KiB
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define debug(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #else #define debug(x...) #endif void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n ; vector<pair<int,int>>vec(n); int sum=0; for(int i=0;i<n;i++){ int t; cin >> t >>vec[i].first; vec[i].second=i; sum+=t; } int ans[n]; memset(ans,0,sizeof(ans)); sort(vec.begin(),vec.end(),greater<pair<int,int>>()); int i; for(i=1;i<=n;i++){ if(i==1&&!sum){ i=0; break; } ans[vec[i-1].second]=min(sum,vec[i-1].first); sum-=ans[vec[i-1].second]; if(sum<=0)break; } cout << n-i <<endl; for(int i=0;i<n;i++){ cout << ans[i]<<endl; } }

Compilation message (stderr)

psk.cpp: In function 'void setIO(std::string)':
psk.cpp:53:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
psk.cpp:54:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...