답안 #275608

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
275608 2020-08-20T06:44:50 Z 문홍윤(#5111) Radio (Balkan15_RADIO) C++17
0 / 100
1 ms 384 KB
#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define svec(x) sort(x.begin(), x.end())
#define press(x) x.erase(unique(x.begin(), x.end()), x.end())
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
const LL llinf=2e18;
const int inf=1e9;

int n, k;
LL x[100010], p[100010], s[100010], ans[100010], anss;
vector<pli> use;
vector<LL> vc;

int main(){
    scanf("%d %d", &n, &k);
    for(int i=1; i<=n; i++){
        scanf("%lld %lld %lld", &x[i], &p[i], &s[i]);
        use.eb(x[i]-p[i], -1);
        use.eb(x[i]+p[i], 1);
        vc.eb(x[i]-p[i]);
        vc.eb(x[i]+p[i]);
    }
    svec(use);
    svec(vc); press(vc);
    LL num=0, sum=0;
    int pv=0;
    for(int i=0; i<vc.size(); i++){
        for(; pv<use.size(); pv++){
            if(use[pv].F>vc[i])break;
            if(use[pv].S==1)num++, sum+=use[pv].F;
        }
        ans[i]+=num*vc[i]-sum;
    }
    num=sum=0;
    pv=use.size()-1;
    for(int i=vc.size()-1; i>=0; i--){
        for(; pv>=0; pv--){
            if(use[pv].F<vc[i])break;
            if(use[pv].S==-1)num++, sum+=use[pv].F;
        }
        ans[i]+=sum-num*vc[i];
    }
    for(int i=0; i<vc.size(); i++)anss=min(anss, ans[i]);
    printf("%lld", anss);
}

Compilation message

radio.cpp: In function 'int main()':
radio.cpp:36:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int i=0; i<vc.size(); i++){
      |                  ~^~~~~~~~~~
radio.cpp:37:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         for(; pv<use.size(); pv++){
      |               ~~^~~~~~~~~~~
radio.cpp:52:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for(int i=0; i<vc.size(); i++)anss=min(anss, ans[i]);
      |                  ~^~~~~~~~~~
radio.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
radio.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |         scanf("%lld %lld %lld", &x[i], &p[i], &s[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -