답안 #339953

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
339953 2020-12-26T12:11:45 Z Hazem Pod starim krovovima (COCI20_psk) C++14
50 / 50
3 ms 384 KB
/*
ID: tmhazem1
LANG: C++14
TASK: pprime
*/

#include <bits/stdc++.h>
using namespace std;

#define S second
#define F first
#define LL long long
const int N = 2e5 + 10;


LL LINF = 100000000000000000;
LL INF = 1000000000;

vector<pair<pair<int,int>,int>>vec;
int ans[N];

int main()
{
    //freopen("out.txt","w",stdout);
    int n;
    scanf("%d",&n);

    for(int i=1;i<=n;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        vec.push_back({{b,a},i});
    } 

    sort(vec.begin(),vec.end());
    for(int i=0;i<vec.size();i++)
        for(int j=vec.size()-1;j>i;j--){
            int mn = min(vec[i].F.S,vec[j].F.F-vec[j].F.S);
            vec[i].F.S -= mn,vec[j].F.S += mn;
        }

    int cnt = 0;
    for(auto x:vec)
        ans[x.S] = x.F.S,cnt += !ans[x.S];

    printf("%d\n",cnt);
    for(int i=1;i<=n;i++)
        printf("%d ",ans[i]);
}       

Compilation message

psk.cpp: In function 'int main()':
psk.cpp:35:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for(int i=0;i<vec.size();i++)
      |                 ~^~~~~~~~~~~
psk.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
psk.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |         scanf("%d%d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 3 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 3 ms 364 KB Output is correct