Submission #844211

# Submission time Handle Problem Language Result Execution time Memory
844211 2023-09-05T11:34:11 Z vjudge1 Pod starim krovovima (COCI20_psk) C++17
50 / 50
1 ms 436 KB
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<map>
#include<set>
#include<climits>
#include<numeric>
#include<queue>
#include<unordered_map>
#include<string>
#include<climits>
#include<unordered_set>
#include<bitset>
#include<cstring>
#include<cmath>
#include<stack>
#if 1
#define pb push_back
#define st first
#define nd second
#define endl '\n'
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MAXN ((int)(2e5+5))
#define int long long int
using namespace std;
const int inf = 1e17 + 5;
#endif

void fileio(string s){
    #ifndef ONLINE_JUDGE
        freopen((s+string(".in")).c_str(),"r",stdin);
        freopen((s+string(".out")).c_str(),"w",stdout);
    #endif
}


signed main(){
    //fileio("test");
    //fio; 
    int n;
    cin >> n;
    set<pair<int, int> , greater<pair<int, int> > >s;
    int sum = 0;
    for(int i = 0; i < n; ++i){
        int t, z;
        cin >> t >> z;
        sum += t;
        s.insert({z,i});
    }
    int status[n];
    memset(status, 0, sizeof(status));
    int ans = n;
    for(auto it = s.begin(); it != s.end(); ++it){
        int val = (*it).st, idx = (*it).nd;
        if(val < sum){
            sum -= val;
            status[idx] = val;
            ans--;
        }
        else{
            status[idx] = sum;
            ans--;
            break;
        }
    }
    cout << ans << endl;
    for(int i = 0; i < n; ++i)cout << status[i] << ' ';cout << endl;
    
}

Compilation message

psk.cpp: In function 'int main()':
psk.cpp:68:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   68 |     for(int i = 0; i < n; ++i)cout << status[i] << ' ';cout << endl;
      |     ^~~
psk.cpp:68:56: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   68 |     for(int i = 0; i < n; ++i)cout << status[i] << ' ';cout << endl;
      |                                                        ^~~~
psk.cpp: In function 'void fileio(std::string)':
psk.cpp:32:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         freopen((s+string(".in")).c_str(),"r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
psk.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         freopen((s+string(".out")).c_str(),"w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 436 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 432 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct